1
0
mirror of https://gitlab.com/lander-team/lander-cpp.git synced 2025-08-02 11:31:34 +00:00

Almost there boys

This commit is contained in:
bpmcgeeney
2021-11-01 12:27:54 -07:00
parent 4a70843273
commit cf93accf8a
6 changed files with 274 additions and 18 deletions

View File

@@ -0,0 +1,82 @@
clear all; clc;
%% Create Thrust Curve using Piecewise Function
dt = 0.001;
t1 = 0.148 : dt : 0.419;
t2 = 0.420 : dt : 3.382;
t3 = 3.383 : dt : 3.45;
y1 = 65.165.*t1 - 2.3921;
y2 = 0.8932*t2.^6 - 11.609*t2.^5 + 60.739*t2.^4 - 162.99*t2.^3 ...
+ 235.6*t2.^2 - 174.43*t2 + 67.17;
y3 = -195.78*t3 + 675.11;
m = 1.2;
a = [y1, y2, y3] ./ m;
t = 0.148 : dt : 3.45;
thrustCurve = [t', (a*m)'];
%% Integrate
v = 0;
h = 0;
g = -9.81;
a = a + g;
for i = 1 : length(a)
v = ((a(i)) * dt) + v;
h = v * dt + h;
end
h = h + ((v^2) / (2*-g))
vb = v
thrustFiring = 0;
dt = 0.001;
v = 0;
j = 1;
k = 1;
t = 0;
while 1
if abs(v + vb) < 0.01
thrustFiring = 1;
tb = 0;
end
if thrustFiring == 0
v = g*dt + v;
h = v*dt + h;
a = g;
elseif thrustFiring == 1
if ((tb >= 0.148) && (tb <= 3.45))
v = v + a(j)*dt;
h = h + v*dt;
disp(tb)
j = j + 1;
else
v = g*dt + v;
h = v*dt + h;
end
tb = tb + dt;
end
accel(k) = a;
vz(k) = v;
z(k) = h;
time(k) = t;
t = t + dt;
k = k + 1;
if h < 0
break
end
end
figure(1)
plot(time, z)
figure(2)
plot(time, vz)
figure(3)
plot(time, accel)

View File

@@ -0,0 +1,88 @@
clear all; clc;
%% Create Thrust Curve using Piecewise Function
dt = 0.001;
t1 = 0.148 : dt : 0.419;
t2 = 0.420 : dt : 3.382;
t3 = 3.383 : dt : 3.45;
y1 = 65.165.*t1 - 2.3921;
y2 = 0.8932*t2.^6 - 11.609*t2.^5 + 60.739*t2.^4 - 162.99*t2.^3 ...
+ 235.6*t2.^2 - 174.43*t2 + 67.17;
y3 = -195.78*t3 + 675.11;
m = 1.2;
a = [y1, y2, y3] ./ m;
t = 0.148 : dt : 3.45;
thrustCurve = [t', (a*m)'];
%% Integrate
v = 0;
h = 0;
g = -9.81;
a = a + g;
for i = 1 : length(a)
v = ((a(i)) * dt) + v;
h = v * dt + h;
end
h = h + ((v^2) / (2*-g))
vb = v
thrustFiring = 0;
dt = 0.001;
v = 0;
j = 1;
k = 1;
t = 0;
while 1
if (abs(v + vb) < 0.005) && (thrustFiring == 0)
thrustFiring = 1;
tb = 0;
end
if thrustFiring == 0
v = g*dt + v;
h = v*dt + h;
az = g;
elseif thrustFiring == 1
if ((tb >= 0.148) && (tb <= 3.45))
v = v + a(j)*dt;
h = h + v*dt;
az = a(j);
j = j + 1;
else
if tb > 3.45
thrustFiring = 0;
end
v = g*dt + v;
h = v*dt + h;
az = g;
end
tb = tb + dt;
end
accel(k) = az;
vz(k) = v;
z(k) = h;
time(k) = t;
t = t + dt;
k = k + 1;
if ((h < 0) && (thrustFiring == 0))
break
end
end
figure(1)
plot(time, z)
figure(2)
plot(time, vz)
figure(3)
plot(time, accel)

46
matlabHelpers/test.m Normal file
View File

@@ -0,0 +1,46 @@
clear all; close all; clc;
g = -9.81;
mass = 1.2;
mdot = 0.0182;
dt = 0.001;
vprev = 0;
hprev = 0;
i = 1;
for t = 0 : dt : 3.45
m = mass - mdot*t;
if t < 0.148
thrust = 0;
elseif (t > 0.147) && (t < 0.419)
thrust = 65.165.*t - 2.3921;
elseif (t > 0.420) && (t < 3.382)
thrust = 0.8932*t^6 - 11.609*t^5 + 60.739*t^4 - 162.99*t^3 ...
+ 235.6*t^2 - 174.43*t + 67.17;
elseif (t > 3.381) && (t < 3.451)
thrust = -195.78*t + 675.11;
elseif t > 3.45
thrust = 0;
end
acceleration(i) = (thrust / mass) + g;
velocity(i) = acceleration(i) * dt + vprev;
height(i) = velocity(i) * dt + hprev;
vprev = velocity(i);
hprev = height(i);
i = i + 1;
end
figure(1)
hold on
t = 0 : dt : 3.45;
plot(t + 0.7712, velocity - max(velocity))
t1 = 0 : 0.001 : 0.7712;
v = -9.81*t1;
plot(t1, v)
figure(2)
h = 0.5*-9.81*t1.^2
plot(t1, h)