From 23566efa670950f854cdd0540a45d6885a15fff5 Mon Sep 17 00:00:00 2001 From: Travis Hunter Date: Sat, 15 Apr 2023 16:50:36 -0600 Subject: [PATCH] Add terminateCondition to Rocket class. Allows the propagator to check the rocket for a terminate condition instead of hardcoding it in the propagator itself --- model/Rocket.cpp | 8 ++++++++ model/Rocket.h | 2 ++ sim/Propagator.cpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/model/Rocket.cpp b/model/Rocket.cpp index d83535e..180e1b9 100644 --- a/model/Rocket.cpp +++ b/model/Rocket.cpp @@ -23,6 +23,14 @@ void Rocket::launch() propagator.runUntilTerminate(); } +bool Rocket::terminateCondition(const std::pair>& cond) +{ + if(cond.second[2] < 0) + return true; + else + return false; +} + double Rocket::getThrust(double t) { return tc.getThrust(t); diff --git a/model/Rocket.h b/model/Rocket.h index 4382af5..44a705c 100644 --- a/model/Rocket.h +++ b/model/Rocket.h @@ -25,6 +25,8 @@ public: double getThrust(double t); void setThrustCurve(const Thrustcurve& curve); + + bool terminateCondition(const std::pair>& cond); private: sim::Propagator propagator; diff --git a/sim/Propagator.cpp b/sim/Propagator.cpp index 23f1272..a2fcf23 100644 --- a/sim/Propagator.cpp +++ b/sim/Propagator.cpp @@ -60,7 +60,7 @@ void Propagator::runUntilTerminate() { states.push_back(std::make_pair(currentTime, currentState)); } - if(currentState[2] < 0.0) + if(rocket->terminateCondition(std::make_pair(currentTime, currentState))) break; currentTime += timeStep;