teleop_twist.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import roslib; roslib.load_manifest('axis_camera')
00004 import rospy
00005 
00006 import math
00007 from sensor_msgs.msg import Joy
00008 from axis_camera.msg import Axis
00009 from geometry_msgs.msg import Twist
00010 
00011 
00012 class Teleop:
00013     def __init__(self):
00014         rospy.init_node('axis_twist_teleop')
00015         self.enable_button = rospy.get_param('~enable_button', 1)
00016         self.zero_button = rospy.get_param('~zero_button', 2)
00017         self.scale_pan = rospy.get_param('~scale_pan_deg', 10)
00018         self.scale_tilt = rospy.get_param('~scale_tilt_deg', 10)
00019         self.state = Axis(pan=180,tilt=0,zoom=1)
00020         self.joy = None
00021 
00022         self.cmd_pub = rospy.Publisher('cmd', Axis)
00023         self.twist_pub = rospy.Publisher('twist', Twist)
00024         rospy.Subscriber("/joy", Joy, self.joy_callback)
00025         # rospy.Subscriber("state", Axis, self.state_callback)
00026         
00027     def spin(self):
00028         twist = Twist()
00029         self.cmd_pub.publish(self.state)
00030         r = rospy.Rate(5)
00031         while not rospy.is_shutdown():
00032             if self.joy != None and self.joy.buttons[self.enable_button] == 1:
00033                 twist.angular.z = self.joy.axes[0]*self.scale_pan*math.pi/180.
00034                 twist.angular.y = -self.joy.axes[1]*self.scale_tilt*math.pi/180.
00035                 self.twist_pub.publish(twist)
00036             if self.joy != None and self.joy.buttons[self.zero_button] == 1:
00037                 self.cmd_pub.publish(self.state)
00038             r.sleep()
00039 
00040     def joy_callback(self, data):
00041         self.joy = data
00042 
00043 
00044 if __name__ == "__main__": Teleop().spin()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


axis_camera
Author(s): Ryan Gariepy
autogenerated on Mon May 13 2013 10:15:52