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
@ -79,6 +79,11 @@ QtRocket::QtRocket()
|
|||||||
|
|
||||||
gravity =
|
gravity =
|
||||||
std::make_shared<sim::ConstantGravityModel>();
|
std::make_shared<sim::ConstantGravityModel>();
|
||||||
|
|
||||||
|
|
||||||
|
rocket =
|
||||||
|
std::make_shared<Rocket>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int QtRocket::run(int argc, char* argv[])
|
int QtRocket::run(int argc, char* argv[])
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
|
|
||||||
|
/// \cond
|
||||||
|
// C headers
|
||||||
|
// C++ headers
|
||||||
|
#include <algorithm>
|
||||||
|
// 3rd party headers
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
// qtrocket headers
|
// qtrocket headers
|
||||||
#include "ThrustCurveMotorSelector.h"
|
#include "ThrustCurveMotorSelector.h"
|
||||||
#include "ui_ThrustCurveMotorSelector.h"
|
#include "ui_ThrustCurveMotorSelector.h"
|
||||||
|
#include "QtRocket.h"
|
||||||
|
|
||||||
ThrustCurveMotorSelector::ThrustCurveMotorSelector(QWidget *parent) :
|
ThrustCurveMotorSelector::ThrustCurveMotorSelector(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
@ -57,6 +65,7 @@ void ThrustCurveMotorSelector::on_searchButton_clicked()
|
|||||||
c.addCriteria("impulseClass", impulseClass);
|
c.addCriteria("impulseClass", impulseClass);
|
||||||
|
|
||||||
std::vector<model::MotorModel> motors = tcApi->searchMotors(c);
|
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)
|
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
|
// qtrocket headers
|
||||||
#include "utils/ThrustCurveAPI.h"
|
#include "utils/ThrustCurveAPI.h"
|
||||||
|
#include "model/MotorModel.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ThrustCurveMotorSelector;
|
class ThrustCurveMotorSelector;
|
||||||
@ -33,10 +34,14 @@ private slots:
|
|||||||
|
|
||||||
void on_searchButton_clicked();
|
void on_searchButton_clicked();
|
||||||
|
|
||||||
private:
|
void on_setMotor_clicked();
|
||||||
|
|
||||||
|
private:
|
||||||
Ui::ThrustCurveMotorSelector *ui;
|
Ui::ThrustCurveMotorSelector *ui;
|
||||||
|
|
||||||
std::unique_ptr<utils::ThrustCurveAPI> tcApi;
|
std::unique_ptr<utils::ThrustCurveAPI> tcApi;
|
||||||
|
|
||||||
|
std::vector<model::MotorModel> motorModels;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // THRUSTCURVEMOTORSELECTOR_H
|
#endif // THRUSTCURVEMOTORSELECTOR_H
|
||||||
|
@ -94,25 +94,31 @@
|
|||||||
<widget class="QWidget" name="formLayoutWidget_2">
|
<widget class="QWidget" name="formLayoutWidget_2">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>170</x>
|
<x>140</x>
|
||||||
<y>260</y>
|
<y>240</y>
|
||||||
<width>160</width>
|
<width>221</width>
|
||||||
<height>41</height>
|
<height>41</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout_2">
|
<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">
|
<item row="0" column="1">
|
||||||
<widget class="QComboBox" name="motorSelection"/>
|
<widget class="QComboBox" name="motorSelection"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</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>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
@ -9,20 +9,14 @@ Rocket::Rocket() : propagator(this)
|
|||||||
|
|
||||||
void Rocket::launch()
|
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)
|
bool Rocket::terminateCondition(const std::pair<double, std::vector<double>>& cond)
|
||||||
{
|
{
|
||||||
if(cond.second[2] < 0)
|
if(cond.second[2] < 0)
|
||||||
|
@ -26,24 +26,9 @@ public:
|
|||||||
ThrustCurve(ThrustCurve&&) = default;
|
ThrustCurve(ThrustCurve&&) = default;
|
||||||
~ThrustCurve();
|
~ThrustCurve();
|
||||||
|
|
||||||
ThrustCurve& operator=(const ThrustCurve& rhs)
|
ThrustCurve& operator=(const ThrustCurve& rhs) = default;
|
||||||
{
|
|
||||||
if(this != &rhs)
|
|
||||||
{
|
|
||||||
thrustCurve = rhs.thrustCurve;
|
|
||||||
maxTime = rhs.maxTime;
|
|
||||||
ignitionTime = rhs.ignitionTime;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ThrustCurve& operator=(ThrustCurve&& rhs)
|
ThrustCurve& operator=(ThrustCurve&& rhs) = default;
|
||||||
{
|
|
||||||
thrustCurve = std::move(rhs.thrustCurve);
|
|
||||||
maxTime = std::move(rhs.maxTime);
|
|
||||||
ignitionTime = std::move(rhs.ignitionTime);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assuming that the thrust is one dimensional. Seems reasonable, but just
|
* Assuming that the thrust is one dimensional. Seems reasonable, but just
|
||||||
|
@ -23,8 +23,7 @@ namespace sim {
|
|||||||
|
|
||||||
Propagator::Propagator(Rocket* r)
|
Propagator::Propagator(Rocket* r)
|
||||||
: integrator(),
|
: integrator(),
|
||||||
rocket(r),
|
rocket(r)
|
||||||
qtrocket(QtRocket::getInstance())
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -45,9 +44,9 @@ Propagator::Propagator(Rocket* r)
|
|||||||
/* dvx/dt */ [this](double, const std::vector<double>& ) -> double { return getForceX() / getMass(); },
|
/* dvx/dt */ [this](double, const std::vector<double>& ) -> double { return getForceX() / getMass(); },
|
||||||
/* dvy/dt */ [this](double, const std::vector<double>& ) -> double { return getForceY() / 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(); },
|
/* 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]; },
|
/* dpitch/dt */ [](double, const std::vector<double>& s) -> double { return s[9]; },
|
||||||
/* dyaw/dt */ [this](double, const std::vector<double>& s) -> double { return s[10]; },
|
/* dyaw/dt */ [](double, const std::vector<double>& s) -> double { return s[10]; },
|
||||||
/* droll/dt */ [this](double, const std::vector<double>& s) -> double { return s[11]; },
|
/* 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(); },
|
/* 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(); },
|
/* 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(); }));
|
/* 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()
|
double Propagator::getForceX()
|
||||||
{
|
{
|
||||||
|
QtRocket* qtrocket = QtRocket::getInstance();
|
||||||
return - qtrocket->getAtmosphereModel()->getDensity(currentState[3])/ 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[3]* currentState[3];
|
return - qtrocket->getAtmosphereModel()->getDensity(currentState[3])/ 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[3]* currentState[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
double Propagator::getForceY()
|
double Propagator::getForceY()
|
||||||
{
|
{
|
||||||
|
QtRocket* qtrocket = QtRocket::getInstance();
|
||||||
return -qtrocket->getAtmosphereModel()->getDensity(currentState[3]) / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[4]* currentState[4];
|
return -qtrocket->getAtmosphereModel()->getDensity(currentState[3]) / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[4]* currentState[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
double Propagator::getForceZ()
|
double Propagator::getForceZ()
|
||||||
{
|
{
|
||||||
|
QtRocket* qtrocket = QtRocket::getInstance();
|
||||||
double gravity = (qtrocket->getGravityModel()->getAccel(currentState[0], currentState[1], currentState[2])).x3;
|
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 airDrag = -qtrocket->getAtmosphereModel()->getDensity(currentState[3]) / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[5]* currentState[5];
|
||||||
double thrust = rocket->getThrust(currentTime);
|
double thrust = rocket->getThrust(currentTime);
|
||||||
|
@ -74,7 +74,6 @@ private:
|
|||||||
std::unique_ptr<sim::DESolver> integrator;
|
std::unique_ptr<sim::DESolver> integrator;
|
||||||
|
|
||||||
Rocket* rocket;
|
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> 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};
|
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