Initial 6DoF implementation. The Euler rigid body dynamical equations are present, but there are no torques yet

This commit is contained in:
Travis Hunter 2023-04-17 18:53:22 -06:00
parent c319a18bbe
commit 9ca604049e
4 changed files with 61 additions and 34 deletions

View File

@ -80,7 +80,7 @@ void MainWindow::on_testButton2_clicked()
double initialVelocityX = initialVelocity * std::cos(initialAngle / 57.2958);
double initialVelocityZ = initialVelocity * std::sin(initialAngle / 57.2958);
Rocket rocket;
std::vector<double> initialState = {0.0, 0.0, 0.0, initialVelocityX, 0.0, initialVelocityZ};
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};
rocket.setInitialState(initialState);
rocket.setMass(mass);
rocket.setDragCoefficient(dragCoeff);

View File

@ -105,42 +105,17 @@
<x>260</x>
<y>80</y>
<width>161</width>
<height>120</height>
<height>151</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Velocity</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="initialVelocity">
<property name="text">
<string>50.0</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="initialAngle">
<property name="text">
<string>90.0</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>mass</string>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
@ -158,6 +133,20 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="initialVelocity">
<property name="text">
<string>50.0</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="dragCoeff">
<property name="text">
@ -165,6 +154,34 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>mass</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Velocity</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="timeStep">
<property name="text">
<string>0.01</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Time Step</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

View File

@ -27,14 +27,21 @@ Propagator::Propagator(Rocket* r)
// template types, and it derives from DESolver, so we can just reset the unique_ptr
// and pass it a freshly allocated RK4Solver pointer
// The state vector has components of the form: (x, y, z, xdot, ydot, zdot)
// The state vector has components of the form:
// (x, y, z, xdot, ydot, zdot, pitch, yaw, roll, pitchRate, yawRate, rollRate)
integrator.reset(new RK4Solver(
/* dx/dt */ [](double, const std::vector<double>& s) -> double {return s[3]; },
/* dy/dt */ [](double, const std::vector<double>& s) -> double {return s[4]; },
/* dz/dt */ [](double, const std::vector<double>& s) -> double {return s[5]; },
/* 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(); }));
/* 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]; },
/* 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(); }));
integrator->setTimeStep(timeStep);

View File

@ -48,6 +48,7 @@ public:
void setSaveStats(bool s) { saveStates = s; }
private:
double getMass();
double getForceX();
double getForceY();
double getForceZ();
@ -56,7 +57,9 @@ private:
double getTorqueQ();
double getTorqueR();
double getMass();
double getIpitch() { return 1.0; }
double getIyaw() { return 1.0; }
double getIroll() { return 1.0; }
//private:
@ -65,8 +68,8 @@ private:
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};
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};
bool saveStates{true};
double currentTime{0.0};
double timeStep{0.01};