@@ -93,6 +93,7 @@ def simulate(
93
93
obs , info = wrapped_env .reset ()
94
94
info ["ctrl_timestep" ] = CTRL_DT
95
95
info ["ctrl_freq" ] = CTRL_FREQ
96
+ lap_finished = False
96
97
# obs = [x, x_dot, y, y_dot, z, z_dot, phi, theta, psi, p, q, r]
97
98
vicon_obs = [obs [0 ], 0 , obs [2 ], 0 , obs [4 ], 0 , obs [6 ], obs [7 ], obs [8 ], 0 , 0 , 0 ]
98
99
ctrl = ctrl_class (vicon_obs , info , verbose = config .verbose )
@@ -135,13 +136,13 @@ def simulate(
135
136
i += 1
136
137
# Break early after passing the last gate (=> gate -1) or task completion
137
138
if terminate_on_lap and info ["current_target_gate_id" ] == - 1 :
138
- info ["task_completed" ] = True
139
+ info ["task_completed" ], lap_finished = True , True
139
140
if info ["task_completed" ]:
140
141
done = True
141
142
142
143
# Learn after the episode if the controller supports it
143
144
ctrl .episode_learn () # Update the controller internal state and models.
144
- log_episode_stats (stats , info , config , curr_time )
145
+ log_episode_stats (stats , info , config , curr_time , lap_finished )
145
146
ctrl .episode_reset ()
146
147
# Reset the statistics
147
148
stats ["ep_reward" ] = 0
@@ -155,14 +156,14 @@ def simulate(
155
156
return ep_times
156
157
157
158
158
- def log_episode_stats (stats : dict , info : dict , config : Munch , curr_time : float ):
159
+ def log_episode_stats (stats : dict , info : dict , config : Munch , curr_time : float , lap_finished : bool ):
159
160
"""Log the statistics of a single episode."""
160
161
stats ["gates_passed" ] = info ["current_target_gate_id" ]
161
162
if stats ["gates_passed" ] == - 1 : # The drone has passed the final gate
162
163
stats ["gates_passed" ] = len (config .quadrotor_config .gates )
163
164
if config .quadrotor_config .done_on_collision and info ["collision" ][1 ]:
164
165
termination = "COLLISION"
165
- elif config .quadrotor_config .done_on_completion and info ["task_completed" ]:
166
+ elif config .quadrotor_config .done_on_completion and info ["task_completed" ] or lap_finished :
166
167
termination = "TASK COMPLETION"
167
168
elif config .quadrotor_config .done_on_violation and info ["constraint_violation" ]:
168
169
termination = "CONSTRAINT VIOLATION"
0 commit comments