1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import rospy
16 import intera_dataflow
17 from intera_io import IODeviceInterface
18 from intera_core_msgs.msg import IODeviceConfiguration
19 from robot_params import RobotParams
20
21
23 """
24 Interface class for cuff on the Intera robots.
25 """
26
28 """
29 Constructor.
30
31 @type limb: str
32 @param limb: limb side to interface
33 """
34 params = RobotParams()
35 limb_names = params.get_limb_names()
36 if limb not in limb_names:
37 rospy.logerr("Cannot detect Cuff's limb {0} on this robot."
38 " Valid limbs are {1}. Exiting Cuff.init().".format(
39 limb, limb_names))
40 return
41 self.limb = limb
42 self.device = None
43 self.name = "cuff"
44 self.cuff_config_sub = rospy.Subscriber('/io/robot/cuff/config', IODeviceConfiguration, self._config_callback)
45
46 intera_dataflow.wait_for(
47 lambda: not self.device is None, timeout=5.0,
48 timeout_msg=("Failed find cuff on limb '{0}'.".format(limb))
49 )
50 self._cuff_io = IODeviceInterface("robot", self.name)
51
53 """
54 config topic callback
55 """
56 if msg.device != []:
57 if str(msg.device.name) == self.name:
58 self.device = msg.device
59
68
77
86
88 """
89 Registers a supplied callback to a change in state of supplied
90 signal_name's value. Spawns a thread that will call the callback with
91 the updated value.
92
93 @type callback_function: function
94 @param callback_function: function handle for callback function
95 @type signal_name: str
96 @param signal_name: the name of the signal to poll for value change
97 @type poll_rate: int
98 @param poll_rate: the rate at which to poll for a value change (in a separate
99 thread)
100
101 @rtype: str
102 @return: callback_id retuned if the callback was registered, and an
103 empty string if the requested signal_name does not exist in the
104 Navigator
105 """
106 return self._cuff_io.register_callback(
107 callback_function=callback_function,
108 signal_name=signal_name,
109 poll_rate=poll_rate)
110
112 """
113 Deregisters a callback based on the supplied callback_id.
114
115 @type callback_id: str
116 @param callback_id: the callback_id string to deregister
117
118 @rtype: bool
119 @return: returns bool True if the callback was successfully
120 deregistered, and False otherwise.
121 """
122 return self._cuff_io.deregister_callback(callback_id)
123