4141from cflib .crazyflie .syncLogger import SyncLogger
4242
4343# URI to the Crazyflie to connect to
44- uri = 'radio://0/53/2M'
45- # uri = 'radio://0/80/2M'
44+ uri = 'radio://0/80/2M'
4645
4746# The trajectory to fly
4847# See https://github.com/whoenig/uav_trajectories for a tool to generate
4948# trajectories
49+
50+ # Duration,x^0,x^1,x^2,x^3,x^4,x^5,x^6,x^7,y^0,y^1,y^2,y^3,y^4,y^5,y^6,y^7,z^0,z^1,z^2,z^3,z^4,z^5,z^6,z^7,yaw^0,yaw^1,yaw^2,yaw^3,yaw^4,yaw^5,yaw^6,yaw^7
5051figure8 = [
5152 [1.050000 , 0.000000 , - 0.000000 , 0.000000 , - 0.000000 , 0.830443 , - 0.276140 , - 0.384219 , 0.180493 , - 0.000000 , 0.000000 , - 0.000000 , 0.000000 , - 1.356107 , 0.688430 , 0.587426 , - 0.329106 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 ], # noqa
5253 [0.710000 , 0.396058 , 0.918033 , 0.128965 , - 0.773546 , 0.339704 , 0.034310 , - 0.026417 , - 0.030049 , - 0.445604 , - 0.684403 , 0.888433 , 1.493630 , - 1.361618 , - 0.139316 , 0.158875 , 0.095799 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 ], # noqa
@@ -137,26 +138,30 @@ def activate_mellinger_controller(cf):
137138def upload_trajectory (cf , trajectory_id , trajectory ):
138139 trajectory_mem = cf .mem .get_mems (MemoryElement .TYPE_TRAJ )[0 ]
139140
141+ total_duration = 0
140142 for row in trajectory :
141143 duration = row [0 ]
142144 x = Poly4D .Poly (row [1 :9 ])
143145 y = Poly4D .Poly (row [9 :17 ])
144146 z = Poly4D .Poly (row [17 :25 ])
145147 yaw = Poly4D .Poly (row [25 :33 ])
146148 trajectory_mem .poly4Ds .append (Poly4D (duration , x , y , z , yaw ))
149+ total_duration += duration
147150
148151 Uploader ().upload (trajectory_mem )
149152 cf .high_level_commander .define_trajectory (trajectory_id , 0 ,
150153 len (trajectory_mem .poly4Ds ))
154+ return total_duration
151155
152156
153- def run_sequence (cf , trajectory_id ):
157+ def run_sequence (cf , trajectory_id , duration ):
154158 commander = cf .high_level_commander
155159
156160 commander .takeoff (1.0 , 2.0 )
157161 time .sleep (3.0 )
158- commander .start_trajectory (1 , 1.0 , True )
159- time .sleep (10 )
162+ relative = True
163+ commander .start_trajectory (trajectory_id , 1.0 , relative )
164+ time .sleep (duration )
160165 commander .land (0.0 , 2.0 )
161166 time .sleep (2 )
162167 commander .stop ()
@@ -171,6 +176,7 @@ def run_sequence(cf, trajectory_id):
171176
172177 activate_high_level_commander (cf )
173178 # activate_mellinger_controller(cf)
174- upload_trajectory (cf , trajectory_id , figure8 )
179+ duration = upload_trajectory (cf , trajectory_id , figure8 )
180+ print ("The sequence is {:.1f} seconds long" .format (duration ))
175181 reset_estimator (cf )
176- run_sequence (cf , trajectory_id )
182+ run_sequence (cf , trajectory_id , duration )
0 commit comments