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

This commit is contained in:
Travis Hunter 2023-05-06 09:20:42 -06:00
parent 8e620cf0c1
commit 558211e9fe
9 changed files with 47 additions and 26 deletions

View File

@ -83,6 +83,9 @@ QtRocket::QtRocket()
rocket.first = rocket.first =
std::make_shared<Rocket>(); std::make_shared<Rocket>();
rocket.second =
std::make_shared<sim::Propagator>(rocket.first);
motorDatabase = std::make_shared<utils::MotorModelDatabase>(); motorDatabase = std::make_shared<utils::MotorModelDatabase>();
} }
@ -101,6 +104,19 @@ int QtRocket::run(int argc, char* argv[])
return 0; 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<model::MotorModel>& m) void QtRocket::addMotorModels(std::vector<model::MotorModel>& m)
{ {
motorDatabase->addMotorModels(m); motorDatabase->addMotorModels(m);

View File

@ -54,6 +54,19 @@ public:
void setEnvironment(std::shared_ptr<sim::Environment> e) { environment = e; } void setEnvironment(std::shared_ptr<sim::Environment> 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<std::pair<double, std::vector<double>>>& 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<double>& initState) { rocket.second->setInitialState(initState); }
private: private:
QtRocket(); QtRocket();

View File

@ -35,8 +35,8 @@ AnalysisWindow::~AnalysisWindow()
void AnalysisWindow::onButton_plotAltitude_clicked() void AnalysisWindow::onButton_plotAltitude_clicked()
{ {
std::shared_ptr<Rocket> rocket = QtRocket::getInstance()->getRocket(); QtRocket* qtRocket = QtRocket::getInstance();
const std::vector<std::pair<double, std::vector<double>>>& res = rocket->getStates(); const std::vector<std::pair<double, std::vector<double>>>& res = qtRocket->getStates();
auto& plot = ui->plotWidget; auto& plot = ui->plotWidget;
plot->clearGraphs(); plot->clearGraphs();
plot->setInteraction(QCP::iRangeDrag, true); plot->setInteraction(QCP::iRangeDrag, true);
@ -62,8 +62,8 @@ void AnalysisWindow::onButton_plotAltitude_clicked()
void AnalysisWindow::onButton_plotVelocity_clicked() void AnalysisWindow::onButton_plotVelocity_clicked()
{ {
std::shared_ptr<Rocket> rocket = QtRocket::getInstance()->getRocket(); QtRocket* qtRocket = QtRocket::getInstance();
const std::vector<std::pair<double, std::vector<double>>>& res = rocket->getStates(); const std::vector<std::pair<double, std::vector<double>>>& res = qtRocket->getStates();
auto& plot = ui->plotWidget; auto& plot = ui->plotWidget;
plot->clearGraphs(); plot->clearGraphs();
plot->setInteraction(QCP::iRangeDrag, true); plot->setInteraction(QCP::iRangeDrag, true);

View File

@ -125,10 +125,11 @@ void MainWindow::onButton_calculateTrajectory_clicked()
double initialVelocityZ = initialVelocity * std::sin(initialAngle / 57.2958); double initialVelocityZ = initialVelocity * std::sin(initialAngle / 57.2958);
std::vector<double> initialState = {0.0, 0.0, 0.0, initialVelocityX, 0.0, initialVelocityZ, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; std::vector<double> 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(); auto rocket = QtRocket::getInstance()->getRocket();
rocket->setInitialState(initialState);
rocket->setMass(mass); rocket->setMass(mass);
rocket->setDragCoefficient(dragCoeff); rocket->setDragCoefficient(dragCoeff);
rocket->launch();
qtRocket->setInitialState(initialState);
qtRocket->launchRocket();
AnalysisWindow aWindow; AnalysisWindow aWindow;
aWindow.setModal(false); aWindow.setModal(false);

View File

@ -1,17 +1,14 @@
#include "Rocket.h" #include "Rocket.h"
#include "QtRocket.h" #include "QtRocket.h"
Rocket::Rocket() : propagator(this) Rocket::Rocket()
{ {
} }
void Rocket::launch() void Rocket::launch()
{ {
propagator.clearStates();
propagator.setCurrentTime(0.0);
mm.startMotor(0.0); mm.startMotor(0.0);
propagator.runUntilTerminate();
} }
void Rocket::setMotorModel(const model::MotorModel& motor) void Rocket::setMotorModel(const model::MotorModel& motor)

View File

@ -34,18 +34,6 @@ public:
*/ */
void launch(); 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<std::pair<double, std::vector<double>>>& 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<double>& initState) { propagator.setInitialState(initState); }
/** /**
* @brief getMass returns the current mass of the rocket. This is the sum of all components' masses * @brief getMass returns the current mass of the rocket. This is the sum of all components' masses
* @return total current mass of the Rocket * @return total current mass of the Rocket
@ -105,12 +93,14 @@ public:
* @param n name to set the Rocket * @param n name to set the Rocket
*/ */
void setName(const std::string& n) { name = n; } void setName(const std::string& n) { name = n; }
private: private:
std::vector<double> 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::vector<double> 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 std::string name; /// Rocket name
sim::Propagator propagator; /// propagator
double dragCoeff; /// @todo get rid of this, should be dynamically calculated 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 double mass; /// @todo get rid of this, should be dynamically computed, but is the current rocket mass

View File

@ -22,7 +22,7 @@
namespace sim { namespace sim {
Propagator::Propagator(Rocket* r) Propagator::Propagator(std::shared_ptr<Rocket> r)
: linearIntegrator(), : linearIntegrator(),
//orientationIntegrator(), //orientationIntegrator(),
rocket(r) rocket(r)

View File

@ -24,7 +24,7 @@ namespace sim
class Propagator class Propagator
{ {
public: public:
Propagator(Rocket* r); Propagator(std::shared_ptr<Rocket> r);
~Propagator(); ~Propagator();
void setInitialState(const std::vector<double>& initialState) void setInitialState(const std::vector<double>& initialState)
@ -77,7 +77,8 @@ private:
std::unique_ptr<sim::DESolver> linearIntegrator; std::unique_ptr<sim::DESolver> linearIntegrator;
//std::unique_ptr<sim::DESolver> orientationIntegrator; //std::unique_ptr<sim::DESolver> orientationIntegrator;
Rocket* rocket; std::shared_ptr<Rocket> rocket;
std::vector<double> currentState{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; std::vector<double> currentState{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
std::vector<double> tempRes{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; std::vector<double> tempRes{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};

View File

@ -25,6 +25,9 @@ public:
Matrix3 dcm{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; 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 // This is an array because the integrator expects it
double data[6]; double data[6];