Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 import roslib
00026 roslib.load_manifest('falkor_ardrone')
00027
00028 import rospy
00029 from geometry_msgs.msg import Twist
00030 from sensor_msgs.msg import Joy
00031 from std_msgs.msg import Empty
00032 from ardrone_autonomy.msg import Navdata
00033 import pid
00034 import time
00035
00036 class ArdroneTeleopJoy:
00037
00038 def __init__( self ):
00039 self.cmd_vel_pub = rospy.Publisher( "cmd_vel_interm", Twist )
00040 self.land_pub = rospy.Publisher( "ardrone/land", Empty )
00041 self.takeoff_pub = rospy.Publisher( "ardrone/takeoff", Empty )
00042 self.reset_pub = rospy.Publisher( "ardrone/reset", Empty )
00043 self.joy_sub = rospy.Subscriber( "joy", Joy, self.callback_joy )
00044
00045 def callback_joy( self, data ):
00046 empty_msg = Empty()
00047
00048 if data.buttons[12] == 1 and self.last_buttons[12] == 0:
00049 self.takeoff_pub.publish( empty_msg )
00050 self.pause = 5.0
00051
00052 if data.buttons[14] == 1 and self.last_buttons[14] == 0:
00053 self.land_pub.publish( empty_msg )
00054
00055 if data.buttons[13] == 1 and self.last_buttons[13] == 0:
00056 self.reset_pub.publish( empty_msg )
00057
00058 self.last_buttons = data.buttons
00059
00060
00061 cmd = Twist()
00062
00063 cmd.angular.x = cmd.angular.y = 0
00064 cmd.angular.z = data.axes[2] * 3.14/2
00065
00066 cmd.linear.z = data.axes[3] * 2.0
00067 cmd.linear.x = data.axes[1] * 1.0
00068 cmd.linear.y = data.axes[0] * 1.0
00069 self.cmd_vel_pub.publish( cmd )
00070
00071
00072 def main():
00073 rospy.init_node( 'ardrone_teleop_joy' )
00074
00075 teleop = ArdroneTeleopJoy()
00076
00077 try:
00078 rospy.spin()
00079 except KeyboardInterrupt:
00080 print "Shutting down"
00081
00082 if __name__ == '__main__':
00083 main()
00084
00085