Clear Filters
Clear Filters

Help with longitudinal car following model based on spring / damper style interactions

2 views (last 30 days)
This is my attempt at creating a car following model using a pedal input u to produce an acceleration/deceleration and thus a velocity using euler integration. It's in it's early days so there may be some fundamental issues, but the theory is that a pedal input u is used to scale a max accel/brake at specific vehicle speeds using a lookup table / known values. The cruise control part is ok but I can't stop the cars from driving through eachother (ie. the cars won't follow). I've tried a range of values of gains and I now suspect the theory in my logic is flawed. The script is below and any help is appreciated.
close all
clear all
%% ------------------------------------------------------------------------
%VEHICLE (acceleration lookup table
Vehicle_Mass = 1675;
Total_Force = [0, 150.3, 293.4, 466.1, 611, 757.1, 884.9, 1024, 1164, 1316, 1481, 1639, 1799, 1974, 2141, 2325, 2502, 2673, 2861, 3030, 3218, 3428, 3633, 3862, 4106, 4363, 4618, 4888, 5199, 5558, 5898, 6296, 6734, 7151, 7610, 8037, 8550, 9121, 9705, 10420, 11170, 11850, 12620, 13380, 14240, 14960, 15740, 16610, 17570, 18460, 19100, 19800, 20750, 21300, 21550, 21550, 21200, 20600, 19850, 18950, 18000, 17150, 16100, 15000, 13000];
Vehicle_Speed = [73.484, 71.9, 70.4, 68.6, 67.1, 65.6, 64.3, 62.9, 61.5, 60, 58.4, 56.9, 55.4, 53.8, 52.3, 50.7, 49.2, 47.8, 46.3, 45, 43.6, 42.1, 40.77, 39.2, 37.7, 36.2, 34.8, 33.4, 31.9, 30.3, 28.9, 27.4, 25.9, 24.6, 23.3, 22.2, 21, 19.8, 18.7, 17.5, 16.4, 15.5, 14.6, 13.8, 13, 12.4, 11.8, 11.2, 10.6, 10.1, 9.7, 9.2, 8.3, 7.4, 6.3, 5.2, 3.8, 2.9, 2.1, 1.5, 1, 0.7, 0.4, 0.2, 0];
Max_Acceleration = Total_Force/Vehicle_Mass;
Max_Deceleration = -15*ones(size(Vehicle_Speed));
%% ------------------------------------------------------------------------
figure
plot(Vehicle_Speed, Max_Acceleration, 'Color', 'r', 'LineWidth', 2)
hold on
plot(Vehicle_Speed, Max_Deceleration, 'Color', 'r', 'LineWidth', 2);
ylim([-20 15])
xlim([0 74])
line([0,0], ylim, 'Color', 'k', 'LineWidth', 2);
line(xlim, [0,0], 'Color', 'k', 'LineWidth', 2)
xlabel('Vehicle Speed (m/s)')
ylabel('Max Vehicle Acceleration (m/s^2)')
grid on
grid MINOR
%% ------------------------------------------------------------------------
N = 1000; % length of sim
h = 0.01; % timestep
cars = 5; % number of cars
in_spac = 10; % initial spacing
a = zeros(cars, N); % acceleration matrix
v = zeros(cars, N); % velocity matrix
d_euler = zeros(cars, N); % distance matrix
d = zeros(cars, N); % distance matrix
u_rec = zeros(cars, N); % input matrix
v_target = randi([22 35],cars,1); % Random values of target speed between 50-80mph
k1 = 1; % gain 1
k2 = 1; % gain 2
for i = 1:N
for j = 1:cars
if v(j,i) < 0
v(j,i) = 0.1;
end
if j == cars || i == 1
u = ( -k1 * ( v(j,i) - v_target(j) ) ); %leading car (j = 5) pedal input according to target speed only
else
u = ( -k1 * ( v(j,i) - v_target(j) ) ) + ( -k2 * ( d(j+1,i-1) - d(j,i-1) ) ); %hooks law type interaction for second term
end
%conditions to keep u between -1 and 1
if u > 1
u = 1;
elseif u < -1
u = -1;
end
if u < 0
a(j,i) = u*15; %uniform max rate deceleration at all speeds
else
a(j,i) = u*interp1(Vehicle_Speed, Max_Acceleration, v(j,i),'spline');
end
v(j,i+1) = v(j,i) + a(j,i)*h;
d_euler(j,i+1) = d_euler(j,i) + v(j,i)*h;
if i == 1
d(j,i) = j*in_spac; %setting initial spacing
else
d(j,i) = d(j,1) + d_euler(j,i);
end
u_rec(j,i) = u; %recording the pedal input
end
end
figure
subplot(4,1,1)
plot(a')
ylabel('Acceleration')
grid on
grid minor
subplot(4,1,2)
plot(v')
ylabel('Velocity')
grid on
grid minor
subplot(4,1,3)
plot(d')
ylabel('Distance')
grid on
grid minor
subplot(4,1,4)
plot(u_rec')
ylabel('u')
grid on
grid minor

Answers (0)

Categories

Find more on Statics and Dynamics in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!