1
0
mirror of https://gitlab.com/lander-team/lander-cpp.git synced 2025-07-25 23:51:35 +00:00

implemented improved thrust curve

This commit is contained in:
bpmcgeeney
2021-09-12 17:19:09 -07:00
parent e83923c876
commit c5d5260c6c
10 changed files with 4363 additions and 4396 deletions

View File

@@ -14,7 +14,7 @@ int main()
Vars.vz = 0; // [m/s]
// Initial YPR
Vars.yaw = 15 * 3.1416 / 180; // [rad]
Vars.yaw = 0 * 3.1416 / 180; // [rad]
Vars.pitch = 0 * 3.1416 / 180; // [rad]
Vars.roll = 0 * 3.1416 / 180; // [rad]
@@ -36,10 +36,10 @@ int main()
Vars.stepSize = 1; // [ms]
// Other Properties
Vars.mp = 0.06; // [kg]
Vars.mb = Vars.m0 - Vars.mp; // [kg]
Vars.tb = Vars.thrustCurve[25][0] - Vars.thrustCurve[0][0]; // [s]
Vars.mdot = Vars.mp / Vars.tb; // [kg/s]
Vars.mp = 0.06; // [kg]
Vars.mb = Vars.m0 - Vars.mp; // [kg]
Vars.tb = 3.45 - 0.148; // [s]
Vars.mdot = Vars.mp / Vars.tb; // [kg/s]
sim(Vars);

View File

@@ -47,38 +47,30 @@ void sim(struct sVars &Vars)
void burnStartTimeCalc(struct sVars &Vars, double g)
{
double v_prev = Vars.vz;
double h_prev = 0;
double dt, a, v, h;
double v = Vars.vz;
double h = 0;
double dt = 0.001;
double a, j, m, thrust;
for (int i = 0; i < 25; i++)
for (double i = 0.148; i < 3.450; i = i + dt)
{
// Integral of thrust curve
if (i < 25)
{
dt = Vars.thrustCurve[i + 1][0] - Vars.thrustCurve[i][0];
a = (Vars.thrustCurve[i][1] /
(Vars.m0 - Vars.mdot * Vars.thrustCurve[i + 1][0]) +
g);
}
else
{
dt = 0;
a = (Vars.thrustCurve[i][1] / Vars.mb) + g;
}
m = Vars.m0 - i * Vars.mdot;
v = a * dt + v_prev;
v_prev = v;
h = v * dt + h_prev;
h_prev = h;
if ((i > 0.147) & (i < 0.420))
thrust = 65.165 * i - 2.3921;
else if ((i > 0.419) & (i < 3.383))
thrust = 0.8932 * pow(i, 6) - 11.609 * pow(i, 5) + 60.739 * pow(i, 4) - 162.99 * pow(i, 3) + 235.6 * pow(i, 2) - 174.43 * i + 67.17;
else if ((i > 3.382) & (i < 3.46))
thrust = -195.78 * i + 675.11;
v = (((thrust / m) + g) * dt) + v;
h = v * dt + h;
}
double hb = h; // height that we want to start our burn at
double hf =
(v * v) / (2 * -g); // amount of height that we need to be in freefall in
// order to reach terminal velocity
Vars.z = hb + hf; // starting height
Vars.vb = v; // terminal velocity
Vars.z = h + (pow(v, 2) / (2 * -g)); // starting height
Vars.vb = v; // terminal velocity
double burnStartTime = Vars.vb / -g;
Vars.simTime = (Vars.tb + burnStartTime) * 1000;
@@ -110,26 +102,14 @@ void thrustSelection(struct sVars &Vars, int t)
else
Vars.burnElapsed = 2000; // arbitrary number to ensure we don't burn
bool b_thrustSelect;
if ((Vars.burnElapsed > 0.147) & (Vars.burnElapsed < 0.420))
Vars.thrust = 65.165 * Vars.burnElapsed - 2.3921;
for (int i = 0; i < 25; i++)
{
// Compare elapsed burn time to each time entry in the thrust curve
b_thrustSelect = (Vars.burnElapsed < (1 + tol) * Vars.thrustCurve[i][0]) &
(Vars.burnElapsed > (1 - tol) * Vars.thrustCurve[i][0]);
else if ((Vars.burnElapsed > 0.419) & (Vars.burnElapsed < 3.383))
Vars.thrust = 0.8932 * pow(Vars.burnElapsed, 6) - 11.609 * pow(Vars.burnElapsed, 5) + 60.739 * pow(Vars.burnElapsed, 4) - 162.99 * pow(Vars.burnElapsed, 3) + 235.6 * pow(Vars.burnElapsed, 2) - 174.43 * Vars.burnElapsed + 67.17;
if (b_thrustSelect)
{
// Choose thrust associated with time entry that elapsed burn time was
// compared to above
Vars.thrust = Vars.thrustCurve[i][1];
Vars.thrust_prev = Vars.thrustCurve[i][1];
}
else
// latch
Vars.thrust = Vars.thrust_prev;
}
else if ((Vars.burnElapsed > 3.382) & (Vars.burnElapsed < 3.46))
Vars.thrust = -195.78 * Vars.burnElapsed + 675.11;
}
void lqrCalc(struct sVars &Vars)