└── Traction Control System ├── FINAL REPORT.pdf ├── Traction Control System - Fuzzy Inference System.fis └── Traction Control System using PID & Fuzzy-PID controllers.m /Traction Control System/FINAL REPORT.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pritismankar-maan/Traction-Control-System-on-MATLAB/HEAD/Traction Control System/FINAL REPORT.pdf -------------------------------------------------------------------------------- /Traction Control System/Traction Control System - Fuzzy Inference System.fis: -------------------------------------------------------------------------------- 1 | [System] 2 | Name='traction_control_pid_gains109' 3 | Type='mamdani' 4 | Version=2.0 5 | NumInputs=2 6 | NumOutputs=2 7 | NumRules=50 8 | AndMethod='min' 9 | OrMethod='max' 10 | ImpMethod='min' 11 | AggMethod='max' 12 | DefuzzMethod='centroid' 13 | 14 | [Input1] 15 | Name='e' 16 | Range=[-1 2] 17 | NumMFs=7 18 | MF1='NL':'trimf',[-3 -1 -0.03] 19 | MF2='NM':'trimf',[-0.06 -0.03 -0.001] 20 | MF3='NS':'trimf',[-0.001 -0.0005 0] 21 | MF4='ZE':'trimf',[-0.0005 0 0.0005] 22 | MF5='PS':'trimf',[0 0.0005 0.001] 23 | MF6='PL':'trimf',[0.03 2 4] 24 | MF7='PM':'trimf',[0.001 0.03 0.06] 25 | 26 | [Input2] 27 | Name='de' 28 | Range=[-600 900] 29 | NumMFs=7 30 | MF1='NM':'trimf',[-450 -300 -150] 31 | MF2='ZE':'trimf',[-150 0 150] 32 | MF3='PM':'trimf',[150 475 900] 33 | MF4='NL':'trimf',[-900 -600 -300] 34 | MF5='NS':'trimf',[-300 -150 0] 35 | MF6='PS':'trimf',[0 150 300] 36 | MF7='PL':'trimf',[300 900 1500] 37 | 38 | [Output1] 39 | Name='Kp' 40 | Range=[0 10000] 41 | NumMFs=7 42 | MF1='S':'trimf',[1667 3333 5000] 43 | MF2='M':'trimf',[3333 5000 6667] 44 | MF3='ML':'trimf',[6667 8333 10000] 45 | MF4='ZE':'trimf',[-1667 0 1667] 46 | MF5='MS':'trimf',[0 1667 3333] 47 | MF6='L':'trimf',[5000 6667 8330] 48 | MF7='VL':'trimf',[8333 10000 11670] 49 | 50 | [Output2] 51 | Name='Ki' 52 | Range=[0 28000] 53 | NumMFs=7 54 | MF1='MS':'trimf',[0 4666 9331] 55 | MF2='M':'trimf',[9331 14000 18660] 56 | MF3='ML':'trimf',[18660 23330 28000] 57 | MF4='ZE':'trimf',[-200 0 200] 58 | MF5='S':'trimf',[4666 9331 14000] 59 | MF6='L':'trimf',[14000 18660 23330] 60 | MF7='VL':'trimf',[23330 28000 32670] 61 | 62 | [Rules] 63 | 1 4, 2 7 (1) : 1 64 | 1 5, 1 6 (1) : 1 65 | 1 2, 5 4 (1) : 1 66 | 1 6, 1 2 (1) : 1 67 | 3 4, 2 7 (1) : 1 68 | 3 5, 1 6 (1) : 1 69 | 3 2, 5 4 (1) : 1 70 | 3 6, 1 6 (1) : 1 71 | 3 7, 2 7 (1) : 1 72 | 1 7, 2 7 (1) : 1 73 | 4 4, 4 7 (1) : 1 74 | 4 5, 4 7 (1) : 1 75 | 4 2, 4 7 (1) : 1 76 | 4 6, 4 7 (1) : 1 77 | 4 7, 4 7 (1) : 1 78 | 5 4, 4 7 (1) : 1 79 | 5 5, 4 7 (1) : 1 80 | 5 2, 4 7 (1) : 1 81 | 5 6, 4 7 (1) : 1 82 | 5 7, 4 7 (1) : 1 83 | 6 4, 7 4 (1) : 1 84 | 6 5, 7 4 (1) : 1 85 | 6 2, 7 4 (1) : 1 86 | 6 3, 7 4 (1) : 1 87 | 6 7, 7 4 (1) : 1 88 | 6 6, 7 4 (1) : 1 89 | 7 2, 4 7 (1) : 1 90 | 7 3, 4 7 (1) : 1 91 | 7 6, 4 7 (1) : 1 92 | 7 7, 4 7 (1) : 1 93 | 7 7, 4 7 (1) : 1 94 | 7 1, 4 7 (1) : 1 95 | 7 4, 4 7 (1) : 1 96 | 7 5, 4 7 (1) : 1 97 | 7 5, 4 7 (1) : 1 98 | 1 1, 7 4 (1) : 1 99 | 1 3, 7 4 (1) : 1 100 | 1 7, 7 4 (1) : 1 101 | 3 1, 4 7 (1) : 1 102 | 3 3, 4 7 (1) : 1 103 | 4 1, 7 4 (1) : 1 104 | 4 3, 7 4 (1) : 1 105 | 5 1, 4 7 (1) : 1 106 | 5 3, 4 7 (1) : 1 107 | 7 1, 7 4 (1) : 1 108 | 7 3, 7 4 (1) : 1 109 | 6 1, 7 4 (1) : 1 110 | 6 1, 7 4 (1) : 1 111 | 6 3, 7 4 (1) : 1 112 | 1 7, 7 4 (1) : 1 113 | -------------------------------------------------------------------------------- /Traction Control System/Traction Control System using PID & Fuzzy-PID controllers.m: -------------------------------------------------------------------------------- 1 | %% APPENDIX 2 | clc;clear all;close all; 3 | %% Traction control system with Fuzzy PID 4 | GR_ax1 = 2.41; % Gear ratio of Axle 5 | GR_tran1 = 4.56; % Gear ratio of different gears 6 | 7 | I_tran1 = 0.147; % Inertia of different gears 8 | I_e1 = 0.09; % Inertia of engine 9 | I_d1 = 0.12; % Inertia of driveshaft 10 | I_ax1 = 0.003; % Inertia of Axle 11 | I_tire1 = 1.2; % Inertia of tire 12 | I_rear1 = I_tire1*2; % Inertia of rear wheels 13 | thetaderedline_dot1 = 6500; % Readline theta [RPM] 14 | M1 = 1665; % mass of car 15 | car_h1 = 1.23; % car's height 16 | car_w1 = 1.97; % car's width 17 | car_area1 = car_h1*car_w1; % car's area 18 | drag_c1 = 0.28; % Drag coefficient 19 | resi_c1 = 0.015; % Friction coefficient 20 | rho1 = 1.225; % air density 21 | I_dt1 = I_tire1 + GR_ax1^2*I_d1 + (GR_ax1^2*GR_tran1^2*(I_e1 + I_tran1)); % Drivetrain Inertia 22 | 23 | % based on Tire specification 24 | Rt_front1 = ((19*0.0254) + (2*((30*285)/100000)))/2; % Front tire radius 25 | Rt_rear1 = ((20*0.0254) + (2*((25*335)/100000)))/2; % Rear tire radius 26 | 27 | Meq_FT1 = (2*I_tire1)/(Rt_front1^2); 28 | Meq1 = M1 + Meq_FT1; 29 | 30 | fis = readfis; 31 | 32 | % evalute torque from engine specification 33 | P_hp1 = [0 10 40 80 160 220 240 270 330 400 480 540 620 660 670 675]; 34 | P_watt1 = P_hp1*746; 35 | thetae_dot_rpm1 = [0 500 1000 1500 2000 2100 2300 2500 3000 3500 4000 4500 5000 5500 6000 6500]; 36 | thetae_dot_rad1 = (2*pi/60)*thetae_dot_rpm1; 37 | T1 = P_watt1./thetae_dot_rad1; 38 | 39 | % evalute rolling resistance force 40 | F_fric1 = resi_c1*M1*9.8; 41 | 42 | N1 = 45001; % vector length 43 | dt1 = 0.0001; % time increment 44 | t1 = (0:dt1:(N1-1)*dt1); 45 | 46 | xdot1 = zeros(N1,1); % velocity vector for plot 47 | xdot1(1) = 5/2.23694; % initial velocity = 5mph 48 | 49 | x1 = zeros(N1,1); % distance vector for plot 50 | x1(1) = 0; % initial distance = 0m 51 | 52 | thetae_dot_rad_instant1 = zeros(N1,1); 53 | P_watt_instant1 = zeros(N1,1); 54 | T_instant1 = zeros(N1,1); 55 | 56 | thetaw_dot_req1 = zeros(N1,1); 57 | sr_instant1 = zeros(N1,1); 58 | thetaw_dot_req1(1) = xdot1(1)/Rt_rear1; 59 | thetaw_dot_instant1 = zeros(N1,1); 60 | t_force_instant1 = zeros(N1,1); 61 | xddot1 = zeros(N1,1); 62 | thetaw_ddot_instant1 = zeros(N1,1); 63 | sr_instant1(1) = 0.01; 64 | % calculate intial wheel angular velocity from slip ratio 65 | thetaw_dot_instant1(1) = xdot1(1)*(sr_instant1(1)+1)*(1/Rt_rear1); 66 | 67 | % input traction force vs slip ratio 68 | t_force1 = [0 2000 3333 4777 6000 6100 6400 6450 6500 6300 6000 5700 5200 5000 4800 4700 4600 4500 4400 4300]; 69 | sr1 = [0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.1 0.15 0.2 0.3 0.4 0.45 0.5 0.6 0.7 0.8 0.9 1]; 70 | 71 | sr_desired1 = 0.1; 72 | error1=zeros(N1,1); 73 | error1(1) = sr_desired1 - sr_instant1(1); 74 | Kp1 = 8000; Kd1 = 0; Ki1 = 7550; 75 | de1 = 0; error_sum1 = 0; 76 | for k = 2:N1 77 | % 1st gear only 78 | % get engine speed from wheel speed 79 | thetae_dot_rad_instant1(k-1) = (thetaw_dot_instant1(k-1)*GR_ax1*GR_tran1(1)); 80 | % PID Controller 81 | if k == 2 82 | de1 = error1(k-1); 83 | else 84 | de1 = error1(k-1) - error1(k-2); 85 | end 86 | error_sum1 = error1(k-1)*dt1 + error_sum1; 87 | % get Kp and Ki from FIS 88 | [K1] = evalfis(fis,[error1(k-1) de1/dt1]); 89 | 90 | de_wrt_t1(k-1) = de1/dt1; 91 | kp1(k-1) = K1(1); 92 | kd1(k-1) = Kd1; 93 | ki1(k-1) = K1(2); 94 | 95 | % Controlled Torque 96 | T_instant1(k-1) = kp1(k-1)*error1(k-1) + kd1(k-1)*(de1/dt1) + ki1(k-1)*error_sum1; 97 | % The torque can't drop's below zero, it's not possible 98 | if T_instant1(k-1) < 0 99 | T_instant1(k-1) = 0; 100 | end 101 | 102 | % logic to get tractive force 103 | if sr_instant1(k-1) >= 0 104 | t_force_instant1(k-1) = interp1(sr1,t_force1, ... 105 | sr_instant1(k-1)); 106 | else 107 | t_force_instant1(k-1) = 0; 108 | end 109 | % calculate linear acceleration (to get linear velocity for next iteration) 110 | xddot1(k-1) = ((t_force_instant1(k-1)/Meq1(1)) - ... 111 | (F_fric1/Meq1(1)) - ((0.5*rho1*drag_c1*car_area1/Meq1(1))* ... 112 | (xdot1(k-1).^2))); 113 | 114 | % calculate angular wheel acceleration (to get angular wheel velocity for next iteration) 115 | thetaw_ddot_instant1(k-1) = (-(t_force_instant1(k-1)*Rt_rear1/I_dt1) + ... 116 | (GR_ax1*GR_tran1*T_instant1(k-1)/I_dt1)); 117 | 118 | % use euler method to calculate speed and distance & angular wheel speed 119 | xdot1(k) = xdot1(k-1) + xddot1(k-1)*dt1; 120 | x1(k) = x1(k-1) + xdot1(k-1)*dt1; 121 | thetaw_dot_instant1(k) = thetaw_dot_instant1(k-1) + thetaw_ddot_instant1(k-1)*dt1; 122 | 123 | % get the actual velocity of car 124 | thetaw_dot_req1(k) = xdot1(k)/Rt_rear1; 125 | % get the new Slip ratio 126 | sr_instant1(k) = (thetaw_dot_instant1(k) - thetaw_dot_req1(k))/thetaw_dot_req1(k); 127 | error1(k) = sr_desired1 - sr_instant1(k); 128 | end 129 | 130 | % for fuzzy 131 | de_wrt_t1(k) = de_wrt_t1(k-1); 132 | kp1(k) = Kp1; 133 | kd1(k) = Kd1; 134 | ki1(k) = Ki1; 135 | 136 | %% Traction control system with PID 137 | 138 | GR_ax = 2.41; % Gear ratio of Axle 139 | GR_tran = 4.56; % Gear ratio of different gears 140 | 141 | I_tran = 0.147; % Inertia of different gears 142 | I_e = 0.09; % Inertia of engine 143 | I_d = 0.12; % Inertia of driveshaft 144 | I_ax = 0.003; % Inertia of Axle 145 | I_tire = 1.2; % Inertia of tire 146 | I_rear = I_tire*2; % Inertia of rear wheels 147 | thetaderedline_dot = 6500; % Readline theta [RPM] 148 | M = 1665; % mass of car 149 | car_h = 1.23; % car's height 150 | car_w = 1.97; % car's width 151 | car_area = car_h*car_w; % car's area 152 | drag_c = 0.28; % Drag coefficient 153 | resi_c = 0.015; % Friction coefficient 154 | rho = 1.225; % air density 155 | I_dt = I_tire + GR_ax^2*I_d + (GR_ax^2*GR_tran^2*(I_e + I_tran)); % Drivetrain Inertia 156 | 157 | % based on Tire specification 158 | Rt_front = ((19*0.0254) + (2*((30*285)/100000)))/2; % Front tire radius 159 | Rt_rear = ((20*0.0254) + (2*((25*335)/100000)))/2; % Rear tire radius 160 | 161 | Meq_FT = (2*I_tire)/(Rt_front^2); 162 | Meq = M + Meq_FT; 163 | 164 | % evalute torque from engine specification 165 | P_hp = [0 10 40 80 160 220 240 270 330 400 480 540 620 660 670 675]; 166 | P_watt = P_hp*746; 167 | thetae_dot_rpm = [0 500 1000 1500 2000 2100 2300 2500 3000 3500 4000 4500 5000 5500 6000 6500]; 168 | thetae_dot_rad = (2*pi/60)*thetae_dot_rpm; 169 | T = P_watt./thetae_dot_rad; 170 | 171 | % evalute rolling resistance force 172 | F_fric = resi_c*M*9.8; 173 | 174 | N = 45001; % vector length 175 | dt = 0.0001; % time increment 176 | t = (0:dt:(N-1)*dt); 177 | 178 | xdot = zeros(N,1); % velocity vector for plot 179 | xdot(1) = 5/2.23694; % initial velocity = 5mph 180 | 181 | x = zeros(N,1); % distance vector for plot 182 | x(1) = 0; % initial distance = 0m 183 | 184 | thetae_dot_rad_instant = zeros(N,1); 185 | P_watt_instant = zeros(N,1); 186 | T_instant = zeros(N,1); 187 | 188 | thetaw_dot_req = zeros(N,1); 189 | sr_instant = zeros(N,1); 190 | thetaw_dot_req(1) = xdot(1)/Rt_rear; 191 | thetaw_dot_instant = zeros(N,1); 192 | t_force_instant = zeros(N,1); 193 | xddot = zeros(N,1); 194 | thetaw_ddot_instant = zeros(N,1); 195 | sr_instant(1) = 0.01; 196 | % calculate intial wheel angular velocity from slip ratio 197 | thetaw_dot_instant(1) = xdot(1)*(sr_instant(1)+1)*(1/Rt_rear); 198 | 199 | % input traction force vs slip ratio 200 | t_force = [0 2000 3333 4777 6000 6100 6400 6450 6500 6300 6000 5700 5200 5000 4800 4700 4600 4500 4400 4300]; 201 | sr = [0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.1 0.15 0.2 0.3 0.4 0.45 0.5 0.6 0.7 0.8 0.9 1]; 202 | 203 | sr_desired = 0.1; 204 | error=zeros(N,1); 205 | error(1) = sr_desired - sr_instant(1); 206 | Kp = 8000; Kd = 0; Ki = 7550; 207 | de = 0; error_sum = 0; 208 | for k = 2:N 209 | % 1st gear only 210 | % get engine speed from wheel speed 211 | thetae_dot_rad_instant(k-1) = (thetaw_dot_instant(k-1)*GR_ax*GR_tran(1)); 212 | % Instead of getting torque from Engine speed, torque is controlled through 213 | % PID Controller 214 | if k == 2 215 | de = error(k-1); 216 | else 217 | de = error(k-1) - error(k-2); 218 | end 219 | error_sum = error(k-1)*dt + error_sum; 220 | % related to fuzzy 221 | de_wrt_t(k-1) = de/dt; 222 | kp(k-1) = Kp; 223 | kd(k-1) = Kd; 224 | ki(k-1) = Ki; 225 | 226 | % Controlled Torque 227 | T_instant(k-1) = Kp*error(k-1) + Kd*(de/dt) + Ki*error_sum; 228 | % The torque can't drop's below zero, it's not possible 229 | if T_instant(k-1) < 0 230 | T_instant(k-1) = 0; 231 | end 232 | 233 | % logic to get tractive force 234 | if sr_instant(k-1) >= 0 235 | t_force_instant(k-1) = interp1(sr,t_force, ... 236 | sr_instant(k-1)); 237 | else 238 | t_force_instant(k-1) = 0; 239 | end 240 | % calculate linear acceleration (to get linear velocity for next iteration) 241 | xddot(k-1) = ((t_force_instant(k-1)/Meq(1)) - ... 242 | (F_fric/Meq(1)) - ((0.5*rho*drag_c*car_area/Meq(1))* ... 243 | (xdot(k-1).^2))); 244 | 245 | % calculate angular wheel acceleration (to get angular wheel velocity for next iteration) 246 | thetaw_ddot_instant(k-1) = (-(t_force_instant(k-1)*Rt_rear/I_dt) + ... 247 | (GR_ax*GR_tran*T_instant(k-1)/I_dt)); 248 | 249 | % use euler method to calculate speed and distance & angular wheel speed 250 | xdot(k) = xdot(k-1) + xddot(k-1)*dt; 251 | x(k) = x(k-1) + xdot(k-1)*dt; 252 | thetaw_dot_instant(k) = thetaw_dot_instant(k-1) + thetaw_ddot_instant(k-1)*dt; 253 | 254 | % get the actual velocity of car 255 | thetaw_dot_req(k) = xdot(k)/Rt_rear; 256 | % get the new Slip ratio 257 | sr_instant(k) = (thetaw_dot_instant(k) - thetaw_dot_req(k))/thetaw_dot_req(k); 258 | error(k) = sr_desired - sr_instant(k); 259 | end 260 | 261 | % for fuzzy 262 | de_wrt_t(k) = de_wrt_t(k-1); 263 | kp(k) = Kp; 264 | kd(k) = Kd; 265 | ki(k) = Ki; 266 | 267 | figure 268 | plot(sr,t_force,'linewi',2),xlabel('Slip Ratio'),ylabel('Tractive Force [N]'), 269 | title('Tractive force vs. Slip Ratio'),grid on 270 | 271 | %% comparsion between PID and Fuzzy-PID Controller 272 | 273 | figure 274 | plot(t,thetaw_dot_instant*Rt_rear*2.23694,t,thetaw_dot_instant1*Rt_rear*2.23694,'linewi',2) 275 | xlabel('time [s]'),ylabel('velocity [mph]') 276 | title('ZR1 velocity, 5 mph rolling start'),grid on 277 | legend('PID','Fuzzy PID') 278 | 279 | figure 280 | plot(t,sr_instant,t,sr_instant1,'linewi',2) 281 | xlabel('time [s]'),ylabel('Current Slip ratio'),grid on 282 | title('Slip ratio') 283 | legend('PID','Fuzzy PID') 284 | 285 | figure 286 | plot(t,t_force_instant,t,t_force_instant1,'linewi',2),grid on 287 | xlabel('time [s]'),ylabel('Tractive force [N]') 288 | title('Tractive force vs. time') 289 | legend('PID','Fuzzy PID') 290 | 291 | figure 292 | plot(t,T_instant,t,T_instant1,'linewi',2),grid on 293 | xlabel('time [s]'),ylabel('Torque [N-m]') 294 | title('Torque vs. time') 295 | legend('PID','Fuzzy PID') 296 | 297 | figure 298 | plot(t,kp,t,ki,t,kp1,t,ki1,'linewi',2),grid on 299 | xlabel('time [s]') 300 | legend('Kp(PID)','Ki(PID)','Kp(Fuzzy PID)','Ki(Fuzzy PID)') 301 | --------------------------------------------------------------------------------