1
0
mirror of https://gitlab.com/lander-team/lander-cpp.git synced 2025-06-16 15:17:23 +00:00

Merge branch '4-correct-ending-conditions' into 'main'

Resolve "Correct Ending Conditions"

Closes #4

See merge request lander-team/lander-cpp!2
This commit is contained in:
Brendan McGeeney 2021-09-16 03:03:58 +00:00
commit dbb6888602
8 changed files with 5696 additions and 4310 deletions

40
.vscode/settings.json vendored
View File

@ -1,6 +1,44 @@
{
"files.associations": {
"iostream": "cpp"
"iostream": "cpp",
"algorithm": "cpp",
"array": "cpp",
"cmath": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
},
"C_Cpp.clang_format_fallbackStyle": "LLVM",
"editor.formatOnSave": true,

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 35 KiB

File diff suppressed because it is too large Load Diff

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) {

View File

@ -8,7 +8,7 @@
#include "Vehicle.h"
#include "sim.h"
void sim(struct Vehicle &);
bool sim(struct Vehicle &);
int main() {
Vehicle State;
@ -47,10 +47,15 @@ int main() {
State.burntime = 3.45 - 0.148; // [s]
State.mdot = State.massPropellant / State.burntime; // [kg/s]
sim(State, PrevState);
bool outcome = sim(State, PrevState);
std::cout << "Finished";
std::cin.get();
std::cout << "Finished"
<< "\n";
if (outcome == 1)
std::cout << "Success!";
else if (outcome == 0)
std::cout << "Failed!";
return 0;
}