Contents
% The Controller simulation contains two steps: % The first step computes the controller gains i.e. tunes the PID % controller with the Twiddle method % The second step uses the PID controller and control the AC for tracking a path % During the simulation several objects are created: % my_car which belongs to the 'dacia' class (bicycle model) % my_PID which belongs to the 'con_PID' class (the PID controller) % my_comp which belongs to the 'comp' class (the comparator)
Tuning the controller
Use the twiddle function which use the error_sim_daci() function in order to compute the Total Error Several simulations are made during the tuning process. The simulated AC belong also to the ‘dacia’ class. The parameters which are used here by the object constructor are: the pose [0;1;0]; the initial steering angle 0; the speed of the car 1m/s the perturbations [0,0].
figure xlabel 'Epochs' ylabel 'The total error TE' grid Parametrii=twiddle;
The simulation
Parametrii=[0.6,9.0,0.0001]; % Simulation parameters: Timp_simulare=560; %Simulation time Pasi_simulare=length(1:Timp_simulare); % Desired trajectory poz_dor_x=[0,80,80,0,0,-80,-80,0]; poz_dor_y=[-60,-60,20,20,60,60,-60,-60]; % The initial pose of the AC ppostura=[0;-60;0]; %Creating the objects: % The AC: pose [x=0;y=-60;alf=0]; gama=0 speed=1, perturbations=[0,0] my_car=dacia([0;-60;0],0,1,[0,0]); % The PID controller my_Pid=con_PID(Parametrii(1,1),Parametrii(1,2),Parametrii(1,3)); % The Comparator my_comp=comp([poz_dor_x;poz_dor_y]); [my_comp,eroarea_initiala]=my_comp.go(ppostura);% computing the initial error my_Pid.Eroarea=eroarea_initiala; eroarea=eroarea_initiala; % The control loop for i=1:Pasi_simulare [my_Pid,comanda]=my_Pid.go(eroarea); gama=0.5*(2/(1+exp(-0.5*comanda))-1); my_car.Gama=gama; my_car=my_car.go(0,0,0); P=[my_car.Postura.x;my_car.Postura.y;my_car.Postura.alf]; [my_comp,eroarea]=my_comp.go(P); end
The graphical representation
my_car.desen title 'The AC trajectory' hold; plot(poz_dor_x, poz_dor_y,'r','linewidth',2) xlabel 'X' ylabel 'Y'
Current plot held Current plot released Current plot held
Supplementary Simulations