1
0
mirror of https://gitlab.com/lander-team/lander-cpp.git synced 2025-07-23 06:31:30 +00:00

implemented new criteria for stopping simulation as well as a failure/success message

This commit is contained in:
bpmcgeeney
2021-09-15 19:56:35 -07:00
parent 78cd59dd11
commit fdddd1f741
8 changed files with 5696 additions and 4310 deletions

View File

@@ -14,7 +14,7 @@ double integral(double x2, double x1, double dt);
double const dt = 0.001;
double const g = -9.81;
void sim(struct Vehicle &State, struct Vehicle &PrevState) {
bool sim(struct Vehicle &State, struct Vehicle &PrevState) {
// defining a few random values here cause I'm lazy
State.burnElapsed = 2000;
@@ -42,16 +42,33 @@ void sim(struct Vehicle &State, struct Vehicle &PrevState) {
"LQRx, LQRy"
<< std::endl;
int t = 0;
// Start Sim
for (int t = 0; t < State.simTime; t++) {
do {
thrustSelection(State, t);
lqrCalc(State);
TVC(State);
vehicleDynamics(State, PrevState, t);
write2CSV(State, outfile, t);
}
t++;
} while ((State.z > 0) && (State.thrust != 0));
outfile.close();
bool returnValue;
if (abs(State.vz) < 5) {
if ((abs(State.yaw) < 5) && (abs(State.pitch) < 5)) {
returnValue = 1;
} else {
returnValue = 0;
}
} else {
returnValue = 0;
}
return returnValue;
}
void burnStartTimeCalc(struct Vehicle &State) {
@@ -94,7 +111,7 @@ void thrustSelection(struct Vehicle &State, int t) {
State.mass = State.massInitial - (State.mdot * State.burnElapsed);
}
else if (abs(State.burnVelocity - State.vz) < .001) {
else if (abs(State.burnVelocity + State.vz) < .001) {
// Start burn
State.burnStart = t;
State.burnElapsed = 0;
@@ -292,6 +309,9 @@ void vehicleDynamics(Vehicle &State, Vehicle &PrevState, int t) {
State.roll = integral(State.psidot, PrevState.roll, State.stepSize);
}
PrevState = State;
/*
// Set "prev" values for next timestep
PrevState.I11 = State.I11;
PrevState.I22 = State.I22;
@@ -320,6 +340,7 @@ void vehicleDynamics(Vehicle &State, Vehicle &PrevState, int t) {
PrevState.x = State.x;
PrevState.y = State.y;
PrevState.z = State.z;
*/
}
void write2CSV(struct Vehicle &State, std::fstream &outfile, int t) {