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

Resolve "Separate native and teensy code"

This commit is contained in:
2021-11-03 22:33:10 +00:00
parent ad602ca834
commit 66590a33fe
6 changed files with 273 additions and 220 deletions

View File

@@ -11,58 +11,59 @@
#include "Vehicle.h"
#include "sim.h"
bool sim(struct Vehicle &);
#if defined(_WIN32) || defined(linux)
#include "native.h"
#elif TEENSY
#include "teensy.h"
#endif
Vehicle State;
Vehicle PrevState;
outVector stateVector;
#if defined(_WIN32) || defined(linux)
void setup() {
init_Vehicle(State);
// Determine when to burn
burnStartTimeCalc(State);
}
#elif TEENSY
void setup() {
init_Vehicle(State);
// Determine when to burn
burnStartTimeCalc(State);
loadCellCalibrate();
}
#endif
void loop() {
vehicleDynamics(State, PrevState);
thrustInfo(State);
pidController(State, PrevState);
TVC(State, PrevState);
processTVC(State);
state2vec(State, PrevState, stateVector);
State.time += State.stepSize;
if (State.z < 0.0) {
write2CSV(stateVector, State);
printSimResults(State);
}
}
#if defined(_WIN32) || defined(linux)
int main() {
Vehicle State;
Vehicle PrevState;
// PID Gains
State.Kp = -6.8699;
State.Ki = 0;
State.Kd = -0.775;
setup();
// Initial Velocity
State.vx = 0; // [m/s]
State.vy = 0; // [m/s]
State.vz = 0; // [m/s]
do {
loop();
} while ((State.z > 0.0));
// Initial YPR
State.yaw = 10 * M_PI / 180; // [rad]
State.pitch = 5 * M_PI / 180; // [rad]
State.roll = 0 * M_PI / 180; // [rad]
// Initial YPRdot
State.yawdot = 1 * M_PI / 180; // [rad/s]
State.pitchdot = -1 * M_PI / 180; // [rad/s]
State.rolldot = 0 * M_PI / 180; // [rad/s]
// Servo Limitation
State.maxServo = 7; // [degs]
State.maxServoRate = 360; // [degs/sec]
// Vehicle Properties
State.massInitial = 1.2; // [kg]
State.vehicleHeight = 0.5318; // [m]
State.vehicleRadius = 0.05105; // [m]
State.momentArm = 0.145; // [m]
// Sim Step Size
State.stepSize = 1; // [ms]
// Other Properties
State.massPropellant = 0.06; // [kg]
State.massBurnout = State.massInitial - State.massPropellant; // [kg]
State.burntime = 3.45 - 0.148; // [s]
State.mdot = State.massPropellant / State.burntime; // [kg/s]
State.mass = State.massInitial; // [kg]
State.burnElapsed = 2000; // [s]
PrevState.thrust = 0; // [N]
bool outcome = sim(State, PrevState);
std::cout << std::endl << "Simulation Complete 🚀" << std::endl;
// ^^^
// 50% chance this makes Mattys linux crash
return 0;
}
}
#endif