teleop.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import roslib; roslib.load_manifest('clearpath_teleop')
00004 import rospy
00005 
00006 from sensor_msgs.msg import Joy
00007 from geometry_msgs.msg import Twist
00008 from std_msgs.msg import String
00009 
00010 
00011 class Teleop:
00012     def __init__(self):
00013         rospy.init_node('clearpath_teleop')
00014 
00015         self.turn_scale = rospy.get_param('~turn_scale')
00016         self.drive_scale = rospy.get_param('~drive_scale')
00017         self.deadman_button = rospy.get_param('~deadman_button', 0)
00018 
00019         self.cmd = None
00020         cmd_pub = rospy.Publisher('cmd_vel', Twist)
00021 
00022         announce_pub = rospy.Publisher('/clearpath/announce/teleops',
00023                                        String, latch=True)
00024         announce_pub.publish(rospy.get_namespace());
00025 
00026         rospy.Subscriber("joy", Joy, self.callback)
00027         rate = rospy.Rate(rospy.get_param('~hz', 20))
00028         
00029         while not rospy.is_shutdown():
00030             rate.sleep()
00031             if self.cmd:
00032                 cmd_pub.publish(self.cmd)
00033 
00034     def callback(self, data):
00035         """ Receive joystick data, formulate Twist message. """
00036         cmd = Twist()
00037         cmd.linear.x = data.axes[1] * self.drive_scale
00038         cmd.angular.z = data.axes[0] * self.turn_scale
00039 
00040         if data.buttons[self.deadman_button] == 1:
00041             self.cmd = cmd
00042         else:
00043             self.cmd = None
00044 
00045 
00046 if __name__ == "__main__": Teleop()


clearpath_teleop
Author(s): Mike Purvis
autogenerated on Sun Oct 5 2014 22:52:05