Clear Filters
Clear Filters

Variables are constant through the integration

1 view (last 30 days)
Marlon
Marlon on 7 Jun 2023
Commented: Marlon on 12 Jun 2023
Hi, I've got the problem that in the following code, all variable parameters from rv to Fwy are calculated with the initial values of the initial vector x and then set as constant over the integration. However, they should be calculatet with with the new state values of x in each integration step.
The code represents a vehicle dynamics model.
It would be great if somebody could help me with this. Thanks in advance!
clear all
%constant parameters:
m = 1700; % Fahrzeugmasse [kg]
lv = 1.2; % Abstand des Fahrzeugschwerpunkts zum Vorderachsmittelpunkt [m]
lh = 1.8; % Abstand des Fahrzeugschwerpunkts zum Hinterachsmittelpunkt [m]
iz = 500; % Trägheitsmoment um die Hochachse [kg*m^2]
cs = 10000; %Umfangssteifigkeit[N/°]
ca = 50000; %Schräglaufsteifigkeit[N/rad]
cx = 10000; %Reifenlängssteifigkeit
cy = 50000; %Seitetsteifigkeit
cw = 0.23; % CW Wert
pL = 1.2041; % Luftdichte [kg^m3]
A = 0.3; %[Windanströmfläche]
Jv = 1.245; %[kgm^2]
Jh = 1.245; %[kgm^2]
r = 0.49;
%Eingangsgrößen
delta = deg2rad(0); %[Lenkwinkel°]
Mav = 25.444132; %25.444132; %Antriebsmoment [Nm]
Mah = 25.444132;
Mbv = 0; %Bremsmoment [Nm]
Mbh = 0;
%Zeitbereich
tspan = [0 0.1 100];
% Initial Vector
x =[0; % x(1): XV - KS X Richtung
0; % x(2): YV - KS Y Richtung
0; % x(3): PSI - Gierwinkel
0; % x(4): XV' - Geschwindigkeit in X Richtung [m/s]
0; % x(5): YV' - Geschwindigkeit in Y Richtung [m/s]
0; % x(6): PSI' - Giergeschwindigkeit
102.573; % x(7): pv' Winkelgeschwindigkeit Vorderes Rad
102.573; % x(8): ph' Winkelgeschwindigkeit hinteres Rad
51.9268; % x(9): vFv,x Kraft Vorderreifen x-Richtung
0; % x(10): vFv,y Kraft Vorderreifen y-Richtung
51.9268; % x(11): hFh,x Kraft Hinterreifen x-Richtung
0]; % x(12): hFh,y Kraft Hinterreifen y-Richtung
%Variable parameters:
% Vektorkombination
rv = [x(4)-lv*x(6)+sin(x(3));
x(5)+lv*x(6)*cos(x(3));
0];
vrv = [cos(x(3)+delta) sin(x(3)+delta) 0;
-sin(x(3)+delta) cos(x(3)+delta) 0;
0 0 1]*rv;
rh = [x(4)-lh*x(6)+sin(x(3));
x(5)+lh*x(6)*cos(x(3));
0];
hrh = [cos(x(3)) sin(x(3)) 0;
-sin(x(3)) cos(x(3)) 0;
0 0 1]*rh;
% Schlupfwerte
% Längsschlupf
sv = (r* x(7)-rv(1))/(max(abs(r*x(7)),abs(vrv(1))));
sh = (r* x(8)-rh(1))/(max(abs(r*x(8)),abs(hrh(1))));
% Schräglaufschlupf
av = -(vrv(2)/abs(x(7)));
ah = -(hrh(2)/abs(x(8)));
% Reifenkräfte
vFvxstat = cs*sv;
vFvystat = ca*av;
hFhxstat = cs*sh;
hFhystat = ca*ah;
% Radkraft Hinterachse
Fhx = cos(x(3))*x(11)-sin(x(3))*x(12);
Fhy = sin(x(3))*x(11)+cos(x(3))*x(12);
% Radkraft Vorderachse
Fvx = cos(x(3) + delta)*x(9)-sin(x(3) + delta)*x(10);
Fvy = sin(x(3) + delta)*x(9)+cos(x(3) + delta)*x(10);
% Luftwiderstand
Fwx = 0.5*cw*pL*A*x(4)*((x(4))^2+(x(5))^2)^0.5;
Fwy = 0.5*cw*pL*A*x(5)*(x(4)^2+(x(5))^2)^0.5;
[t,x] = ode45(@(t,x) odefcn(x, m, Fvy, Fhy, Fvx, Fhx, Fwx,Fwy, Mav, Mah, Mbv, Mbh, r,iz,delta,lv,lh,Jv,Jh,cs,ca,cy,cx,vFvxstat,vFvystat,t,hFhxstat,hFhystat),tspan,x);
--subplots (..)--
function dxdt = odefcn(x, m, Fvy, Fhy, Fvx, Fhx, Fwx,Fwy, Mav, Mah, Mbv, Mbh, r,iz,delta,lv,lh,Jv,Jh,cs,ca,cy,cx,vFvxstat,vFvystat,t,hFhxstat,hFhystat)
dxdt = zeros(12,1);
dxdt(1) = x(4); %Geschwindigkeit x-Richtung
dxdt(2) = x(5); %Geschwindigkeit y-Richtung
dxdt(3) = x(6); %Gierbeschleunigung
dxdt(4) = (m^-1)*(Fvx+Fhx-Fwx); %Beschleunigung x-Richtung
dxdt(5) = (m^-1)*(Fvy+Fhy-Fwy); %Beschleunigung y-Richtung
dxdt(6) = ((iz^-1)*lv*sin(delta)*x(9)+cos(delta)*x(10)-lh*x(12)); %Gierbeschleunigung
dxdt(7) = (1/Jv)*(Mav-Mbv*sign(x(7))-r*x(9)); %Radwinkelgeschwindigkeit VA
dxdt(8) = (1/Jh)*(Mah-Mbh*sign(x(8))-r*x(11));%Radwinkelgeschwindigkeit HA
dxdt(9) = (cx*(r*x(7))/cs)*(vFvxstat-x(9)); %Radkraft VA X-Richtung
dxdt(10)= (cy*(r*x(7))/ca)*(vFvystat-x(10)); %Radkraft VA Y-Richtung
dxdt(11)= (cx*(r*x(8))/cs)*(hFhxstat-x(11)); %Radkraft VA X-Richtung
dxdt(12)= (cy*(r*x(8))/ca)*(hFhystat-x(12)); %Radkraft VA Y-Richtung
end

Answers (1)

Torsten
Torsten on 7 Jun 2023
Moved: Torsten on 7 Jun 2023
You have to pass only constants to "odefcn", but computations with the unknowns x have to be done within the function. Thus copy the complete computational part after the lines
%Variable parameters:
% Vektorkombination
into your function "odefcn".

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!