Fix deadlock in QtRocket initialization after instantiating a default Rocket model during construction. sim::Propagator doesn't need a pointer to QtRocket always, it can just get the instance when it needs it. This is probably an opportunity for cleanup later though
This commit is contained in:
parent
c2979e3118
commit
0acec0829a
@ -75,10 +75,15 @@ QtRocket::QtRocket()
|
||||
running = false;
|
||||
|
||||
atmosphere =
|
||||
std::make_shared<sim::ConstantAtmosphere>();
|
||||
std::make_shared<sim::ConstantAtmosphere>();
|
||||
|
||||
gravity =
|
||||
std::make_shared<sim::ConstantGravityModel>();
|
||||
std::make_shared<sim::ConstantGravityModel>();
|
||||
|
||||
|
||||
rocket =
|
||||
std::make_shared<Rocket>();
|
||||
|
||||
}
|
||||
|
||||
int QtRocket::run(int argc, char* argv[])
|
||||
|
@ -1,7 +1,15 @@
|
||||
|
||||
/// \cond
|
||||
// C headers
|
||||
// C++ headers
|
||||
#include <algorithm>
|
||||
// 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<model::MotorModel> 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);
|
||||
}
|
||||
|
||||
|
@ -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<utils::ThrustCurveAPI> tcApi;
|
||||
|
||||
std::vector<model::MotorModel> motorModels;
|
||||
};
|
||||
|
||||
#endif // THRUSTCURVEMOTORSELECTOR_H
|
||||
|
@ -94,25 +94,31 @@
|
||||
<widget class="QWidget" name="formLayoutWidget_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>170</x>
|
||||
<y>260</y>
|
||||
<width>160</width>
|
||||
<x>140</x>
|
||||
<y>240</y>
|
||||
<width>221</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>Download</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="motorSelection"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="setMotor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>200</x>
|
||||
<y>290</y>
|
||||
<width>80</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>setMotor</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
@ -9,18 +9,12 @@ Rocket::Rocket() : propagator(this)
|
||||
|
||||
void Rocket::launch()
|
||||
{
|
||||
tc.setIgnitionTime(5.0);
|
||||
std::vector<std::pair<double, double>> 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<double, std::vector<double>>& cond)
|
||||
|
@ -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
|
||||
|
@ -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>& ) -> double { return getForceX() / getMass(); },
|
||||
/* dvy/dt */ [this](double, const std::vector<double>& ) -> double { return getForceY() / getMass(); },
|
||||
/* dvz/dt */ [this](double, const std::vector<double>& ) -> double { return getForceZ() / getMass(); },
|
||||
/* dpitch/dt */ [this](double, const std::vector<double>& s) -> double { return s[9]; },
|
||||
/* dyaw/dt */ [this](double, const std::vector<double>& s) -> double { return s[10]; },
|
||||
/* droll/dt */ [this](double, const std::vector<double>& s) -> double { return s[11]; },
|
||||
/* dpitch/dt */ [](double, const std::vector<double>& s) -> double { return s[9]; },
|
||||
/* dyaw/dt */ [](double, const std::vector<double>& s) -> double { return s[10]; },
|
||||
/* droll/dt */ [](double, const std::vector<double>& s) -> double { return s[11]; },
|
||||
/* dpitchRate/dt */ [this](double, const std::vector<double>& s) -> double { (getTorqueP() - s[7] * s[8] * (getIroll() - getIyaw())) / getIpitch(); },
|
||||
/* dyawRate/dt */ [this](double, const std::vector<double>& s) -> double { (getTorqueQ() - s[6] * s[9] * (getIpitch() - getIroll())) / getIyaw(); },
|
||||
/* drollRate/dt */ [this](double, const std::vector<double>& 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);
|
||||
|
@ -74,7 +74,6 @@ private:
|
||||
std::unique_ptr<sim::DESolver> integrator;
|
||||
|
||||
Rocket* rocket;
|
||||
QtRocket* qtrocket;
|
||||
|
||||
std::vector<double> 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<double> 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};
|
||||
|
Loading…
x
Reference in New Issue
Block a user