Add terminateCondition to Rocket class. Allows the propagator to check the rocket for a terminate condition instead of hardcoding it in the propagator itself

This commit is contained in:
Travis Hunter 2023-04-15 16:50:36 -06:00
parent e942cfb819
commit 23566efa67
3 changed files with 11 additions and 1 deletions

View File

@ -23,6 +23,14 @@ void Rocket::launch()
propagator.runUntilTerminate(); propagator.runUntilTerminate();
} }
bool Rocket::terminateCondition(const std::pair<double, std::vector<double>>& cond)
{
if(cond.second[2] < 0)
return true;
else
return false;
}
double Rocket::getThrust(double t) double Rocket::getThrust(double t)
{ {
return tc.getThrust(t); return tc.getThrust(t);

View File

@ -25,6 +25,8 @@ public:
double getThrust(double t); double getThrust(double t);
void setThrustCurve(const Thrustcurve& curve); void setThrustCurve(const Thrustcurve& curve);
bool terminateCondition(const std::pair<double, std::vector<double>>& cond);
private: private:
sim::Propagator propagator; sim::Propagator propagator;

View File

@ -60,7 +60,7 @@ void Propagator::runUntilTerminate()
{ {
states.push_back(std::make_pair(currentTime, currentState)); states.push_back(std::make_pair(currentTime, currentState));
} }
if(currentState[2] < 0.0) if(rocket->terminateCondition(std::make_pair(currentTime, currentState)))
break; break;
currentTime += timeStep; currentTime += timeStep;