Skip to content

Commit 86f8d7d

Browse files
Fixed a bug where gates_visited and obstacles_visited would not be updated if the practice_without_track_objects setting was enabled.
1 parent c1b7194 commit 86f8d7d

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

lsy_drone_racing/envs/drone_racing_deploy_env.py

+27-20
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,18 @@ def close(self):
185185
RETURN_DURATION = 5.0 # s
186186
LAND_DURATION = 4.5 # s
187187

188-
try: # prevent hanging process if drone not reachable
188+
try: # prevent hanging process if drone not reachable
189189
self.cf.notifySetpointsStop()
190190
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+
)
193195
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
196200

197201
return_pos[:2] = self.config.env.track.drone.pos[:2]
198202
self.cf.goTo(goal=return_pos, yaw=0, duration=RETURN_DURATION)
@@ -201,7 +205,7 @@ def close(self):
201205
self.cf.land(self.config.env.track.drone.pos[2], LAND_DURATION)
202206
time.sleep(LAND_DURATION)
203207
except rospy.service.ServiceException as e:
204-
logger.error('Cannot return home: ' + str(e))
208+
logger.error("Cannot return home: " + str(e))
205209

206210
@property
207211
def obs(self) -> dict:
@@ -230,27 +234,30 @@ def obs(self) -> dict:
230234
obstacles_pos = np.array([o.pos for o in self.config.env.track.obstacles])
231235
obstacle_names = [f"obstacle{g}" for g in range(1, len(obstacles_pos) + 1)]
232236

237+
real_gates_pos = gates_pos
238+
real_gates_rpy = gates_rpy
239+
real_obstacles_pos = obstacles_pos
233240
# Update objects position with vicon data if not in practice mode and object
234241
# either is in range or was in range previously.
235242
if not self.config.deploy.practice_without_track_objects:
236243
real_gates_pos = np.array([self.vicon.pos[g] for g in gate_names])
237244
real_gates_rpy = np.array([self.vicon.rpy[g] for g in gate_names])
238245
real_obstacles_pos = np.array([self.vicon.pos[o] for o in obstacle_names])
239246

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}")
254261

255262
obs["gates_pos"] = gates_pos.astype(np.float32)
256263
obs["gates_rpy"] = gates_rpy.astype(np.float32)

0 commit comments

Comments
 (0)