MCPcopy Create free account
hub / github.com/OpenDriveLab/TCP / run_step

Method run_step

leaderboard/team_code/roach_ap_agent.py:304–363  ·  view source on GitHub ↗
(self, input_data, timestamp)

Source from the content-addressed store, hash-verified

302
303 @torch.no_grad()
304 def run_step(self, input_data, timestamp):
305 if not self.initialized:
306 self._init()
307
308 self.step += 1
309
310 if self.step < 20:
311
312 control = carla.VehicleControl()
313 control.steer = 0.0
314 control.throttle = 0.0
315 control.brake = 0.0
316 self.last_control = control
317 return control
318
319 if self.step % 2 != 0:
320 return self.last_control
321 tick_data, policy_input, rendered, target_gps, target_command = self.tick(input_data, timestamp)
322
323 gps = self._get_position(tick_data)
324
325 near_node, near_command = self._waypoint_planner.run_step(gps)
326 far_node, far_command = self._command_planner.run_step(gps)
327
328 actions, values, log_probs, mu, sigma, features = self._policy.forward(
329 policy_input, deterministic=True, clip_action=True)
330 control = self.process_act(actions)
331
332 render_dict = {"rendered": rendered, "action": actions}
333
334 # additional collision detection to enhance safety
335 should_brake = self.collision_detect()
336 only_ap_brake = True if (control.brake <= 0 and should_brake) else False
337 if should_brake:
338 control.steer = control.steer * 0.5
339 control.throttle = 0.0
340 control.brake = 1.0
341 render_dict = {"rendered": rendered, "action": actions, "should_brake":str(should_brake),}
342
343 render_img = self.im_render(render_dict)
344
345 supervision_dict = {
346 'action': np.array([control.throttle, control.steer, control.brake], dtype=np.float32),
347 'value': values[0],
348 'action_mu': mu[0],
349 'action_sigma': sigma[0],
350 'features': features[0],
351 'speed': tick_data['speed'],
352 'target_gps': target_gps,
353 'target_command': target_command,
354 'should_brake': should_brake,
355 'only_ap_brake': only_ap_brake,
356 }
357 if SAVE_PATH is not None and self.step % 10 == 0:
358 self.save(near_node, far_node, near_command, far_command, tick_data, supervision_dict, render_img, should_brake)
359
360 steer = control.steer
361 control.steer = steer + 1e-2 * np.random.randn()

Callers 1

tickMethod · 0.45

Calls 8

_initMethod · 0.95
tickMethod · 0.95
_get_positionMethod · 0.95
process_actMethod · 0.95
collision_detectMethod · 0.95
im_renderMethod · 0.95
saveMethod · 0.95
forwardMethod · 0.45

Tested by

no test coverage detected