Program to control acceleration of a car

6 visualizzazioni (ultimi 30 giorni)
Ryan
Ryan il 22 Ott 2014
Commentato: Jon Boerner il 23 Ott 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 Commento
Jon Boerner
Jon Boerner il 23 Ott 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by