improvements to propagator getForceXYZ methods. The propagator now reaches out to the QtRocket singleton for current gravity data at each timestep. Can easily do the same for atmospheric density next
This commit is contained in:
parent
b77ba0ef04
commit
0734d6a013
@ -30,6 +30,9 @@ public:
|
||||
|
||||
void runSim();
|
||||
|
||||
std::shared_ptr<sim::GravityModel> getGravityModel() { return gravity; }
|
||||
std::shared_ptr<sim::AtmosphericModel> getAtmosphereModel() { return atmosphere; }
|
||||
|
||||
private:
|
||||
QtRocket();
|
||||
|
||||
|
@ -74,9 +74,9 @@ void MainWindow::on_testButton2_clicked()
|
||||
ui->rocketPartButtons->findChild<QLineEdit*>(QString("dragCoeff"))->text().toDouble();
|
||||
|
||||
double initialVelocityX = initialVelocity * std::cos(initialAngle / 57.2958);
|
||||
double initialVelocityY = initialVelocity * std::sin(initialAngle / 57.2958);
|
||||
double initialVelocityZ = initialVelocity * std::sin(initialAngle / 57.2958);
|
||||
Rocket rocket;
|
||||
std::vector<double> initialState = {0.0, 0.0, 0.0, initialVelocityX, initialVelocityY, 0.0};
|
||||
std::vector<double> initialState = {0.0, 0.0, 0.0, initialVelocityX, 0.0, initialVelocityZ};
|
||||
rocket.setInitialState(initialState);
|
||||
rocket.setMass(mass);
|
||||
rocket.setDragCoefficient(dragCoeff);
|
||||
@ -89,7 +89,7 @@ void MainWindow::on_testButton2_clicked()
|
||||
for (int i = 0; i < xData.size(); ++i)
|
||||
{
|
||||
xData[i] = res[i][0];
|
||||
yData[i] = res[i][1];
|
||||
yData[i] = res[i][2];
|
||||
}
|
||||
// create graph and assign data to it:
|
||||
plot->addGraph();
|
||||
|
@ -12,7 +12,7 @@ public:
|
||||
|
||||
virtual ~ConstantGravityModel() {}
|
||||
|
||||
std::tuple<double, double, double> getAccel(double, double, double) override { return std::make_tuple(0.0, 0.0, 9.8); }
|
||||
std::tuple<double, double, double> getAccel(double, double, double) override { return std::make_tuple(0.0, 0.0, -9.8); }
|
||||
};
|
||||
|
||||
} // namespace sim
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "sim/RK4Solver.h"
|
||||
#include "model/Rocket.h"
|
||||
#include "QtRocket.h"
|
||||
|
||||
#include <utility>
|
||||
#include <QTextStream>
|
||||
@ -11,7 +12,8 @@ namespace sim {
|
||||
|
||||
Propagator::Propagator(Rocket* r)
|
||||
: integrator(),
|
||||
rocket(r)
|
||||
rocket(r),
|
||||
qtrocket(QtRocket::getInstance())
|
||||
|
||||
{
|
||||
|
||||
@ -71,7 +73,7 @@ void Propagator::runUntilTerminate()
|
||||
<< currentState[3] << ", "
|
||||
<< currentState[4] << ", "
|
||||
<< currentState[5] << ")\n";
|
||||
if(currentState[1] < 0.0)
|
||||
if(currentState[2] < 0.0)
|
||||
break;
|
||||
|
||||
j++;
|
||||
@ -84,9 +86,22 @@ double Propagator::getMass()
|
||||
return rocket->getMass();
|
||||
}
|
||||
|
||||
double Propagator::getForceX() { return -1.225 / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[3]* currentState[3]; }
|
||||
double Propagator::getForceY() { return -1.225 / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[4]* currentState[4] -9.8; }
|
||||
double Propagator::getForceZ() { return 0; }
|
||||
double Propagator::getForceX()
|
||||
{
|
||||
return -1.225 / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[3]* currentState[3];
|
||||
}
|
||||
|
||||
double Propagator::getForceY()
|
||||
{
|
||||
return -1.225 / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[4]* currentState[4];
|
||||
}
|
||||
|
||||
double Propagator::getForceZ()
|
||||
{
|
||||
double gravity = std::get<2>(qtrocket->getGravityModel()->getAccel(currentState[0], currentState[1], currentState[2]));
|
||||
double airDrag = -1.225 / 2.0 * 0.008107 * rocket->getDragCoefficient() * currentState[5]* currentState[5];
|
||||
return gravity + airDrag;
|
||||
}
|
||||
|
||||
double Propagator::getTorqueP() { return 0.0; }
|
||||
double Propagator::getTorqueQ() { return 0.0; }
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
// Forward declare
|
||||
class Rocket;
|
||||
class QtRocket;
|
||||
|
||||
namespace sim
|
||||
{
|
||||
@ -62,6 +63,7 @@ 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};
|
||||
std::vector<double> tempRes{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||
|
Loading…
x
Reference in New Issue
Block a user