udacity / self-driving-car-sim

A self-driving car simulator built with Unity
http://udacity.com/self-driving-car
MIT License
3.88k stars 1.5k forks source link

Term 3 Simulator: Time Mismatch between Ego Vehicle and Sensor Fusion Data #98

Open ser94mor opened 5 years ago

ser94mor commented 5 years ago

Hello!

I have been doing the path planning project for a long time. The last problem that I've fought was collision avoidance with a car in front of the ego vehicle. I struggle to do this for several days, checked my code multiple times, wrote unit tests for critical parts. Here is what I have found.

I assumed that at some time T, I receive the response from the simulator with data about ego car at time T and data about other cars at time T. Based on this reasonable assumption, I calculated predicted positions for other vehicles. That is, assume that I generate trajectories of length N and at time T have K points left in my previous path (K < N). My path planner needs to generate N-K more points. At the Kth point from the previous path, the time would be T+0.02*K. The Kth entry from the previous path is the starting point for the generation of the new trajectory of length N-K. The Kth point is the starting point for the behavior planner (time T+0.02*K), and the end point is some time T+0.02*K+Tb in the future (Tb is a behavior planning horizon). So, I generated predictions for other cars with the time 0.02*K+Tb into the future. It is reasonable since sensor fusion information was obtained at time point T.

However, despite all my hard work on resolving the problem, collisions between ego vehicle and a vehicle in front of it always happened. Collisions always happened, until I changed prediction time from 0.02*K+Tb to Tb. That is like the simulator sent me data about the ego vehicle at time T and data about other vehicles at time T+0.02*K. After this change, my collision avoidance code works perfectly and maintains the expected buffer between the cars (of approximate length in meters as I specified in the settings).

TO SUM UP: simulator sends information about the ego vehicle at time T and sensor fusion information about other cars at time T+0.02*K, where K equals the number of points left in the previous path.

I am reasonably confident that this timing mismatch is not caused by the code I have written. I have a separate prediction module, which is covered by unit tests. Unit tests use two simplified versions of a track (highway maps), which is a straight line and a circle. For both synthetic tracks, the results of my prediction module are as expected.