flow
flow copied to clipboard
Changing the collision-action
How can I avoid the simulation stopping when a collision occurs when running examples/simulate.py? I just want the vehicles involved in the collision being teleported. I would like to modify the collision-action value (<collision.action value=“teleport” />), but where is it in Flow?
If you look at the base class of the flow environment, the crash/collision is implemented here.
If you want to avoid the vehicle ending the simulation you can change the crash logic to something like this. Here, I want to terminate the episode only if there is any rl vehicle collision. For the rest of the vehicles, it is ignored and the vehicle is teleported.
# Get ids of collided vehicles
collided_vehicle_ids = set(self.k.kernel_api.simulation.getStartingTeleportIDList())
if len(collided_vehicle_ids) > 0:
print(collided_vehicle_ids)
# Get rl vehicle ids
rl_vehicle_ids = set(['rl_0'])
# Get list of other vehicles minus rl vehicles
other_vehicle_ids = set(self.k.vehicle.get_ids()) - rl_vehicle_ids
if (len(rl_vehicle_ids.intersection(collided_vehicle_ids)) > 0):
print("Setting crash to true.")
crash = True