From 47919b661f249912b1bff4cd9fe1c5c92521cb46 Mon Sep 17 00:00:00 2001 From: Travis Hunter Date: Wed, 3 May 2023 18:46:14 -0600 Subject: [PATCH] Fix for motor mass curve calculation --- CMakeLists.txt | 3 +++ QtRocket.cpp | 5 +++++ model/MotorModel.cpp | 19 +++++++++++-------- model/MotorModel.h | 2 ++ model/Rocket.h | 2 +- sim/Propagator.cpp | 2 +- utils/RSEDatabaseLoader.cpp | 3 ++- utils/ThrustCurveAPI.cpp | 2 +- 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0659ef..ece6ee2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,9 @@ set(BUILD_CURL_EXE OFF) set(BUILD_SHARED_LIBS OFF) set(HTTP_ONLY ON) set(SSL_ENABLED ON) +if(WIN32) + set(CURL_USE_SCHANNEL ON) +endif() FetchContent_MakeAvailable(CURL) diff --git a/QtRocket.cpp b/QtRocket.cpp index 9c39fe7..c077080 100644 --- a/QtRocket.cpp +++ b/QtRocket.cpp @@ -12,6 +12,7 @@ // qtrocket headers #include "QtRocket.h" +#include "utils/Logger.h" #include "gui/MainWindow.h" // Initialize static member data @@ -23,6 +24,8 @@ bool QtRocket::initialized = false; // The gui worker thread void guiWorker(int argc, char* argv[], int& ret) { + utils::Logger* logger = utils::Logger::getInstance(); + logger->info("Starting QApplication"); QApplication a(argc, argv); a.setWindowIcon(QIcon(":/qtrocket.png")); @@ -42,6 +45,7 @@ void guiWorker(int argc, char* argv[], int& ret) // Go! MainWindow w(QtRocket::getInstance()); + logger->info("Showing MainWindow"); w.show(); ret = a.exec(); @@ -61,6 +65,7 @@ void QtRocket::init() std::lock_guard lck(mtx); if(!initialized) { + utils::Logger::getInstance()->info("Instantiating new QtRocket"); instance = new QtRocket(); initialized = true; } diff --git a/model/MotorModel.cpp b/model/MotorModel.cpp index 80c5c75..63c393e 100644 --- a/model/MotorModel.cpp +++ b/model/MotorModel.cpp @@ -89,6 +89,17 @@ double MotorModel::getThrust(double simTime) void MotorModel::setMetaData(const MetaData& md) { data = md; + computeMassCurve(); +} + +void MotorModel::moveMetaData(MetaData&& md) +{ + data = std::move(md); + computeMassCurve(); +} + +void MotorModel::computeMassCurve() +{ emptyMass = data.totalWeight - data.propWeight; // Calculate the Isp for the motor, as we'll need this for the computing the mass flow rate. @@ -115,13 +126,5 @@ void MotorModel::setMetaData(const MetaData& md) propMass -= thrust.getThrust(t + i*timeStep) * timeStep * data.propWeight / data.totalImpulse; } massCurve.push_back(std::make_pair(data.burnTime, 0.0)); - - - -} - -void MotorModel::moveMetaData(MetaData&& md) -{ - data = std::move(md); } } // namespace model diff --git a/model/MotorModel.h b/model/MotorModel.h index 4f719d3..cc96314 100644 --- a/model/MotorModel.h +++ b/model/MotorModel.h @@ -412,6 +412,8 @@ private: ThrustCurve thrust; /// The measured motor thrust curve std::vector> massCurve; + + void computeMassCurve(); }; diff --git a/model/Rocket.h b/model/Rocket.h index da1459a..72345a4 100644 --- a/model/Rocket.h +++ b/model/Rocket.h @@ -50,7 +50,7 @@ public: * @brief getMass returns the current mass of the rocket. This is the sum of all components' masses * @return total current mass of the Rocket */ - double getMass() const { return mass; } + double getMass(double simTime) const { return mass + mm.getMass(simTime); } /** * @brief setMass sets the current total mass of the Rocket diff --git a/sim/Propagator.cpp b/sim/Propagator.cpp index 93659eb..619377a 100644 --- a/sim/Propagator.cpp +++ b/sim/Propagator.cpp @@ -92,7 +92,7 @@ void Propagator::runUntilTerminate() double Propagator::getMass() { - return rocket->getMass(); + return rocket->getMass(currentTime); } double Propagator::getForceX() diff --git a/utils/RSEDatabaseLoader.cpp b/utils/RSEDatabaseLoader.cpp index 3d9eba8..111aa21 100644 --- a/utils/RSEDatabaseLoader.cpp +++ b/utils/RSEDatabaseLoader.cpp @@ -71,7 +71,8 @@ void RSEDatabaseLoader::buildAndAppendMotorModel(boost::property_tree::ptree& v) mm.length = v.get(".len", 0.0); mm.manufacturer = model::MotorModel::MotorManufacturer::toEnum(v.get(".mfg", "")); mm.maxThrust = v.get(".peakThrust", 0.0); - mm.propWeight = v.get(".propWt", 0.0); + mm.totalWeight = v.get(".initWt", 0.0) / 1000.0; // convert g -> kg + mm.propWeight = v.get(".propWt", 0.0) / 1000.0; // convert g -> kg mm.totalImpulse = v.get(".Itot", 0.0); mm.type = model::MotorModel::MotorType::toEnum(v.get(".Type")); diff --git a/utils/ThrustCurveAPI.cpp b/utils/ThrustCurveAPI.cpp index 26ad054..de3ff83 100644 --- a/utils/ThrustCurveAPI.cpp +++ b/utils/ThrustCurveAPI.cpp @@ -14,7 +14,7 @@ namespace utils { ThrustCurveAPI::ThrustCurveAPI() - : hostname("http://www.thrustcurve.org/"), + : hostname("https://www.thrustcurve.org/"), curlConnection() {