24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

init_MB.m 3.6 KB
Newer Older
Markus Koschi's avatar
Markus Koschi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
function x0 = init_MB(initState, p)
% init_MB - generates the initial state vector for the multi-body model
%
% Syntax:  
%     x0 = init_MB(initState, p)
%
% Inputs:
%     initState - core initial states
%     p - parameter vector
%
% Outputs:
%     x0 - initial state vector
%
% Example: 
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: ---

% Author:       Matthias Althoff
% Written:      11-January-2017
% Last update:  ---
% Last revision:---

%------------- BEGIN CODE --------------

%states
%x1 = s_x x-position in a global coordinate system
%x2 = s_y y-position in a global coordinate system
%x3 = δ steering angle of front wheels
%x4 = u velocity in x-direction
%x5 = Ψ yaw angle
%x6 = Ψ yaw rate

%x7 = ΦS roll angle
%x8 = ΦS roll rate
%x9 = ΘS pitch angle
%x10 = ΘS pitch rate
%x11 = v velocity in y-direction
%x12 = zS z-position
%x13 = w velocity in z-direction

%x14 = ΦUF roll angle front
%x15 = ΦUF roll rate front
%x16 = vUF velocity in y-direction front
%x17 = zUF z-position front
%x18 = wUF velocity in z-direction front

%x19 = ΦUR roll angle rear
%x20 = ΦUR roll rate rear
%x21 = vUR velocity in y-direction rear
%x22 = zUR z-position rear
%x23 = wUR velocity in z-direction rear

%x24 = ωLF left front wheel angular speed
%x25 = ωRF right front wheel angular speed
%x26 = ωLR left rear wheel angular speed
%x27 = ωRR right rear wheel angular speed

%x28 = delta_y_f
%x29 = delta_y_r

%u1 = v_delta steering angle velocity of front wheels
%u2 = acceleration


%obtain initial states from vector
sx0 = initState(1);
sy0 = initState(2);
vel0 = initState(3);
Psi0 = initState(4);
dotPsi0 = initState(5);
beta0 = initState(6);


%create equivalent bicycle parameters
g = 9.81; %[m/s^2]
mu = p.tire.p_dy1;
C_Sf = -p.tire.p_ky1/p.tire.p_dy1; 
C_Sr = -p.tire.p_ky1/p.tire.p_dy1; 
lf = p.a;
lr = p.b;

%initial steering angle from steady state of slip angle
delta0 = vel0*(lf + lr)/(C_Sf*g*lr*mu)*dotPsi0 ...
    + 1/(C_Sf*lr)*((C_Sr*lf + C_Sf*lr)*beta0 - (C_Sr - C_Sf)*lr*lf*dotPsi0/vel0);

%auxiliary initial states
F0_z_f = p.m_s*g*p.b/((p.a + p.b)) + p.m_uf*g;
F0_z_r = p.m_s*g*p.a/((p.a + p.b)) + p.m_ur*g;

%sprung mass states
x0(1) = sx0; % s_x x-position in a global coordinate system
x0(2) = sy0; % s_y y-position in a global coordinate system
x0(3) = delta0; % steering angle of front wheels
x0(4) = cos(beta0)*vel0; % u velocity in x-direction
x0(5) = Psi0; % Ψ yaw angle
x0(6) = dotPsi0; % Ψ yaw rate
x0(7) = 0; % ΦS roll angle
x0(8) = 0; % ΦS roll rate
x0(9) = 0; % ΘS pitch angle
x0(10) = 0; % ΘS pitch rate
x0(11) = sin(beta0)*vel0; % v velocity in y-direction
x0(12) = 0; % zS z-position (zero height corresponds to steady state solution)
x0(13) = 0; % w velocity in z-direction

%unsprung mass states (front)
x0(14) = 0; % ΦUF roll angle front
x0(15) = 0; % ΦUF roll rate front
x0(16) = sin(beta0)*vel0 + p.a*dotPsi0; % vUF velocity in y-direction front
x0(17) = (F0_z_f)/(2*p.K_zt); % zUF z-position front
x0(18) = 0; % wUF velocity in z-direction front

%unsprung mass states (rear)
x0(19) = 0; % ΦUR roll angle rear
x0(20) = 0; % ΦUR roll rate rear
x0(21) = sin(beta0)*vel0 - p.b*dotPsi0; % vUR velocity in y-direction rear
x0(22) = (F0_z_r)/(2*p.K_zt); % zUR z-position rear
x0(23) = 0; % wUR velocity in z-direction rear

%wheel states
x0(24) = x0(4)/(p.R_w); % ωLF left front wheel angular speed
x0(25) = x0(4)/(p.R_w); % ωRF right front wheel angular speed
x0(26) = x0(4)/(p.R_w); % ωLR left rear wheel angular speed
x0(27) = x0(4)/(p.R_w); % ωRR right rear wheel angular speed

x0(28) = 0; % delta_y_f
x0(29) = 0; % delta_y_r



%------------- END OF CODE --------------