switch.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # license removed for brevity
00003 import rospy
00004 from geometry_msgs.msg import Twist
00005 from sensor_msgs.msg import Joy
00006 
00007 # This script will listen for joystick button 5 being toggled and
00008 # send zero speed messages to the mux to disable the follower until
00009 # button 5 is pressed again.
00010 
00011 class BehaviorSwitch(object):
00012     def __init__(self):
00013         self.running = False
00014 
00015     def callback(self, joy_msg):
00016         if joy_msg.buttons[5] == 1:
00017             self.running = not self.running
00018 
00019         rospy.loginfo(repr(joy_msg))
00020 
00021     def run(self):
00022         rospy.init_node('behavior_switch', anonymous=True)
00023         pub = rospy.Publisher('cmd_vel_mux/input/switch', Twist, queue_size=10)
00024         rospy.Subscriber('joy', Joy, self.callback)
00025         rate = rospy.Rate(10)
00026         while not rospy.is_shutdown():
00027             if self.running:
00028                 empty_msg = Twist()
00029                 pub.publish(empty_msg)
00030             rate.sleep()
00031 
00032 if __name__ == '__main__':
00033     try:
00034         behavior_switch = BehaviorSwitch()
00035         behavior_switch.run()
00036     except rospy.ROSInterruptException:
00037         pass


turtlebot_follower
Author(s): Tony Pratkanis
autogenerated on Sat Jun 8 2019 20:35:33