From 9050658199f47af630a0c1103284a0eaab20946a Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Mon, 13 Sep 2021 08:28:07 -0700 Subject: [PATCH] use M_PI constant instead of hard coding --- include/sim.h | 26 +++++++++++++------------- src/main.cpp | 12 ++++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/sim.h b/include/sim.h index e413412..95ced22 100644 --- a/include/sim.h +++ b/include/sim.h @@ -244,7 +244,7 @@ void TVC(struct sVars &Vars, double g) { else { // Convert servo position to degrees for comparison to max allowable - Vars.xServoDegs = (180 / 3.1416) * asin(Vars.LQRx / Vars.thrust); + Vars.xServoDegs = (180 / M_PI) * asin(Vars.LQRx / Vars.thrust); // Servo position limiter if (Vars.xServoDegs > Vars.maxServo) @@ -253,7 +253,7 @@ void TVC(struct sVars &Vars, double g) { Vars.xServoDegs = -1 * Vars.maxServo; // Convert servo position to degrees for comparison to max allowable - Vars.yServoDegs = (180 / 3.1416) * asin(Vars.LQRy / Vars.thrust); + Vars.yServoDegs = (180 / M_PI) * asin(Vars.LQRy / Vars.thrust); // Servo position limiter if (Vars.yServoDegs > Vars.maxServo) @@ -262,8 +262,8 @@ void TVC(struct sVars &Vars, double g) { Vars.yServoDegs = -1 * Vars.maxServo; // Vector math to aqcuire thrust vector components - Vars.Fx = Vars.thrust * sin(Vars.xServoDegs * (3.1416 / 180)); - Vars.Fy = Vars.thrust * sin(Vars.yServoDegs * (3.1416 / 180)); + Vars.Fx = Vars.thrust * sin(Vars.xServoDegs * (M_PI / 180)); + Vars.Fy = Vars.thrust * sin(Vars.yServoDegs * (M_PI / 180)); Vars.Fz = sqrt(pow(Vars.thrust, 2) - (pow(Vars.Fx, 2) + pow(Vars.Fy, 2))) + (Vars.m * g); @@ -394,17 +394,17 @@ void write2CSV(struct sVars &Vars, std::fstream &outfile, int t) { outfile << Vars.ay << ", "; outfile << Vars.az << ", "; - outfile << Vars.yaw * 180 / 3.1416 << ", "; - outfile << Vars.pitch * 180 / 3.1416 << ", "; - outfile << Vars.roll * 180 / 3.1416 << ", "; + outfile << Vars.yaw * 180 / M_PI << ", "; + outfile << Vars.pitch * 180 / M_PI << ", "; + outfile << Vars.roll * 180 / M_PI << ", "; - outfile << Vars.yawdot * 180 / 3.1416 << ", "; - outfile << Vars.pitchdot * 180 / 3.1416 << ", "; - outfile << Vars.rolldot * 180 / 3.1416 << ", "; + outfile << Vars.yawdot * 180 / M_PI << ", "; + outfile << Vars.pitchdot * 180 / M_PI << ", "; + outfile << Vars.rolldot * 180 / M_PI << ", "; - outfile << Vars.yawddot * 180 / 3.1416 << ", "; - outfile << Vars.pitchddot * 180 / 3.1416 << ", "; - outfile << Vars.rollddot * 180 / 3.1416 << ", "; + outfile << Vars.yawddot * 180 / M_PI << ", "; + outfile << Vars.pitchddot * 180 / M_PI << ", "; + outfile << Vars.rollddot * 180 / M_PI << ", "; outfile << Vars.I11 << ", "; outfile << Vars.I22 << ", "; diff --git a/src/main.cpp b/src/main.cpp index 23b5f31..be4e4de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,14 +17,14 @@ int main() { Vars.vz = 0; // [m/s] // Initial YPR - Vars.yaw = 0 * 3.1416 / 180; // [rad] - Vars.pitch = 0 * 3.1416 / 180; // [rad] - Vars.roll = 0 * 3.1416 / 180; // [rad] + Vars.yaw = 0 * M_PI / 180; // [rad] + Vars.pitch = 0 * M_PI / 180; // [rad] + Vars.roll = 0 * M_PI / 180; // [rad] // Initial YPRdot - Vars.yawdot = 0 * 3.1416 / 180; // [rad/s] - Vars.pitchdot = 0 * 3.1416 / 180; // [rad/s] - Vars.rolldot = 0 * 3.1416 / 180; // [rad/s] + Vars.yawdot = 0 * M_PI / 180; // [rad/s] + Vars.pitchdot = 0 * M_PI / 180; // [rad/s] + Vars.rolldot = 0 * M_PI / 180; // [rad/s] // Servo Limitation Vars.maxServo = 15; // [degs]