mirror of
https://gitlab.com/lander-team/lander-cpp.git
synced 2025-07-27 16:41:26 +00:00
Almost there boys
This commit is contained in:
@@ -77,30 +77,72 @@ void burnStartTimeCalc(Vehicle &State) {
|
||||
double mass, thrust, acceleration;
|
||||
|
||||
// Piecewise functions for F15 thrust curve
|
||||
for (double i = 0.148; i < 3.450; i = i + dt) {
|
||||
for (double i = 0.0; i < 3.450; i = i + dt) {
|
||||
mass = State.massInitial - i * State.mdot;
|
||||
|
||||
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;
|
||||
else if (i < 0.148)
|
||||
thrust = 0.0;
|
||||
|
||||
acceleration = (thrust / mass) + g;
|
||||
velocity = integral(acceleration, velocity, State.stepSize);
|
||||
h = integral(velocity, h, State.stepSize);
|
||||
}
|
||||
|
||||
State.z = 18.88;//h + (pow(velocity, 2) / (2 * -g)); // starting height
|
||||
State.z = h + (pow(velocity, 2) / (2 * -g)); // starting height
|
||||
State.burnVelocity = velocity; // terminal velocity
|
||||
std::cout << State.z << std::endl;
|
||||
// std::cout << State.z << std::endl;
|
||||
// std::cout << State.burnVelocity << std::endl;
|
||||
|
||||
double burnStartTime = State.burnVelocity / -g;
|
||||
State.simTime = (State.burntime + burnStartTime) * 1000;
|
||||
|
||||
int local_thrustFiring = 0;
|
||||
double local_t = 0.0;
|
||||
double local_a = 0.0;
|
||||
double local_v = 0.0;
|
||||
double local_h = State.z;
|
||||
double local_tb = 0.0;
|
||||
double local_thrust = 0.0;
|
||||
|
||||
// Pre sim simulation to simulate the simulation
|
||||
do {
|
||||
if ((std::abs(local_v + State.burnVelocity) < 1.10) &&
|
||||
(local_thrustFiring == 0))
|
||||
local_thrustFiring = 1;
|
||||
|
||||
if (local_thrustFiring == 0) {
|
||||
local_thrust = 0.0;
|
||||
|
||||
} else if (local_thrustFiring == 1) {
|
||||
if ((local_tb > 0.147) && (local_tb < 0.420))
|
||||
local_thrust = 65.165 * local_tb - 2.3921;
|
||||
else if ((local_tb > 0.419) && (local_tb < 3.383))
|
||||
local_thrust = 0.8932 * pow(local_tb, 6) - 11.609 * pow(local_tb, 5) +
|
||||
60.739 * pow(local_tb, 4) - 162.99 * pow(local_tb, 3) +
|
||||
235.6 * pow(local_tb, 2) - 174.43 * local_tb + 67.17;
|
||||
else if ((local_tb > 3.382) && (local_tb < 3.451))
|
||||
local_thrust = -195.78 * local_tb + 675.11;
|
||||
else if (local_tb > 3.45) {
|
||||
local_thrust = 0.0;
|
||||
local_thrustFiring = 3;
|
||||
std::cout << (local_h) << std::endl;
|
||||
std::cout << (local_v) << std::endl;
|
||||
}
|
||||
|
||||
local_tb += State.stepSize / 1000.0;
|
||||
}
|
||||
|
||||
local_v += (((local_thrust / State.mass) + g) * State.stepSize / 1000);
|
||||
local_h += local_v * State.stepSize / 1000.0;
|
||||
|
||||
} while (local_thrustFiring != 3);
|
||||
}
|
||||
|
||||
void vehicleDynamics(Vehicle &State, Vehicle &PrevState, int t) {
|
||||
@@ -197,21 +239,16 @@ void thrustSelection(Vehicle &State, int t) {
|
||||
// as well as current mass
|
||||
State.burnElapsed = (t - State.burnStart) / 1000;
|
||||
State.mass = State.massInitial - (State.mdot * State.burnElapsed);
|
||||
}
|
||||
|
||||
else if (abs(State.burnVelocity + State.vz) < 0.001) {
|
||||
} else if (std::abs(State.burnVelocity + State.vz) < 0.001) {
|
||||
// Start burn
|
||||
State.burnStart = t;
|
||||
State.burnElapsed = 0;
|
||||
}
|
||||
|
||||
else
|
||||
} else
|
||||
State.burnElapsed = 2000; // arbitrary number to ensure we don't burn
|
||||
|
||||
if ((State.burnElapsed > 0.147) && (State.burnElapsed < 0.420)) {
|
||||
State.thrustFiring = true;
|
||||
State.thrust = 65.165 * State.burnElapsed - 2.3921;
|
||||
|
||||
} else if ((State.burnElapsed > 0.419) && (State.burnElapsed < 3.383))
|
||||
State.thrust = 0.8932 * pow(State.burnElapsed, 6) -
|
||||
11.609 * pow(State.burnElapsed, 5) +
|
||||
@@ -219,13 +256,13 @@ void thrustSelection(Vehicle &State, int t) {
|
||||
162.99 * pow(State.burnElapsed, 3) +
|
||||
235.6 * pow(State.burnElapsed, 2) -
|
||||
174.43 * State.burnElapsed + 67.17;
|
||||
|
||||
else if ((State.burnElapsed > 3.382) && (State.burnElapsed < 3.46))
|
||||
State.thrust = -195.78 * State.burnElapsed - 675.11;
|
||||
State.thrust = -195.78 * State.burnElapsed + 675.11;
|
||||
|
||||
if (State.burnElapsed > 3.45) {
|
||||
State.thrustFiring = false;
|
||||
State.thrust = 0;
|
||||
State.az = g;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user