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:
parent
8e620cf0c1
commit
558211e9fe
16
QtRocket.cpp
16
QtRocket.cpp
@ -82,6 +82,9 @@ QtRocket::QtRocket()
|
||||
|
||||
rocket.first =
|
||||
std::make_shared<Rocket>();
|
||||
|
||||
rocket.second =
|
||||
std::make_shared<sim::Propagator>(rocket.first);
|
||||
|
||||
motorDatabase = std::make_shared<utils::MotorModelDatabase>();
|
||||
|
||||
@ -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<model::MotorModel>& m)
|
||||
{
|
||||
motorDatabase->addMotorModels(m);
|
||||
|
13
QtRocket.h
13
QtRocket.h
@ -54,6 +54,19 @@ public:
|
||||
|
||||
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:
|
||||
QtRocket();
|
||||
|
||||
|
@ -35,8 +35,8 @@ AnalysisWindow::~AnalysisWindow()
|
||||
|
||||
void AnalysisWindow::onButton_plotAltitude_clicked()
|
||||
{
|
||||
std::shared_ptr<Rocket> rocket = QtRocket::getInstance()->getRocket();
|
||||
const std::vector<std::pair<double, std::vector<double>>>& res = rocket->getStates();
|
||||
QtRocket* qtRocket = QtRocket::getInstance();
|
||||
const std::vector<std::pair<double, std::vector<double>>>& 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> rocket = QtRocket::getInstance()->getRocket();
|
||||
const std::vector<std::pair<double, std::vector<double>>>& res = rocket->getStates();
|
||||
QtRocket* qtRocket = QtRocket::getInstance();
|
||||
const std::vector<std::pair<double, std::vector<double>>>& res = qtRocket->getStates();
|
||||
auto& plot = ui->plotWidget;
|
||||
plot->clearGraphs();
|
||||
plot->setInteraction(QCP::iRangeDrag, true);
|
||||
|
@ -125,10 +125,11 @@ void MainWindow::onButton_calculateTrajectory_clicked()
|
||||
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};
|
||||
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);
|
||||
|
@ -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)
|
||||
|
@ -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<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
|
||||
* @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<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
|
||||
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
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
namespace sim {
|
||||
|
||||
Propagator::Propagator(Rocket* r)
|
||||
Propagator::Propagator(std::shared_ptr<Rocket> r)
|
||||
: linearIntegrator(),
|
||||
//orientationIntegrator(),
|
||||
rocket(r)
|
||||
|
@ -24,7 +24,7 @@ namespace sim
|
||||
class Propagator
|
||||
{
|
||||
public:
|
||||
Propagator(Rocket* r);
|
||||
Propagator(std::shared_ptr<Rocket> r);
|
||||
~Propagator();
|
||||
|
||||
void setInitialState(const std::vector<double>& initialState)
|
||||
@ -77,7 +77,8 @@ private:
|
||||
std::unique_ptr<sim::DESolver> linearIntegrator;
|
||||
//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> tempRes{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||
|
@ -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];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user