8 Catches the output from buttons on a joystick and converts these 9 to customisable ros publishers (Empty, Time Timestamped Bool) for use 10 as pure events, timestamped events, or true/false triggers. 12 Publishing only occurs when joystick button signals change state. 20 from yocs_msgs.msg
import MagicButton
21 from std_msgs.msg
import Empty
22 from std_msgs.msg
import Time
23 from sensor_msgs.msg
import Joy
33 self.
publisher = rospy.Publisher(name, Empty, queue_size=10)
34 rospy.loginfo(
"MagicButtonRelay : adding event relay for button '%s' to publisher at '%s'" % (self.
button_id, self.publisher.name))
37 def update(self, pressed, unused_timestamp):
39 self.publisher.publish(Empty())
40 rospy.logdebug(
"MagicButtonRelay : event for button '%s' published at '%s'" % (self.
button_id, self.publisher.name))
46 self.
publisher = rospy.Publisher(name, Time, queue_size=10)
47 rospy.loginfo(
"MagicButtonRelay : adding stamped event relay for button '%s' to publisher at '%s'" % (self.
button_id, self.publisher.name))
50 def update(self, pressed, timestamp):
52 rospy.logdebug(
"MagicButtonRelay : stamped event for button '%s' published at '%s'" % (self.
button_id, self.publisher.name))
53 self.publisher.publish(Time(timestamp))
59 self.
publisher = rospy.Publisher(name, MagicButton, queue_size=10)
60 rospy.loginfo(
"MagicButtonRelay : adding stamped button relay for button '%s' to publisher at '%s'" % (self.
button_id, self.publisher.name))
63 def update(self, pressed, timestamp):
66 msg.header.stamp = timestamp
68 rospy.logdebug(
"MagicButtonRelay : stamped button event for button '%s' published at '%s'" % (self.
button_id, self.publisher.name))
69 self.publisher.publish(msg)
77 for spec
in relay_specifications:
79 if spec[
"type"] ==
"event":
80 self.relays.append(
EventRelay(spec[
"id"], spec[
"name"]))
81 elif spec[
"type"] ==
"stamped_event":
83 elif spec[
"type"] ==
"stamped_button":
86 rospy.logerr(
"MagicButtonRelay : invalid type (%s) for the magic button ['event', 'timestamp', 'button']" % spec[
"type"])
88 rospy.logerr(
"MagicButtonRelay : no 'type' provided for the magic button ['event', 'timestamp', 'button']")
92 Processes the joy topic. 94 timestamp = msg.header.stamp
96 relay.update(msg.buttons[relay.button_id], msg.header.stamp)
98 if __name__ ==
'__main__':
99 rospy.init_node(
'magic_button_relay')
100 relay_specifications = rospy.get_param(
"~relays")