execute_trajectory.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import argparse
00004 import rospy
00005 import tf_conversions
00006 from crazyflie_driver.msg import FullState
00007 import geometry_msgs
00008 import uav_trajectory
00009 
00010 
00011 if __name__ == '__main__':
00012     parser = argparse.ArgumentParser()
00013     parser.add_argument("trajectory", type=str, help="CSV file containing trajectory")
00014     args = parser.parse_args()
00015 
00016     rospy.init_node('full_state')
00017 
00018     traj = uav_trajectory.Trajectory()
00019     traj.loadcsv(args.trajectory)
00020 
00021     rate = rospy.Rate(100)
00022 
00023     msg = FullState()
00024     msg.header.seq = 0
00025     msg.header.stamp = rospy.Time.now()
00026     msg.header.frame_id = "/world"
00027 
00028     pub = rospy.Publisher("/crazyflie/cmd_full_state", FullState, queue_size=1)
00029     start_time = rospy.Time.now()
00030 
00031     while not rospy.is_shutdown():
00032         msg.header.seq += 1
00033         msg.header.stamp = rospy.Time.now()
00034         t = (msg.header.stamp - start_time).to_sec()
00035         print(t)
00036         if t > traj.duration:
00037             break
00038             # t = traj.duration
00039 
00040         e = traj.eval(t)
00041 
00042         msg.pose.position.x    = e.pos[0]
00043         msg.pose.position.y    = e.pos[1]
00044         msg.pose.position.z    = e.pos[2]
00045         msg.twist.linear.x     = e.vel[0]
00046         msg.twist.linear.y     = e.vel[1]
00047         msg.twist.linear.z     = e.vel[2]
00048         msg.acc.x              = e.acc[0]
00049         msg.acc.y              = e.acc[1]
00050         msg.acc.z              = e.acc[2]
00051         msg.pose.orientation   = geometry_msgs.msg.Quaternion(*tf_conversions.transformations.quaternion_from_euler(0, 0, e.yaw))
00052         msg.twist.angular.x    = e.omega[0]
00053         msg.twist.angular.y    = e.omega[1]
00054         msg.twist.angular.z    = e.omega[2]
00055 
00056         pub.publish(msg)
00057         rate.sleep()


crazyflie_demo
Author(s): Wolfgang Hoenig
autogenerated on Wed Jun 12 2019 19:20:46