Lab7: Passing Logic

We discussed some of the basic issues in making cars pass in class. Now it is time to try to make this happen in your simulator.

If your car gets too close to another car directly in front of it, you want to pass.

To actually pass, you need to check if your car is within some safe distance from you. If it is safe, we need to move to some other lne. Our options are these:

  • If we are in the right land, pass into the middle lane
  • If we are in the left lane, pass into the middle lane
  • If we are in the middle lane, pass to either side.

Your ability to move into the chosen lane is based on there being room to do this. For this simple experiment, just calculate how far your vehicle is from vehicles on either side. This sounds like a search of sorts. All we need to do here is loop over all vehicles (except ours) and do our calculation. Our calculation subtracts the location of every car from the location of our car. We will get a number that is either positive (meaning we are ahead of that car), or negative (meaning that car is ahead of us). You are interested in the closest car ahead of you and behind you in the next lane. Then you are interested in the gap between those two cars.

If the gap is too small, or if oneof thse two vehicles is too close, we will not pass. Otherwise it is safe to pass into that lane. All you need to do for this test is “hop’ into the next lane.

Obviously, real passing logic is more complex than this, but this is about what my simulation does at this point. It still looks interesting.

Note

This will be the last lab involving the simulation of I35. After the exam, we will move on to other projects.