mirror of
https://gitlab.com/lander-team/lander-cpp.git
synced 2025-06-16 15:17:23 +00:00
107 lines
2.0 KiB
C++
107 lines
2.0 KiB
C++
#define M_PI 3.14159265359
|
|
|
|
#if defined(NATIVE) || defined(_WIN32)
|
|
#include <cmath>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <stdexcept> // std::runtime_error
|
|
#include <stdio.h>
|
|
#include <string>
|
|
#include <vector>
|
|
#elif defined(TEENSY)
|
|
#include <Arduino.h>
|
|
|
|
unsigned long last;
|
|
#endif
|
|
|
|
#include "Vehicle.h"
|
|
#include "sim.h"
|
|
|
|
#if defined(NATIVE) || defined(_WIN32)
|
|
#include "native.h"
|
|
#elif defined(TEENSY)
|
|
#include "teensy.h"
|
|
#endif
|
|
|
|
Vehicle State;
|
|
Vehicle PrevState;
|
|
outVector stateVector;
|
|
|
|
#if defined(NATIVE) || defined(_WIN32)
|
|
void setup() {
|
|
init_Vehicle(State);
|
|
|
|
// Determine when to burn
|
|
burnStartTimeCalc(State);
|
|
}
|
|
#elif defined(TEENSY)
|
|
void setup() {
|
|
delay(1000);
|
|
init_Vehicle(State);
|
|
Serial.println("Simulated Vehicle Initalized");
|
|
delay(1000);
|
|
|
|
// Determine when to burn
|
|
burnStartTimeCalc(State);
|
|
Serial.println("Starting Height Calculated");
|
|
delay(1000);
|
|
loadCellCalibrate();
|
|
Serial.println("Load Cells Calibrated");
|
|
delay(1000);
|
|
}
|
|
#endif
|
|
|
|
#if defined(NATIVE) || defined(_WIN32)
|
|
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);
|
|
init_Vehicle(State);
|
|
}
|
|
}
|
|
#elif defined(TEENSY)
|
|
void loop() {
|
|
last = millis();
|
|
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);
|
|
init_Vehicle(State);
|
|
Serial.println("Last run duration:" + String(millis() - last + " ms"));
|
|
|
|
delay(1000);
|
|
|
|
Serial.println("Restarting Sim");
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if defined(_WIN32) || defined(linux)
|
|
int main() {
|
|
|
|
setup();
|
|
|
|
do {
|
|
loop();
|
|
} while ((State.z > 0.0));
|
|
|
|
return 0;
|
|
}
|
|
#endif |