% Script to calculate the velocity and distance profiles of a vehicle
%The vehicle has a non-uniform
% acceleration model of the form:

% dV/dt = k1 - k2 * V
%
% where:
%
% dV/dt = acceleration = acceleration (m/s-s)
% V = speed = vehicle speed (m/s) 
% S = distance = distance traveled (m)
% k1 = maximum acceleration (m/s-s)
% k2 = slope of dV/dt vs V profile (1/s)

% Programmer: T. Trani
% Date: 10/15/2013

% Enter constants of the problem

k1 = 3.0;          % maximum acceleration (m/s-s)
k2 = 0.02;        % slope of dV/dt vs. V curve ((1/s)
Vo = 0;             % initial speed (m/s)
time = 0:0.01:50;     % time vector to estimate velocity vs time profile (s)
So = 0;             % initial distance traveled (m)

% Solve equations by caling the function speedDistanceCalculator.m

[speed, distance, acceleration]= speedDistanceCalculator(k1,k2,time,Vo,So);

% Plot the results

% Plot vehicle acceleration (a), speed (V) and position (x)
figure
subplot(2,1,1)
plot(time,acceleration,'o-')
xlabel ('Time (s)','fontsize',22)
ylabel ('Acceleration (m/s-s)','fontsize',22)
grid   

subplot(2,1,2)
plot(time,speed,'o-')
xlabel ('Time (s)','fontsize',22)
ylabel ('Speed (m/s)','fontsize',22)
grid 

figure
subplot(2,1,1)
plot(time,speed,'o-')
xlabel ('Time (s)','fontsize',22)
ylabel ('Speed (m/s)','fontsize',22)
grid 

subplot(2,1,2)
plot(time,distance,'o-')
xlabel ('Time (s)','fontsize',22)
ylabel ('Position (m)','fontsize',22)
grid 

% Plot the acceleration vs speed to verify V vs. acceleration assumption

figure
plot(speed,acceleration,'o-')
xlabel ('Speed (m/s)','fontsize',22)
ylabel ('Acceleration (m/s-s)','fontsize',22)
grid 


