mirror of
https://gitlab.com/lander-team/lander-sim.git
synced 2025-08-03 11:51:27 +00:00
Replace simPrototypeSTART.m
This commit is contained in:
@@ -3,14 +3,14 @@ close all; clear all; clc;
|
|||||||
|
|
||||||
%% User Defined Values
|
%% User Defined Values
|
||||||
% Initial Conditions
|
% Initial Conditions
|
||||||
Kp = -8;
|
Kp = -6.8699;
|
||||||
Ki = -0.25;
|
Ki = 0;
|
||||||
Kd = -1.6818;
|
Kd = -0.775;
|
||||||
|
|
||||||
v0 = 0; % Initial Velocity (z) [m/s]
|
v0 = 0; % Initial Velocity (z) [m/s]
|
||||||
M0 = 1.2; % Initial Mass [kg]
|
M0 = 1.2; % Initial Mass [kg]
|
||||||
yaw0 = 75; % Initial Yaw [deg]
|
yaw0 = 75; % Initial Yaw [deg]
|
||||||
pitch0 = 0; % Initial Pitch [deg]
|
pitch0 = 30; % Initial Pitch [deg]
|
||||||
roll0 = 0; % Initial Roll [deg]
|
roll0 = 0; % Initial Roll [deg]
|
||||||
p0 = 0; % Initial Angular Velocity (x) [deg/s]
|
p0 = 0; % Initial Angular Velocity (x) [deg/s]
|
||||||
q0 = 0; % Initial Angular Velocity (y) [deg/s]
|
q0 = 0; % Initial Angular Velocity (y) [deg/s]
|
||||||
@@ -25,8 +25,8 @@ Mb = M0 - Mp; % Bu
|
|||||||
tb = Tcurve(end, 1) - Tcurve(1, 1); % Burn Time [s]
|
tb = Tcurve(end, 1) - Tcurve(1, 1); % Burn Time [s]
|
||||||
mdot = Mp / tb; % Mass Flow Rate [kg/s]
|
mdot = Mp / tb; % Mass Flow Rate [kg/s]
|
||||||
D = 0; % Drag [N]
|
D = 0; % Drag [N]
|
||||||
stepSize = 1/100; % Simulation Step Size [s]
|
stepSize = 1/1000; % Simulation Step Size [s]
|
||||||
maxServo = 7.5; % Max Servo Rotation [deg]
|
maxServo = 7; % Max Servo Rotation [deg]
|
||||||
|
|
||||||
% Moment of Inertia / Mass
|
% Moment of Inertia / Mass
|
||||||
I11 = (1/12) * 0.5318^2 + 0.25 * 0.05105^2; % (1/12) * h^2 + 0.25 * r^2
|
I11 = (1/12) * 0.5318^2 + 0.25 * 0.05105^2; % (1/12) * h^2 + 0.25 * r^2
|
||||||
@@ -36,9 +36,9 @@ I = [I11 0 0; 0 I22 0; 0 0 I33]; % I
|
|||||||
|
|
||||||
%% Pre-Sim Calcs
|
%% Pre-Sim Calcs
|
||||||
%K = calcLQR(I*M0) % LQR Gain Calcs
|
%K = calcLQR(I*M0) % LQR Gain Calcs
|
||||||
[h0, vb, burnStartTime] = burnStartTimeCalc(Tcurve, tb, M0, mdot, Mb, v0); % Burn Start Time Calc
|
[h0, vb, burnStartTime] = burnStartTimeCalc(Tcurve, tb, M0, mdot, Mb, v0) % Burn Start Time Calc
|
||||||
h0 = 21;
|
h0 = 21;
|
||||||
simTime = burnStartTime + tb; % Simulation Time [s]
|
simTime = burnStartTime + tb % Simulation Time [s]
|
||||||
|
|
||||||
yaw0 = yaw0 * pi / 180; % Initial Yaw [rad]
|
yaw0 = yaw0 * pi / 180; % Initial Yaw [rad]
|
||||||
pitch0 = pitch0 * pi / 180; % Initial Pitch [rad]
|
pitch0 = pitch0 * pi / 180; % Initial Pitch [rad]
|
||||||
@@ -55,6 +55,20 @@ load_system(model);
|
|||||||
simOut = sim(model);
|
simOut = sim(model);
|
||||||
|
|
||||||
toc
|
toc
|
||||||
|
%% Write to CSV
|
||||||
|
t = simOut.v.Time;
|
||||||
|
pos = simOut.h.Data;
|
||||||
|
vel = simOut.v.Data;
|
||||||
|
accel = simOut.a.Data;
|
||||||
|
ypr = simOut.YPR.Data;
|
||||||
|
yprDot = simOut.YPRdot.Data;
|
||||||
|
servo1 = [zeros(1163,1);simOut.servo1.Data];
|
||||||
|
servo2 = [zeros(1163,1);simOut.servo2.Data];
|
||||||
|
PIDx = simOut.PIDx.Data;
|
||||||
|
PIDy = simOut.PIDy.Data;
|
||||||
|
|
||||||
|
M = [t, pos, vel, accel, ypr, yprDot, servo1, servo2, PIDx, PIDy];
|
||||||
|
writematrix(M, 'out.xls');
|
||||||
%% Outputs
|
%% Outputs
|
||||||
% figure(1)
|
% figure(1)
|
||||||
%
|
%
|
||||||
|
Reference in New Issue
Block a user