1
0
mirror of https://gitlab.com/lander-team/lander-cpp.git synced 2025-06-15 22:56:53 +00:00

printing timing info

This commit is contained in:
bpmcgeeney 2021-11-12 15:05:03 -07:00
parent 8ec17dd820
commit 03c5b6d16f
3 changed files with 15 additions and 11 deletions

View File

@ -41,6 +41,7 @@ struct Vehicle {
double simTime;
double stepSize;
double stepDuration;
double time = 0.0;
};

View File

@ -75,7 +75,7 @@ void initFile() {
// File Header
dataFile.println(
"t,x,y,z,vx,vy,vz,ax,ay,az,yaw,pitch,roll,yawdot,pitchdot,rolldot,"
"Servo1,Servo2,thrustFiring,PIDx,PIDy,thrust");
"Servo1,Servo2,thrustFiring,thrust,simResponse");
}
void thrustInfo(Vehicle &State) {
@ -166,14 +166,12 @@ void write2CSV(Vehicle &State) {
dataFile.print(String(State.thrustFiring, 5));
dataFile.print(",");
dataFile.print(String(State.PIDx, 5));
dataFile.print(",");
dataFile.print(String(State.PIDy, 5));
dataFile.print(",");
dataFile.print(String(State.thrust, 5));
dataFile.print(",");
dataFile.print(String(State.stepDuration, 5));
dataFile.print("\n");
}
void printSimResults(Vehicle &State) {

View File

@ -12,7 +12,7 @@
#include <Arduino.h>
int BUILTIN_LED = 13;
unsigned long last;
unsigned long last, initTime;
#endif
#include "Vehicle.h"
@ -51,6 +51,8 @@ void setup() {
delay(1000);
initFile();
delay(1000);
initTime = micros();
}
#endif
@ -76,22 +78,23 @@ void loop() {
#elif defined(TEENSY)
void loop() {
last = millis();
last = micros();
vehicleDynamics(State, PrevState);
thrustInfo(State);
pidController(State, PrevState);
TVC(State, PrevState);
processTVC(State);
State.stepDuration = micros() - last;
write2CSV(State);
// Set "prev" values for next timestep
PrevState = State;
State.time += State.stepSize;
if ((State.z < 0.0) && (State.thrustFiring == 2)) {
printSimResults(State);
Serial.println("Run duration:" + String(millis() - last) + " ms");
Serial.println("Run duration:" + String(micros() - initTime) + " us");
closeFile();
delay(20000);
@ -100,6 +103,8 @@ void loop() {
Serial.println("Aborting Sim");
teensyAbort();
}
delay(20 - ((micros() - last) * 1000.0));
}
#endif