From 558211e9feb3ec9752c2ca402b29c64d899bbdeb Mon Sep 17 00:00:00 2001 From: Travis Hunter Date: Sat, 6 May 2023 09:20:42 -0600 Subject: [PATCH] Removed the Propagator from the Rocket. It shouldn't really be there, now the Propagator belongs to QtRocket, and is paired with a particular Rocket model, but doesn't belong to that model --- QtRocket.cpp | 16 ++++++++++++++++ QtRocket.h | 13 +++++++++++++ gui/AnalysisWindow.cpp | 8 ++++---- gui/MainWindow.cpp | 5 +++-- model/Rocket.cpp | 5 +---- model/Rocket.h | 16 +++------------- sim/Propagator.cpp | 2 +- sim/Propagator.h | 5 +++-- sim/StateData.h | 3 +++ 9 files changed, 47 insertions(+), 26 deletions(-) diff --git a/QtRocket.cpp b/QtRocket.cpp index 88703e6..49a8bc5 100644 --- a/QtRocket.cpp +++ b/QtRocket.cpp @@ -82,6 +82,9 @@ QtRocket::QtRocket() rocket.first = std::make_shared(); + + rocket.second = + std::make_shared(rocket.first); motorDatabase = std::make_shared(); @@ -101,6 +104,19 @@ int QtRocket::run(int argc, char* argv[]) return 0; } +void QtRocket::launchRocket() +{ + // initialize the propagator + rocket.second->clearStates(); + rocket.second->setCurrentTime(0.0); + + // start the rocket motor + rocket.first->launch(); + + // run the propagator until it terminates + rocket.second->runUntilTerminate(); +} + void QtRocket::addMotorModels(std::vector& m) { motorDatabase->addMotorModels(m); diff --git a/QtRocket.h b/QtRocket.h index 88a719a..02e301b 100644 --- a/QtRocket.h +++ b/QtRocket.h @@ -54,6 +54,19 @@ public: void setEnvironment(std::shared_ptr e) { environment = e; } + void launchRocket(); + /** + * @brief getStates returns a vector of time/state pairs generated during launch() + * @return vector of pairs of doubles, where the first value is a time and the second a state vector + */ + const std::vector>>& getStates() const { return rocket.second->getStates(); } + + /** + * @brief setInitialState sets the initial state of the Rocket. + * @param initState initial state vector (x, y, z, xDot, yDot, zDot, pitch, yaw, roll, pitchDot, yawDot, rollDot) + */ + void setInitialState(const std::vector& initState) { rocket.second->setInitialState(initState); } + private: QtRocket(); diff --git a/gui/AnalysisWindow.cpp b/gui/AnalysisWindow.cpp index 3a47076..92c4e66 100644 --- a/gui/AnalysisWindow.cpp +++ b/gui/AnalysisWindow.cpp @@ -35,8 +35,8 @@ AnalysisWindow::~AnalysisWindow() void AnalysisWindow::onButton_plotAltitude_clicked() { - std::shared_ptr rocket = QtRocket::getInstance()->getRocket(); - const std::vector>>& res = rocket->getStates(); + QtRocket* qtRocket = QtRocket::getInstance(); + const std::vector>>& res = qtRocket->getStates(); auto& plot = ui->plotWidget; plot->clearGraphs(); plot->setInteraction(QCP::iRangeDrag, true); @@ -62,8 +62,8 @@ void AnalysisWindow::onButton_plotAltitude_clicked() void AnalysisWindow::onButton_plotVelocity_clicked() { - std::shared_ptr rocket = QtRocket::getInstance()->getRocket(); - const std::vector>>& res = rocket->getStates(); + QtRocket* qtRocket = QtRocket::getInstance(); + const std::vector>>& res = qtRocket->getStates(); auto& plot = ui->plotWidget; plot->clearGraphs(); plot->setInteraction(QCP::iRangeDrag, true); diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 8937398..054c266 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -125,10 +125,11 @@ void MainWindow::onButton_calculateTrajectory_clicked() double initialVelocityZ = initialVelocity * std::sin(initialAngle / 57.2958); std::vector initialState = {0.0, 0.0, 0.0, initialVelocityX, 0.0, initialVelocityZ, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; auto rocket = QtRocket::getInstance()->getRocket(); - rocket->setInitialState(initialState); rocket->setMass(mass); rocket->setDragCoefficient(dragCoeff); - rocket->launch(); + + qtRocket->setInitialState(initialState); + qtRocket->launchRocket(); AnalysisWindow aWindow; aWindow.setModal(false); diff --git a/model/Rocket.cpp b/model/Rocket.cpp index 1ce0e14..144553f 100644 --- a/model/Rocket.cpp +++ b/model/Rocket.cpp @@ -1,17 +1,14 @@ #include "Rocket.h" #include "QtRocket.h" -Rocket::Rocket() : propagator(this) +Rocket::Rocket() { } void Rocket::launch() { - propagator.clearStates(); - propagator.setCurrentTime(0.0); mm.startMotor(0.0); - propagator.runUntilTerminate(); } void Rocket::setMotorModel(const model::MotorModel& motor) diff --git a/model/Rocket.h b/model/Rocket.h index f802d70..5473840 100644 --- a/model/Rocket.h +++ b/model/Rocket.h @@ -34,18 +34,6 @@ public: */ void launch(); - /** - * @brief getStates returns a vector of time/state pairs generated during launch() - * @return vector of pairs of doubles, where the first value is a time and the second a state vector - */ - const std::vector>>& getStates() const { return propagator.getStates(); } - - /** - * @brief setInitialState sets the initial state of the Rocket. - * @param initState initial state vector (x, y, z, xDot, yDot, zDot, pitch, yaw, roll, pitchDot, yawDot, rollDot) - */ - void setInitialState(const std::vector& initState) { propagator.setInitialState(initState); } - /** * @brief getMass returns the current mass of the rocket. This is the sum of all components' masses * @return total current mass of the Rocket @@ -105,12 +93,14 @@ public: * @param n name to set the Rocket */ void setName(const std::string& n) { name = n; } + + + private: std::vector bodyFrameState{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; std::string name; /// Rocket name - sim::Propagator propagator; /// propagator double dragCoeff; /// @todo get rid of this, should be dynamically calculated double mass; /// @todo get rid of this, should be dynamically computed, but is the current rocket mass diff --git a/sim/Propagator.cpp b/sim/Propagator.cpp index c17738b..bb46605 100644 --- a/sim/Propagator.cpp +++ b/sim/Propagator.cpp @@ -22,7 +22,7 @@ namespace sim { -Propagator::Propagator(Rocket* r) +Propagator::Propagator(std::shared_ptr r) : linearIntegrator(), //orientationIntegrator(), rocket(r) diff --git a/sim/Propagator.h b/sim/Propagator.h index 97a04ee..916251d 100644 --- a/sim/Propagator.h +++ b/sim/Propagator.h @@ -24,7 +24,7 @@ namespace sim class Propagator { public: - Propagator(Rocket* r); + Propagator(std::shared_ptr r); ~Propagator(); void setInitialState(const std::vector& initialState) @@ -77,7 +77,8 @@ private: std::unique_ptr linearIntegrator; //std::unique_ptr orientationIntegrator; - Rocket* rocket; + std::shared_ptr rocket; + std::vector currentState{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; std::vector tempRes{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; diff --git a/sim/StateData.h b/sim/StateData.h index e0b2567..f0a747b 100644 --- a/sim/StateData.h +++ b/sim/StateData.h @@ -25,6 +25,9 @@ public: Matrix3 dcm{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; + /// Euler angles are yaw-pitch-roll, and (3-2-1) order + Vector3 eulerAngles{0.0, 0.0, 0.0}; + // This is an array because the integrator expects it double data[6];