Go to the documentation of this file.00001
00002
00003 import roslib; roslib.load_manifest('kingfisher_teleop')
00004 import rospy
00005
00006 from sensor_msgs.msg import Joy
00007 from geometry_msgs.msg import Twist
00008
00009
00010 class Teleop:
00011 def __init__(self):
00012 rospy.init_node('clearpath_teleop')
00013
00014 self.turn_scale = rospy.get_param('~turn_scale')
00015 self.drive_scale = rospy.get_param('~drive_scale', 0.7)
00016 self.turbo_drive_scale = rospy.get_param('~turbo_drive_scale', 1.0)
00017
00018 self.deadman_button = rospy.get_param('~deadman_button', 0)
00019 self.turbo_button = rospy.get_param('~turbo_button', 1)
00020
00021 self.max_age = None
00022 max_age_seconds = rospy.get_param('~max_age_seconds', None)
00023 if max_age_seconds:
00024 self.max_age = rospy.Duration.from_sec(max_age_seconds)
00025
00026 self.cmd_pub = rospy.Publisher('cmd_vel', Twist)
00027
00028 rospy.Subscriber("joy", Joy, self.callback)
00029 rospy.spin()
00030
00031 def callback(self, data):
00032 """ Receive joystick data, formulate Twist message. """
00033
00034 if self.max_age and data.header.stamp - rospy.Time.now() > self.max_age:
00035
00036 return
00037
00038 scale = 0
00039 if data.buttons[self.deadman_button] == 1:
00040 scale = self.drive_scale
00041 if data.buttons[self.turbo_button] == 1:
00042 scale = self.turbo_drive_scale
00043
00044 if scale != 0:
00045 cmd = Twist()
00046 cmd.linear.x = data.axes[1] * scale
00047 cmd.angular.z = data.axes[0] * self.turn_scale
00048 self.cmd_pub.publish(cmd)
00049
00050
00051 if __name__ == "__main__": Teleop()