Borrar filtros
Borrar filtros

how to assign initial values to scalar quantities in simulink function. please help

6 visualizaciones (últimos 30 días)
function [P_dot, Q_dot, R_dot, phi_dot, theta_dot, psi_dot] = fcn(P,Q, R,phi, theta, psi, step_force_x, step_force_y, step_force_z)
%% parameters
mass = 5;
x = 0.3; % length
y = 0.2; % width
z = 0.1; % height
rx = 0.1; ry = 0.2; rz = 0.1;
% equations
tow_x = ((ry * step_force_z) - (rz * step_force_y)); % along x-axis
tow_y = ((rz * step_force_x) - (rx * step_force_z)); % along y-axis
tow_z = ((rx * step_force_y) - (ry * step_force_x)); % along z-axis
Jx = (mass / 12) * (y^2 + z^2);
Jy = (mass / 12) * (x^2 + z^2);
Jz = (mass / 12) * (x^2 + y^2);
Jxz = 0;
omega_x = tow_x / Jx; % calculating initial values of angular velocity
omega_y = tow_y / Jy;
omega_z = tow_z / Jz;
% Angular moments
Lx = Jx * omega_x;
Ly = Jy * omega_y;
Lz = Jz * omega_z;
% Calculate gamma
gamma = (Jx * Jz) - (Jxz^2);
% OMEGA_dot
P_dot = ((Jxz*(Jx-Jy+Jz)*P*Q)/gamma) - (((Jz*(Jz-Jy)+Jxz^2)*Q*R)/gamma) + ((Jxz*Lz)/gamma) + (Jz*Lx)/gamma;
Q_dot = ((Jz - Jx)*P*R)/Jy - (Jxz*(P^2 - R^2))/ Jy + (Ly / Jy);
R_dot = ((Jx*(Jx-Jy)+Jxz^2)*(P*Q)/gamma) - (((Jxz*(Jx-Jy+Jz))*P*R)/gamma) + ((Jx*Lz)/gamma) + (Jxz*Lx)/gamma;
%EUL_dot
phi_dot = P + Q * sin(phi) * tan(theta) + R * cos(phi) * tan(theta);
theta_dot = Q * cos(phi) - (R * sin(phi));
psi_dot = Q * sin(phi) / cos(theta) + R * cos(phi) / cos(theta);
end

Respuesta aceptada

Sam Chak
Sam Chak el 9 de Ag. de 2023
You can insert the initial values in the Integrator block as shown in the example below:

Más respuestas (0)

Categorías

Más información sobre Engines & Motors en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by