ardrone_teleop_joy.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Copyright (c) 2012, Falkor Systems, Inc.  All rights reserved.
00003 
00004 # Redistribution and use in source and binary forms, with or without
00005 # modification, are permitted provided that the following conditions are
00006 # met:
00007 
00008 # Redistributions of source code must retain the above copyright notice,
00009 # this list of conditions and the following disclaimer.  Redistributions
00010 # in binary form must reproduce the above copyright notice, this list of
00011 # conditions and the following disclaimer in the documentation and/or
00012 # other materials provided with the distribution.  THIS SOFTWARE IS
00013 # PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00014 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00015 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00017 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00018 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00019 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00020 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00021 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00022 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00023 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         # Do cmd_vel
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     


falkor_ardrone
Author(s): Sameer Parekh
autogenerated on Tue Jan 7 2014 11:12:13