@@ -185,14 +185,18 @@ def close(self):
185
185
RETURN_DURATION = 5.0 # s
186
186
LAND_DURATION = 4.5 # s
187
187
188
- try : # prevent hanging process if drone not reachable
188
+ try : # prevent hanging process if drone not reachable
189
189
self .cf .notifySetpointsStop ()
190
190
obs = self .obs
191
-
192
- return_pos = obs ['pos' ] + obs ['vel' ]/ (np .linalg .norm (obs ['vel' ]) + 1e-8 ) * BREAKING_DISTANCE
191
+
192
+ return_pos = (
193
+ obs ["pos" ] + obs ["vel" ] / (np .linalg .norm (obs ["vel" ]) + 1e-8 ) * BREAKING_DISTANCE
194
+ )
193
195
return_pos [2 ] = RETURN_HEIGHT
194
- self .cf .goTo (goal = return_pos , yaw = 0 , duration = BREAKING_DURATION )
195
- time .sleep (BREAKING_DURATION - 1 ) # Smoothly transition to next position by setting the next goal earlier
196
+ self .cf .goTo (goal = return_pos , yaw = 0 , duration = BREAKING_DURATION )
197
+ time .sleep (
198
+ BREAKING_DURATION - 1
199
+ ) # Smoothly transition to next position by setting the next goal earlier
196
200
197
201
return_pos [:2 ] = self .config .env .track .drone .pos [:2 ]
198
202
self .cf .goTo (goal = return_pos , yaw = 0 , duration = RETURN_DURATION )
@@ -201,7 +205,7 @@ def close(self):
201
205
self .cf .land (self .config .env .track .drone .pos [2 ], LAND_DURATION )
202
206
time .sleep (LAND_DURATION )
203
207
except rospy .service .ServiceException as e :
204
- logger .error (' Cannot return home: ' + str (e ))
208
+ logger .error (" Cannot return home: " + str (e ))
205
209
206
210
@property
207
211
def obs (self ) -> dict :
@@ -230,27 +234,30 @@ def obs(self) -> dict:
230
234
obstacles_pos = np .array ([o .pos for o in self .config .env .track .obstacles ])
231
235
obstacle_names = [f"obstacle{ g } " for g in range (1 , len (obstacles_pos ) + 1 )]
232
236
237
+ real_gates_pos = gates_pos
238
+ real_gates_rpy = gates_rpy
239
+ real_obstacles_pos = obstacles_pos
233
240
# Update objects position with vicon data if not in practice mode and object
234
241
# either is in range or was in range previously.
235
242
if not self .config .deploy .practice_without_track_objects :
236
243
real_gates_pos = np .array ([self .vicon .pos [g ] for g in gate_names ])
237
244
real_gates_rpy = np .array ([self .vicon .rpy [g ] for g in gate_names ])
238
245
real_obstacles_pos = np .array ([self .vicon .pos [o ] for o in obstacle_names ])
239
246
240
- # Use x-y distance to calucate sensor range, otherwise it would depend on the height of the drone
241
- # and obstacle how early the obstacle is in range.
242
- in_range = np .linalg .norm (real_gates_pos [:, :2 ] - drone_pos [:2 ], axis = 1 ) < sensor_range
243
- self .gates_visited = np .logical_or (self .gates_visited , in_range )
244
- gates_pos [self .gates_visited ] = real_gates_pos [self .gates_visited ]
245
- gates_rpy [self .gates_visited ] = real_gates_rpy [self .gates_visited ]
246
- obs ["gates_visited" ] = in_range
247
-
248
- in_range = (
249
- np .linalg .norm (real_obstacles_pos [:, :2 ] - drone_pos [:2 ], axis = 1 ) < sensor_range
250
- )
251
- self .obstacles_visited = np . logical_or ( self .obstacles_visited , in_range )
252
- obstacles_pos [ self . obstacles_visited ] = real_obstacles_pos [ self .obstacles_visited ]
253
- obs [ " obstacles_visited" ] = in_range
247
+ # Use x-y distance to calucate sensor range, otherwise it would depend on the height of the drone
248
+ # and obstacle how early the obstacle is in range.
249
+ in_range = np .linalg .norm (real_gates_pos [:, :2 ] - drone_pos [:2 ], axis = 1 ) < sensor_range
250
+ self .gates_visited = np .logical_or (self .gates_visited , in_range )
251
+ gates_pos [self .gates_visited ] = real_gates_pos [self .gates_visited ]
252
+ gates_rpy [self .gates_visited ] = real_gates_rpy [self .gates_visited ]
253
+ obs ["gates_visited" ] = self . gates_visited
254
+ print ( f"gates visited: { self . gates_visited } " )
255
+
256
+ in_range = np .linalg .norm (real_obstacles_pos [:, :2 ] - drone_pos [:2 ], axis = 1 ) < sensor_range
257
+ self . obstacles_visited = np . logical_or ( self . obstacles_visited , in_range )
258
+ obstacles_pos [ self .obstacles_visited ] = real_obstacles_pos [ self .obstacles_visited ]
259
+ obs [ " obstacles_visited" ] = self .obstacles_visited
260
+ print ( f"obs visited: { self . obstacles_visited } " )
254
261
255
262
obs ["gates_pos" ] = gates_pos .astype (np .float32 )
256
263
obs ["gates_rpy" ] = gates_rpy .astype (np .float32 )
0 commit comments