From badfef7a3f4eb80c59d14cca53d8c30f743bb7b2 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Mon, 13 Sep 2021 08:50:54 -0700 Subject: [PATCH] start of readability changes --- include/sim.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/sim.h b/include/sim.h index 95ced22..ab193eb 100644 --- a/include/sim.h +++ b/include/sim.h @@ -1,23 +1,27 @@ #include "sVars.h" -void burnStartTimeCalc(struct sVars &, double g); +void burnStartTimeCalc(struct sVars &); void thrustSelection(struct sVars &, int t); void lqrCalc(struct sVars &); -void TVC(struct sVars &, double g); +void TVC(struct sVars &); void vehicleDynamics(struct sVars &, int t); void write2CSV(struct sVars &, std::fstream &outfile, int t); double derivative(double x2, double x1, double dt); double integral(double x2, double x1, double dt); +// Any parameters that are constants should be declared here instead of buried +// in code +float const dt = 0.001; +float const g = -9.81; + void sim(struct sVars &Vars) { - double g = -9.81; // defining a few random values here cause I'm lazy Vars.burnElapsed = 2000; Vars.m = Vars.m0; Vars.thrust_prev = 0; - burnStartTimeCalc(Vars, g); + burnStartTimeCalc(Vars); // Deleting any previous output file if (remove("simOut.csv") != 0) @@ -42,7 +46,7 @@ void sim(struct sVars &Vars) { for (int t = 0; t < Vars.simTime; t++) { thrustSelection(Vars, t); lqrCalc(Vars); - TVC(Vars, g); + TVC(Vars); vehicleDynamics(Vars, t); write2CSV(Vars, outfile, t); } @@ -50,10 +54,10 @@ void sim(struct sVars &Vars) { outfile.close(); } -void burnStartTimeCalc(struct sVars &Vars, double g) { +void burnStartTimeCalc(struct sVars &Vars) { double v = Vars.vz; double h = 0; - double dt = 0.001; + double a, j, m, thrust; for (double i = 0.148; i < 3.450; i = i + dt) { @@ -230,7 +234,7 @@ void lqrCalc(struct sVars &Vars) { Vars.LQRy = -1 * Vars.thrust; } -void TVC(struct sVars &Vars, double g) { +void TVC(struct sVars &Vars) { if (Vars.thrust < 1) { // Define forces and moments for t = 0 Vars.Fx = 0;