metadriverse / scenarionet

ScenarioNet: Scalable Traffic Scenario Management System for Autonomous Driving
Apache License 2.0
142 stars 21 forks source link

Manipulating behavior of other vehicles #63

Open abastola0 opened 4 months ago

abastola0 commented 4 months ago

I wanted to alter the behavior of another vehicle so that it can for example overtake the default vehicle at certain point. I think there's a way where we can record the drive where we can overtake certain vehicle and later change the simulated vehicle to be non-default and the other one to be us. I wanted to this in digital twin obtained from waymo dataset but it seems to bit hard than what i expected. The other option i was thinking was executing IDM policy to navigate between points and provide some waypoints or a hand drawn line in the birds eye view where we can define the trajectory but the points seem to be in 3D so i'm not sure if changing only the 2D coordinates will be enough.

I was also thinking if this can be done with multi-agent planning but i'm not sure how to do this way.

Any of your suggestion would be highly appreciated.

QuanyiLi commented 4 months ago

If you take a look at the ScenarioEnv, you will find other cars are controlled by ScenarioTrafficManager. If you set no_traffic=True, this manager will be canceled and thus no vehicles/objects are added into the scene except the ego vehicle. The code is at: https://github.com/metadriverse/metadrive/blob/fc04519ff124670575eb3bba5cb9ea53587c3167/metadrive/envs/scenario_env.py#L123

Thus, to know how to change other car's behavior, you need to figure out how ScenarioTrafficManager works. By default, it replays the trajectories for all objects. But we also introduce a key, reactive_traffic, which, if enabled, can make other vehicles react to the ego car. If ego car behaves different from the recorded trajectory, for example, slowing down, the rear cars will slow down as well to avoid collision. I believe this is a good example that how we alter the behaviors of surrounding vehicles. Also, the documentation of MetaDrive provides detailed explanation of whole system: https://metadrive-simulator.readthedocs.io/en/latest/. It is worth to read it before you move forward.

If you are familiar with these stuff, the challenge now is how would you alter the trajectory of the target vehicle. The information you have is the original trajectory. Sometime, you can even find a path or route which leads you from start point to end point by BFS. Besides, each step, your vehicle can perceive the surrounding objects with pseudo-lidar. Thus, with these information you should be able to program a tiny self-driving system and allow it to overtake objects. But to be honest, this is as hard as building a driving system from scratch...

Let's go back to your idea. If you can pre-calculate the overtaking point and the overtaking trajectory from the top down view, yes, you can directly make a simple PID controller to track that trajectory. Actually, the IDM policy used in MetaDrive uses two PID controller to track the planned trajectories. When doing this, you may need some debug tools documented here: https://metadrive-simulator.readthedocs.io/en/latest/points_and_lines.html

abastola0 commented 4 months ago

Thus, to know how to change other car's behavior, you need to figure out how ScenarioTrafficManager works. By default, it replays the trajectories for all objects. But we also introduce a key, reactive_traffic, which, if enabled, can make other vehicles react to the ego car. If ego car behaves different from the recorded trajectory, for example, slowing down, the rear cars will slow down as well to avoid collision. I believe this is a good example that how we alter the behaviors of surrounding vehicles. Also, the documentation of MetaDrive provides detailed explanation of whole system: https://metadrive-simulator.readthedocs.io/en/latest/. It is worth to read it before you move forward.

Thanks Quanyi. I'll look at the PID tracking part and see if i can get things to work.