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 std_msgs.msg import Empty
00031 from ardrone_autonomy.msg import Navdata
00032 import pid
00033 import time
00034
00035 class ArdroneControl:
00036 def __init__( self ):
00037 self.nav_sub = rospy.Subscriber( "ardrone/navdata", Navdata, self.callback_navdata )
00038 self.cmd_vel_pub = rospy.Publisher( "cmd_vel", Twist )
00039 self.goal_vel_sub = rospy.Subscriber( "goal_vel", Twist, self.callback_goal_vel )
00040
00041
00042 self.linearxpid = pid.Pid2( 0.5, 0.0, 0.5 )
00043 self.linearypid = pid.Pid2( 0.5, 0.0, 0.5 )
00044
00045 self.vx = self.vy = self.vz = self.ax = self.ay = self.az = 0.0
00046 self.last_time = None
00047 self.goal_vel = Twist()
00048
00049 def callback_goal_vel( self, data ):
00050 self.goal_vel = data
00051
00052 def callback_navdata( self, data ):
00053 self.vx = data.vx/1e3
00054 self.vy = data.vy/1e3
00055 self.vz = data.vz/1e3
00056
00057
00058
00059
00060
00061
00062
00063 def update( self ):
00064 if self.last_time == None:
00065 self.last_time = rospy.Time.now()
00066 dt = 0.0
00067 else:
00068 time = rospy.Time.now()
00069 dt = ( time - self.last_time ).to_sec()
00070 self.last_time = time
00071
00072 cmd = Twist()
00073 cmd.angular.y = 0
00074 cmd.angular.x = 0
00075 cmd.angular.z = self.goal_vel.angular.z
00076 cmd.linear.z = self.goal_vel.linear.z
00077 cmd.linear.x = self.linearxpid.update( self.goal_vel.linear.x, self.vx, 0.0, dt )
00078 cmd.linear.y = self.linearypid.update( self.goal_vel.linear.y, self.vy, 0.0, dt )
00079
00080 self.cmd_vel_pub.publish( cmd )
00081
00082 def main():
00083 rospy.init_node( 'ardrone_control' )
00084
00085 control = ArdroneControl()
00086 r = rospy.Rate(100)
00087
00088 try:
00089 while not rospy.is_shutdown():
00090 control.update()
00091 r.sleep()
00092 except KeyboardInterrupt:
00093 print "Shutting down"
00094
00095 if __name__ == '__main__':
00096 main()