@@ -73,14 +73,14 @@ def arm(scf):
7373 time .sleep (1.0 )
7474
7575
76- def position_callback (uri , timestamp , data , logconf ):
76+ def position_callback (uri , data ):
7777 global pos1 , pos2
78- if uri == 'radio://0/80/2M/E7E7E7E7E7' :
78+ if uri == URI1 :
7979 pos1 [0 ] = data ['stateEstimate.x' ]
8080 pos1 [1 ] = data ['stateEstimate.y' ]
8181 pos1 [2 ] = data ['stateEstimate.z' ]
8282 print (f'Uri1 position: x={ pos1 [0 ]} , y-{ pos1 [1 ]} , z{ pos1 [2 ]} ' )
83- elif uri == 'radio://0/80/2M/E7E7E7E7E8' :
83+ elif uri == URI2 :
8484 pos2 [0 ] = data ['stateEstimate.x' ]
8585 pos2 [1 ] = data ['stateEstimate.y' ]
8686 pos2 [2 ] = data ['stateEstimate.z' ]
@@ -93,38 +93,41 @@ def start_position_printing(scf):
9393 log_conf1 .add_variable ('stateEstimate.y' , 'float' )
9494 log_conf1 .add_variable ('stateEstimate.z' , 'float' )
9595 scf .cf .log .add_config (log_conf1 )
96- log_conf1 .data_received_cb .add_callback (
97- lambda timestamp , data , logconf : position_callback (scf .cf .link_uri , timestamp , data , logconf ))
96+ log_conf1 .data_received_cb .add_callback (lambda _timestamp , data , _logconf : position_callback (scf .cf .link_uri , data ))
9897 log_conf1 .start ()
9998
10099
101100def async_flight (scf ):
102101 with MotionCommander (scf , default_height = DEFAULT_HEIGHT ) as mc :
103102 time .sleep (1 )
103+
104+ start_time = time .time ()
104105 end_time = time .time () + 12
106+
105107 while time .time () < end_time :
106- if scf .__dict__ ['_link_uri' ] == 'radio://0/80/2M/E7E7E7E7E7' :
107- if time .time () < end_time - 7 :
108+
109+ if scf .__dict__ ['_link_uri' ] == URI1 :
110+ if time .time () - start_time < 5 :
108111 mc .start_up (DEFAULT_VELOCITY )
109- elif time .time () < end_time - 5 :
112+ elif time .time () - start_time < 7 :
110113 mc .stop ()
111- elif time .time () < end_time :
114+ elif time .time () - start_time < 12 :
112115 mc .start_down (DEFAULT_VELOCITY )
113116 else :
114117 mc .stop ()
115118
116- elif scf .__dict__ ['_link_uri' ] == 'radio://0/80/2M/E7E7E7E7E8' :
117- if time .time () < end_time - 10 :
119+ elif scf .__dict__ ['_link_uri' ] == URI2 :
120+ if time .time () - start_time < 2 :
118121 mc .start_left (DEFAULT_VELOCITY )
119- elif time .time () < end_time - 8 :
122+ elif time .time () - start_time < 4 :
120123 mc .start_right (DEFAULT_VELOCITY )
121- elif time .time () < end_time - 6 :
124+ elif time .time () - start_time < 6 :
122125 mc .start_left (DEFAULT_VELOCITY )
123- elif time .time () < end_time - 4 :
126+ elif time .time () - start_time < 8 :
124127 mc .start_right (DEFAULT_VELOCITY )
125- elif time .time () < end_time - 2 :
128+ elif time .time () - start_time < 10 :
126129 mc .start_left (DEFAULT_VELOCITY )
127- elif time .time () < end_time :
130+ elif time .time () - start_time < 12 :
128131 mc .start_right (DEFAULT_VELOCITY )
129132 else :
130133 mc .stop ()
0 commit comments