diff --git a/QtRocket.cpp b/QtRocket.cpp index 703ea20..e144d59 100644 --- a/QtRocket.cpp +++ b/QtRocket.cpp @@ -75,10 +75,15 @@ QtRocket::QtRocket() running = false; atmosphere = - std::make_shared(); + std::make_shared(); gravity = - std::make_shared(); + std::make_shared(); + + + rocket = + std::make_shared(); + } int QtRocket::run(int argc, char* argv[]) diff --git a/gui/ThrustCurveMotorSelector.cpp b/gui/ThrustCurveMotorSelector.cpp index 6f29ea6..aee1681 100644 --- a/gui/ThrustCurveMotorSelector.cpp +++ b/gui/ThrustCurveMotorSelector.cpp @@ -1,7 +1,15 @@ +/// \cond +// C headers +// C++ headers +#include +// 3rd party headers +/// \endcond + // qtrocket headers #include "ThrustCurveMotorSelector.h" #include "ui_ThrustCurveMotorSelector.h" +#include "QtRocket.h" ThrustCurveMotorSelector::ThrustCurveMotorSelector(QWidget *parent) : QDialog(parent), @@ -57,6 +65,7 @@ void ThrustCurveMotorSelector::on_searchButton_clicked() c.addCriteria("impulseClass", impulseClass); std::vector motors = tcApi->searchMotors(c); + std::copy(std::begin(motors), std::end(motors), std::back_inserter(motorModels)); for(const auto& i : motors) { @@ -65,3 +74,22 @@ void ThrustCurveMotorSelector::on_searchButton_clicked() } + +void ThrustCurveMotorSelector::on_setMotor_clicked() +{ + //asdf + std::string commonName = ui->motorSelection->currentText().toStdString(); + + // get motor + + model::MotorModel mm = *std::find_if( + std::begin(motorModels), + std::end(motorModels), + [&commonName](const auto& item) + { + return item.commonName == commonName; + }); + + QtRocket::getInstance()->getRocket()->setMotorModel(mm); +} + diff --git a/gui/ThrustCurveMotorSelector.h b/gui/ThrustCurveMotorSelector.h index b123651..fa07c3b 100644 --- a/gui/ThrustCurveMotorSelector.h +++ b/gui/ThrustCurveMotorSelector.h @@ -12,6 +12,7 @@ // qtrocket headers #include "utils/ThrustCurveAPI.h" +#include "model/MotorModel.h" namespace Ui { class ThrustCurveMotorSelector; @@ -33,10 +34,14 @@ private slots: void on_searchButton_clicked(); -private: + void on_setMotor_clicked(); + + private: Ui::ThrustCurveMotorSelector *ui; std::unique_ptr tcApi; + + std::vector motorModels; }; #endif // THRUSTCURVEMOTORSELECTOR_H diff --git a/gui/ThrustCurveMotorSelector.ui b/gui/ThrustCurveMotorSelector.ui index 6cacd12..ef47b7c 100644 --- a/gui/ThrustCurveMotorSelector.ui +++ b/gui/ThrustCurveMotorSelector.ui @@ -94,25 +94,31 @@ - 170 - 260 - 160 + 140 + 240 + 221 41 - - - - Download - - - + + + + 200 + 290 + 80 + 25 + + + + setMotor + + diff --git a/model/Rocket.cpp b/model/Rocket.cpp index 883b7a7..608318a 100644 --- a/model/Rocket.cpp +++ b/model/Rocket.cpp @@ -9,18 +9,12 @@ Rocket::Rocket() : propagator(this) void Rocket::launch() { - tc.setIgnitionTime(5.0); - std::vector> temp; - temp.push_back(std::make_pair(0.0, 0.0)); - temp.push_back(std::make_pair(0.1, 10.0)); - temp.push_back(std::make_pair(0.2, 100.0)); - temp.push_back(std::make_pair(1.2, 50.0)); - temp.push_back(std::make_pair(1.3, 0.0)); - temp.push_back(std::make_pair(8.0, 0.0)); - temp.push_back(std::make_pair(9.0, 100.0)); - temp.push_back(std::make_pair(10.0, 0.0)); - tc.setThrustCurveVector(temp); - propagator.runUntilTerminate(); + propagator.runUntilTerminate(); +} + +void Rocket::setMotorModel(const model::MotorModel& motor) +{ + mm = motor; } bool Rocket::terminateCondition(const std::pair>& cond) diff --git a/model/ThrustCurve.h b/model/ThrustCurve.h index 37467fc..9bf6129 100644 --- a/model/ThrustCurve.h +++ b/model/ThrustCurve.h @@ -26,24 +26,9 @@ public: ThrustCurve(ThrustCurve&&) = default; ~ThrustCurve(); - ThrustCurve& operator=(const ThrustCurve& rhs) - { - if(this != &rhs) - { - thrustCurve = rhs.thrustCurve; - maxTime = rhs.maxTime; - ignitionTime = rhs.ignitionTime; - } - return *this; - } + ThrustCurve& operator=(const ThrustCurve& rhs) = default; - ThrustCurve& operator=(ThrustCurve&& rhs) - { - thrustCurve = std::move(rhs.thrustCurve); - maxTime = std::move(rhs.maxTime); - ignitionTime = std::move(rhs.ignitionTime); - return *this; - } + ThrustCurve& operator=(ThrustCurve&& rhs) = default; /** * Assuming that the thrust is one dimensional. Seems reasonable, but just diff --git a/sim/Propagator.cpp b/sim/Propagator.cpp index dbdc69a..c204f6a 100644 --- a/sim/Propagator.cpp +++ b/sim/Propagator.cpp @@ -23,8 +23,7 @@ namespace sim { Propagator::Propagator(Rocket* r) : integrator(), - rocket(r), - qtrocket(QtRocket::getInstance()) + rocket(r) { @@ -45,9 +44,9 @@ Propagator::Propagator(Rocket* r) /* dvx/dt */ [this](double, const std::vector& ) -> double { return getForceX() / getMass(); }, /* dvy/dt */ [this](double, const std::vector& ) -> double { return getForceY() / getMass(); }, /* dvz/dt */ [this](double, const std::vector& ) -> double { return getForceZ() / getMass(); }, - /* dpitch/dt */ [this](double, const std::vector& s) -> double { return s[9]; }, - /* dyaw/dt */ [this](double, const std::vector& s) -> double { return s[10]; }, - /* droll/dt */ [this](double, const std::vector& s) -> double { return s[11]; }, + /* dpitch/dt */ [](double, const std::vector& s) -> double { return s[9]; }, + /* dyaw/dt */ [](double, const std::vector& s) -> double { return s[10]; }, + /* droll/dt */ [](double, const std::vector& s) -> double { return s[11]; }, /* dpitchRate/dt */ [this](double, const std::vector& s) -> double { (getTorqueP() - s[7] * s[8] * (getIroll() - getIyaw())) / getIpitch(); }, /* dyawRate/dt */ [this](double, const std::vector& s) -> double { (getTorqueQ() - s[6] * s[9] * (getIpitch() - getIroll())) / getIyaw(); }, /* drollRate/dt */ [this](double, const std::vector& s) -> double { (getTorqueR() - s[6] * s[7] * (getIyaw() - getIpitch())) / getIroll(); })); @@ -97,16 +96,19 @@ double Propagator::getMass() double Propagator::getForceX() { + QtRocket* qtrocket = QtRocket::getInstance(); return - qtrocket->getAtmosphereModel()->getDensity(currentState[3])/ 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[3]* currentState[3]; } double Propagator::getForceY() { + QtRocket* qtrocket = QtRocket::getInstance(); return -qtrocket->getAtmosphereModel()->getDensity(currentState[3]) / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[4]* currentState[4]; } double Propagator::getForceZ() { + QtRocket* qtrocket = QtRocket::getInstance(); double gravity = (qtrocket->getGravityModel()->getAccel(currentState[0], currentState[1], currentState[2])).x3; double airDrag = -qtrocket->getAtmosphereModel()->getDensity(currentState[3]) / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[5]* currentState[5]; double thrust = rocket->getThrust(currentTime); diff --git a/sim/Propagator.h b/sim/Propagator.h index 1f7515a..613aef5 100644 --- a/sim/Propagator.h +++ b/sim/Propagator.h @@ -74,7 +74,6 @@ private: std::unique_ptr integrator; Rocket* rocket; - QtRocket* qtrocket; std::vector currentState{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 tempRes{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};