Program to control acceleration of a car

5 views (last 30 days)
Ryan
Ryan on 22 Oct 2014
Commented: Jon Boerner on 23 Oct 2014
Hello, I am trying to create a program to control the acceleration of a car. The car has accelerate up to the speed limit or the car in front of it, which ever is slower and decelerate to avoid a collision if necessary. There are comfortable limits for deceleration and acceleration.
The first test case is the simplest and involves accelerating up to meet a car and then following it. I can get up behind it, but my acceleration and deceleration oscillate extremely. The graph of acceleration bounces back forth between the max and min acceleration..
How can I fix this?
if true
% code
% D(n) is the distance to the car in front at time n
% VL is the velocity of the lead car
% V(n) is the velocity of the car at time n
if D(n)>(8*V(n)) % accel comfortably until within 8sec of car in front
a=AccelLimit;
elseif(VL-V(n))<0
a= min((100/((D(n))))*((VL-V(n))/dt),AccelLimit);% if the car in front is going slower, we want our deceleration to be proportional to diff in VL-V(n) and inverse to D(n)
elseif D(n)<1
a=DecelLimit;
else
a=min((0.01*(D(n))*((VL-V(n))/dt)),DecelLimit); % if the car in front is going faser, we want our acceleration to be proportional to D(n) and VL-V(n)
end
end
Thanks!
  1 Comment
Jon Boerner
Jon Boerner on 23 Oct 2014
Hi Ryan,
Could you post enough code so we can see the behavior you are talking about? For example, I would imagine you have a loop and some variable definitions. It would be a lot easier to take a look if you did that.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!