This commit is contained in:
Travis Hunter 2023-04-22 17:37:41 -06:00
parent 32c9cda4b8
commit 620cd80fe4
12 changed files with 107 additions and 89 deletions

View File

@ -95,7 +95,7 @@ int QtRocket::run(int argc, char* argv[])
return 0; return 0;
} }
void QtRocket::addMotorModels(std::vector<MotorModel>& m) void QtRocket::addMotorModels(std::vector<model::MotorModel>& m)
{ {
for(const auto& i : m) for(const auto& i : m)
{ {

View File

@ -41,7 +41,7 @@ public:
std::shared_ptr<sim::AtmosphericModel> getAtmosphereModel() { return atmosphere; } std::shared_ptr<sim::AtmosphericModel> getAtmosphereModel() { return atmosphere; }
void addMotorModels(std::vector<MotorModel>& m); void addMotorModels(std::vector<model::MotorModel>& m);
void addRocket(std::shared_ptr<Rocket> r) { rocket = r; } void addRocket(std::shared_ptr<Rocket> r) { rocket = r; }
@ -58,7 +58,7 @@ private:
static QtRocket* instance; static QtRocket* instance;
// Motor "database(s)" // Motor "database(s)"
std::vector<MotorModel> motorModels; std::vector<model::MotorModel> motorModels;
utils::Logger* logger; utils::Logger* logger;

View File

@ -143,7 +143,7 @@ void MainWindow::on_loadRSE_button_clicked()
QComboBox* engineSelector = QComboBox* engineSelector =
ui->rocketPartButtons->findChild<QComboBox*>(QString("engineSelectorComboBox")); ui->rocketPartButtons->findChild<QComboBox*>(QString("engineSelectorComboBox"));
const std::vector<MotorModel>& motors = loader.getMotors(); const std::vector<model::MotorModel>& motors = loader.getMotors();
for(const auto& motor : motors) for(const auto& motor : motors)
{ {
std::cout << "Adding: " << motor.commonName << std::endl; std::cout << "Adding: " << motor.commonName << std::endl;

View File

@ -56,7 +56,7 @@ void ThrustCurveMotorSelector::on_searchButton_clicked()
c.addCriteria("manufacturer", manufacturer); c.addCriteria("manufacturer", manufacturer);
c.addCriteria("impulseClass", impulseClass); c.addCriteria("impulseClass", impulseClass);
std::vector<MotorModel> motors = tcApi->searchMotors(c); std::vector<model::MotorModel> motors = tcApi->searchMotors(c);
for(const auto& i : motors) for(const auto& i : motors)
{ {

View File

@ -1,6 +1,8 @@
#ifndef MODEL_MOTORCASE_H #ifndef MODEL_MOTORCASE_H
#define MODEL_MOTORCASE_H #define MODEL_MOTORCASE_H
namespace model
{
class MotorCase class MotorCase
{ {
public: public:
@ -11,4 +13,5 @@ private:
}; };
} // namespace model
#endif // MODEL_MOTORCASE_H #endif // MODEL_MOTORCASE_H

View File

@ -1,4 +1,7 @@
#include "MotorModel.h" #include "model/MotorModel.h"
namespace model
{
MotorModel::MotorModel() MotorModel::MotorModel()
{ {
@ -9,3 +12,5 @@ MotorModel::~MotorModel()
{ {
} }
} // namespace model

View File

@ -16,6 +16,9 @@
// qtrocket theaders // qtrocket theaders
#include "ThrustCurve.h" #include "ThrustCurve.h"
namespace model
{
/** /**
* @brief The MotorModel class * @brief The MotorModel class
* *
@ -134,6 +137,14 @@ public:
else else
return std::string("OOP"); return std::string("OOP");
} }
static AVAILABILITY toEnum(const std::string& name)
{
if(name == "regular")
return AVAILABILITY::REGULAR;
else
return AVAILABILITY::OOP;
}
}; };
/** /**
@ -171,6 +182,22 @@ public:
else // UNK - Unknown else // UNK - Unknown
return std::string("Unkown"); return std::string("Unkown");
} }
static CERTORG toEnum(const std::string& name)
{
if(name == "AMRS")
return CERTORG::AMRS;
else if(name == "CAR")
return CERTORG::CAR;
else if(name == "NAR")
return CERTORG::NAR;
else if(name == "TRA")
return CERTORG::TRA;
else if(name == "UNC")
return CERTORG::UNC;
else // Unknown
return CERTORG::UNK;
}
}; };
/** /**
@ -202,6 +229,17 @@ public:
else else
return std::string("Hybrid"); return std::string("Hybrid");
} }
static MOTORTYPE toEnum(const std::string& name)
{
if(name == "SU" ||
name == "Single Use")
return MOTORTYPE::SU;
else if(name == "Hybrid")
return MOTORTYPE::HYBRID;
else if(name == "reload" ||
name == "Reload")
return MOTORTYPE::RELOAD;
}
}; };
/** /**
@ -245,6 +283,24 @@ public:
return std::string("Unknown"); return std::string("Unknown");
} }
} }
static MOTORMANUFACTURER toEnum(const std::string& name)
{
if(name == "AeroTech" ||
name == "Aerotech")
return MOTORMANUFACTURER::AEROTECH;
else if(name == "AMW")
return MOTORMANUFACTURER::AMW;
else if(name == "Cesaroni")
return MOTORMANUFACTURER::CESARONI;
else if(name == "Estes")
return MOTORMANUFACTURER::ESTES;
else if(name == "Loki")
return MOTORMANUFACTURER::LOKI;
else if(name == "Apogee")
return MOTORMANUFACTURER::APOGEE;
else
return MOTORMANUFACTURER::UNKNOWN;
}
}; };
/// TODO: make these MotorModel members private. Public just for testing /// TODO: make these MotorModel members private. Public just for testing
@ -279,4 +335,6 @@ public:
}; };
} // namespace model
#endif // MODEL_MOTORMODEL_H #endif // MODEL_MOTORMODEL_H

View File

@ -34,7 +34,7 @@ public:
* @param manufacturer The manufacturer to search for * @param manufacturer The manufacturer to search for
* @return vector of MotorModels from a given manufacturer * @return vector of MotorModels from a given manufacturer
*/ */
std::vector<MotorModel> findMotorsByManufacturer(const std::string& manufacturer); std::vector<model::MotorModel> findMotorsByManufacturer(const std::string& manufacturer);
/** /**
* @brief findMotersByImpulseClass returns a vector of MotorModels with a given * @brief findMotersByImpulseClass returns a vector of MotorModels with a given
@ -42,11 +42,11 @@ public:
* @param imClass Impulse class to search for * @param imClass Impulse class to search for
* @return vector of MotorModels with a given Impulse class * @return vector of MotorModels with a given Impulse class
*/ */
std::vector<MotorModel> findMotersByImpulseClass(const std::string& imClass); std::vector<model::MotorModel> findMotersByImpulseClass(const std::string& imClass);
private: private:
std::vector<MotorModel> motors; std::vector<model::MotorModel> motors;
}; };

View File

@ -35,23 +35,18 @@ RSEDatabaseLoader::~RSEDatabaseLoader()
void RSEDatabaseLoader::buildAndAppendMotorModel(boost::property_tree::ptree& v) void RSEDatabaseLoader::buildAndAppendMotorModel(boost::property_tree::ptree& v)
{ {
MotorModel mm; model::MotorModel mm;
mm.availability = MotorModel::MotorAvailability(MotorModel::AVAILABILITY::REGULAR); mm.availability = model::MotorModel::MotorAvailability(model::MotorModel::AVAILABILITY::REGULAR);
mm.avgThrust = v.get<double>("<xmlattr>.avgThrust", 0.0); mm.avgThrust = v.get<double>("<xmlattr>.avgThrust", 0.0);
mm.burnTime = v.get<double>("<xmlattr>.burn-time", 0.0); mm.burnTime = v.get<double>("<xmlattr>.burn-time", 0.0);
mm.certOrg = MotorModel::CertOrg(MotorModel::CERTORG::UNK); mm.certOrg = model::MotorModel::CertOrg(model::MotorModel::CERTORG::UNK);
mm.commonName = v.get<std::string>("<xmlattr>.code", ""); mm.commonName = v.get<std::string>("<xmlattr>.code", "");
// mm.delays = extract vector from csv list // mm.delays = extract vector from csv list
// mm.designation = What is this? // mm.designation = What is this?
// This is in the form of dia="18.", or dia="38." mm.diameter = v.get<double>("<xmlattr>.dia", 0.0);
{
std::string dia = v.get<std::string>("<xmlattr>.dia", "");
dia = dia.substr(0, dia.length() - 1);
mm.diameter = std::stoi(dia);
}
// impulse class is the motor letter designation. extract from the first character // impulse class is the motor letter designation. extract from the first character
// of the commonName since it isn't given explicity in the RSE file // of the commonName since it isn't given explicity in the RSE file
mm.impulseClass = mm.commonName[0]; mm.impulseClass = mm.commonName[0];
@ -59,38 +54,12 @@ void RSEDatabaseLoader::buildAndAppendMotorModel(boost::property_tree::ptree& v)
// infoUrl not present in RSE file // infoUrl not present in RSE file
mm.infoUrl = ""; mm.infoUrl = "";
mm.length = v.get<double>("<xmlattr>.len", 0.0); mm.length = v.get<double>("<xmlattr>.len", 0.0);
{ mm.manufacturer = model::MotorModel::MotorManufacturer::toEnum(v.get<std::string>("<xmlattr>.mfg", ""));
std::string manufacturer = v.get<std::string>("<xmlattr>.mfg", "");
MotorModel::MotorManufacturer manu(MotorModel::MOTORMANUFACTURER::UNKNOWN);
if(manufacturer == "Aerotech")
manu = MotorModel::MOTORMANUFACTURER::AEROTECH;
else if(manufacturer == "Animal Motor Works")
manu = MotorModel::MOTORMANUFACTURER::AMW;
else if(manufacturer == "Apogee")
manu = MotorModel::MOTORMANUFACTURER::APOGEE;
mm.manufacturer = manu;
}
mm.maxThrust = v.get<double>("<xmlattr>.peakThrust", 0.0); mm.maxThrust = v.get<double>("<xmlattr>.peakThrust", 0.0);
mm.propWeight = v.get<double>("<xmlattr>.propWt", 0.0); mm.propWeight = v.get<double>("<xmlattr>.propWt", 0.0);
mm.totalImpulse = v.get<double>("<xmlattr>.Itot", 0.0); mm.totalImpulse = v.get<double>("<xmlattr>.Itot", 0.0);
{ mm.type = model::MotorModel::MotorType::toEnum(v.get<std::string>("<xmlattr>.Type"));
std::string type = v.get<std::string>("<xmlattr>.Type");
MotorModel::MotorType mt(MotorModel::MOTORTYPE::SU);
if(type.compare("reloadable") == 0)
{
mt = MotorModel::MOTORTYPE::RELOAD;
}
else if(type.compare("hybrid") == 0)
{
mt = MotorModel::MOTORTYPE::HYBRID;
}
else
{
// single use, which is default
}
mm.type = mt;
}
// Now get the thrust data // Now get the thrust data
std::vector<std::pair<double, double>> thrustData; std::vector<std::pair<double, double>> thrustData;
@ -100,23 +69,6 @@ void RSEDatabaseLoader::buildAndAppendMotorModel(boost::property_tree::ptree& v)
double fdata = w.second.get<double>("<xmlattr>.f"); double fdata = w.second.get<double>("<xmlattr>.f");
thrustData.push_back(std::make_pair(tdata, fdata)); thrustData.push_back(std::make_pair(tdata, fdata));
} }
/*
std::cout << "\n--------------------------------------------\n";
std::cout << "name: " << mm.commonName << std::endl;
std::cout << "impulseClass: " << mm.impulseClass << std::endl;
std::cout << "length: " << mm.length << std::endl;
std::cout << "manufacturer: " << mm.manufacturer << std::endl;
std::cout << "maxThrust: " << mm.maxThrust << std::endl;
std::cout << "propWeight: " << mm.propWeight << std::endl;
std::cout << "totalImpulse: " << mm.totalImpulse << std::endl;
std::cout << "--------------------------------------------\n";
std::cout << "thrust data:\n";
for(const auto& i : thrustData)
{
std::cout << "(" << i.first << ", " << i.second << ")\n";
}
*/
motors.emplace_back(std::move(mm)); motors.emplace_back(std::move(mm));
} }

View File

@ -23,10 +23,10 @@ public:
RSEDatabaseLoader(const std::string& filename); RSEDatabaseLoader(const std::string& filename);
~RSEDatabaseLoader(); ~RSEDatabaseLoader();
const std::vector<MotorModel>& getMotors() const { return motors; } const std::vector<model::MotorModel>& getMotors() const { return motors; }
private: private:
std::vector<MotorModel> motors; std::vector<model::MotorModel> motors;
void buildAndAppendMotorModel(boost::property_tree::ptree& v); void buildAndAppendMotorModel(boost::property_tree::ptree& v);

View File

@ -26,7 +26,7 @@ ThrustCurveAPI::~ThrustCurveAPI()
} }
MotorModel ThrustCurveAPI::getMotorData(const std::string& motorId) model::MotorModel ThrustCurveAPI::getMotorData(const std::string& motorId)
{ {
std::stringstream endpoint; std::stringstream endpoint;
endpoint << hostname << "download.json?motorId=" << motorId << "&data=samples"; endpoint << hostname << "download.json?motorId=" << motorId << "&data=samples";
@ -35,7 +35,7 @@ MotorModel ThrustCurveAPI::getMotorData(const std::string& motorId)
std::string res = curlConnection.get(endpoint.str(), extraHeaders); std::string res = curlConnection.get(endpoint.str(), extraHeaders);
/// TODO: fix this /// TODO: fix this
MotorModel mm; model::MotorModel mm;
return mm; return mm;
} }
@ -62,17 +62,17 @@ ThrustcurveMetadata ThrustCurveAPI::getMetadata()
std::string org = (*iter)["abbrev"].asString(); std::string org = (*iter)["abbrev"].asString();
if(org == "AMRS") if(org == "AMRS")
ret.certOrgs.emplace_back(MotorModel::CERTORG::AMRS); ret.certOrgs.emplace_back(model::MotorModel::CERTORG::AMRS);
else if(org == "CAR") else if(org == "CAR")
ret.certOrgs.emplace_back(MotorModel::CERTORG::CAR); ret.certOrgs.emplace_back(model::MotorModel::CERTORG::CAR);
else if(org == "NAR") else if(org == "NAR")
ret.certOrgs.emplace_back(MotorModel::CERTORG::NAR); ret.certOrgs.emplace_back(model::MotorModel::CERTORG::NAR);
else if(org == "TRA") else if(org == "TRA")
ret.certOrgs.emplace_back(MotorModel::CERTORG::TRA); ret.certOrgs.emplace_back(model::MotorModel::CERTORG::TRA);
else if(org == "UNC") else if(org == "UNC")
ret.certOrgs.emplace_back(MotorModel::CERTORG::UNC); ret.certOrgs.emplace_back(model::MotorModel::CERTORG::UNC);
else else
ret.certOrgs.emplace_back(MotorModel::CERTORG::UNK); ret.certOrgs.emplace_back(model::MotorModel::CERTORG::UNK);
} }
for(Json::ValueConstIterator iter = jsonResult["diameters"].begin(); for(Json::ValueConstIterator iter = jsonResult["diameters"].begin();
iter != jsonResult["diameters"].end(); iter != jsonResult["diameters"].end();
@ -98,11 +98,11 @@ ThrustcurveMetadata ThrustCurveAPI::getMetadata()
{ {
std::string type = (*iter)["types"].asString(); std::string type = (*iter)["types"].asString();
if(type == "SU") if(type == "SU")
ret.types.emplace_back(MotorModel::MOTORTYPE::SU); ret.types.emplace_back(model::MotorModel::MOTORTYPE::SU);
else if(type == "reload") else if(type == "reload")
ret.types.emplace_back(MotorModel::MOTORTYPE::RELOAD); ret.types.emplace_back(model::MotorModel::MOTORTYPE::RELOAD);
else else
ret.types.emplace_back(MotorModel::MOTORTYPE::HYBRID); ret.types.emplace_back(model::MotorModel::MOTORTYPE::HYBRID);
} }
} }
catch(const std::exception& e) catch(const std::exception& e)
@ -119,9 +119,9 @@ ThrustcurveMetadata ThrustCurveAPI::getMetadata()
} }
std::vector<MotorModel> ThrustCurveAPI::searchMotors(const SearchCriteria& c) std::vector<model::MotorModel> ThrustCurveAPI::searchMotors(const SearchCriteria& c)
{ {
std::vector<MotorModel> retVal; std::vector<model::MotorModel> retVal;
std::string endpoint = hostname; std::string endpoint = hostname;
endpoint += "search.json?"; endpoint += "search.json?";
for(const auto& i : c.criteria) for(const auto& i : c.criteria)
@ -148,14 +148,14 @@ std::vector<MotorModel> ThrustCurveAPI::searchMotors(const SearchCriteria& c)
iter != jsonResult["results"].end(); iter != jsonResult["results"].end();
++iter) ++iter)
{ {
MotorModel mm; model::MotorModel mm;
mm.commonName = (*iter)["commonName"].asString(); mm.commonName = (*iter)["commonName"].asString();
std::string availability = (*iter)["availability"].asString(); std::string availability = (*iter)["availability"].asString();
if(availability == "regular") if(availability == "regular")
mm.availability = MotorModel::MotorAvailability(MotorModel::AVAILABILITY::REGULAR); mm.availability = model::MotorModel::MotorAvailability(model::MotorModel::AVAILABILITY::REGULAR);
else else
mm.availability = MotorModel::MotorAvailability(MotorModel::AVAILABILITY::OOP); mm.availability = model::MotorModel::MotorAvailability(model::MotorModel::AVAILABILITY::OOP);
mm.avgThrust = (*iter)["avgThrustN"].asDouble(); mm.avgThrust = (*iter)["avgThrustN"].asDouble();
mm.burnTime = (*iter)["burnTimeS"].asDouble(); mm.burnTime = (*iter)["burnTimeS"].asDouble();
@ -167,7 +167,7 @@ std::vector<MotorModel> ThrustCurveAPI::searchMotors(const SearchCriteria& c)
mm.length = (*iter)["length"].asDouble(); mm.length = (*iter)["length"].asDouble();
std::string manu = (*iter)["manufacturer"].asString(); std::string manu = (*iter)["manufacturer"].asString();
if(manu == "AeroTech") if(manu == "AeroTech")
mm.manufacturer = MotorModel::MOTORMANUFACTURER::AEROTECH; mm.manufacturer = model::MotorModel::MOTORMANUFACTURER::AEROTECH;
//mm.manufacturer = (*iter)["manufacturer"].asString(); //mm.manufacturer = (*iter)["manufacturer"].asString();
mm.maxThrust = (*iter)["maxThrustN"].asDouble(); mm.maxThrust = (*iter)["maxThrustN"].asDouble();
mm.motorIdTC = (*iter)["motorId"].asString(); mm.motorIdTC = (*iter)["motorId"].asString();
@ -179,11 +179,11 @@ std::vector<MotorModel> ThrustCurveAPI::searchMotors(const SearchCriteria& c)
std::string type = (*iter)["type"].asString(); std::string type = (*iter)["type"].asString();
if(type == "SU") if(type == "SU")
mm.type = MotorModel::MotorType(MotorModel::MOTORTYPE::SU); mm.type = model::MotorModel::MotorType(model::MotorModel::MOTORTYPE::SU);
else if(type == "reload") else if(type == "reload")
mm.type = MotorModel::MotorType(MotorModel::MOTORTYPE::RELOAD); mm.type = model::MotorModel::MotorType(model::MotorModel::MOTORTYPE::RELOAD);
else else
mm.type = MotorModel::MotorType(MotorModel::MOTORTYPE::HYBRID); mm.type = model::MotorModel::MotorType(model::MotorModel::MOTORTYPE::HYBRID);
retVal.push_back(mm); retVal.push_back(mm);
} }

View File

@ -31,11 +31,11 @@ public:
ThrustcurveMetadata& operator=(ThrustcurveMetadata&&) = default; ThrustcurveMetadata& operator=(ThrustcurveMetadata&&) = default;
//private: //private:
std::vector<MotorModel::CertOrg> certOrgs; std::vector<model::MotorModel::CertOrg> certOrgs;
std::vector<double> diameters; std::vector<double> diameters;
std::vector<std::string> impulseClasses; std::vector<std::string> impulseClasses;
std::map<std::string, std::string> manufacturers; std::map<std::string, std::string> manufacturers;
std::vector<MotorModel::MotorType> types; std::vector<model::MotorModel::MotorType> types;
}; };
@ -73,7 +73,7 @@ public:
* @brief getThrustCurve will download the thrust data for the given Motor using the motorId * @brief getThrustCurve will download the thrust data for the given Motor using the motorId
* @param m MotorModel to populate * @param m MotorModel to populate
*/ */
MotorModel getMotorData(const std::string& motorId); model::MotorModel getMotorData(const std::string& motorId);
/** /**
@ -82,7 +82,7 @@ public:
ThrustcurveMetadata getMetadata(); ThrustcurveMetadata getMetadata();
std::vector<MotorModel> searchMotors(const SearchCriteria& c); std::vector<model::MotorModel> searchMotors(const SearchCriteria& c);