1
0
mirror of https://gitlab.com/lander-team/lander-cpp.git synced 2025-06-16 15:17:23 +00:00

use M_PI constant instead of hard coding

This commit is contained in:
Anson Biggs 2021-09-13 08:28:07 -07:00
parent 7a31ed04a9
commit 9050658199
2 changed files with 19 additions and 19 deletions

View File

@ -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 << ", ";

View File

@ -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]