Template Simplified

This template shows how to simulate a simple vehicle and plot the results.


Simulation models and parameters

First, all classes of the package are imported with

clear ; close all ; clc

import VehicleDynamicsLongitudinal.*

Choosing vehicle model.

% Choosing vehicle
VehicleModel = VehicleModelNonlinear();

Choosing simulation time span

T       = 70;                       % Total simulation time         [s]
resol   = 100;                       % Resolution
TSPAN   = 0:T/resol:T;              % Time span                     [s]

To define a simulation object (simulator) the arguments must be the vehicle object and the time span.

simulator = Simulator(VehicleModel, TSPAN);

Run simulation

To simulate the system we run the Simulate method of the simulation object.

options = 

  struct with fields:

              AbsTol: 1.0000e-06
                 BDF: []
              Events: []
         InitialStep: []
            Jacobian: []
           JConstant: []
            JPattern: []
                Mass: []
        MassSingular: []
            MaxOrder: []
             MaxStep: []
         NonNegative: []
         NormControl: []
           OutputFcn: []
           OutputSel: []
              Refine: []
              RelTol: 1.0000e-06
               Stats: []
          Vectorized: []
    MStateDependence: []
           MvPattern: []
        InitialSlope: []


The time series of each state is stored in separate variables. Retrieving states

X      = simulator.X;
V      = simulator.V;

Plotting the states

hold on ; grid on ; box on
xlabel('Time [s]')
ylabel('Speed [m/s]')

See Also