Added database loader for Rocksim Engine file databases
This commit is contained in:
parent
23566efa67
commit
c319a18bbe
@ -11,6 +11,8 @@
|
||||
#include "sim/AtmosphericModel.h"
|
||||
#include "sim/GravityModel.h"
|
||||
|
||||
#include "model/MotorModel.h"
|
||||
|
||||
/**
|
||||
* @brief The QtRocket class is the master controller for the QtRocket application.
|
||||
* It is the singleton that controls the interaction of the various components of
|
||||
@ -43,6 +45,9 @@ private:
|
||||
static std::mutex mtx;
|
||||
static QtRocket* instance;
|
||||
|
||||
// Motor "database(s)"
|
||||
std::vector<MotorModel> motorModels;
|
||||
|
||||
utils::Logger* logger;
|
||||
|
||||
std::shared_ptr<Rocket> rocket;
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "sim/RK4Solver.h"
|
||||
#include "model/Rocket.h"
|
||||
|
||||
#include "utils/RSEDatabaseLoader.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
#include <memory>
|
||||
@ -56,6 +58,7 @@ void MainWindow::on_testButton1_clicked()
|
||||
plot->yAxis->setRange(0, 1);
|
||||
plot->replot();
|
||||
|
||||
utils::RSEDatabaseLoader("Aerotech.rse");
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,14 +9,18 @@
|
||||
#include <string>
|
||||
|
||||
#include "Thrustcurve.h"
|
||||
#include "MotorCase.h"
|
||||
|
||||
class MotorModel
|
||||
{
|
||||
public:
|
||||
MotorModel();
|
||||
MotorModel(const MotorModel&) = default;
|
||||
MotorModel(MotorModel&&) = default;
|
||||
~MotorModel();
|
||||
|
||||
MotorModel& operator=(const MotorModel&) = default;
|
||||
MotorModel& operator=(MotorModel&&) = default;
|
||||
|
||||
void setDataFromJsonString(const std::string& jsonString);
|
||||
|
||||
enum class AVAILABILITY
|
||||
@ -31,7 +35,8 @@ public:
|
||||
CAR,
|
||||
NAR,
|
||||
TRA,
|
||||
UNC
|
||||
UNC,
|
||||
UNK
|
||||
};
|
||||
|
||||
enum class MOTORTYPE
|
||||
@ -44,8 +49,12 @@ public:
|
||||
struct MotorAvailability
|
||||
{
|
||||
MotorAvailability(const AVAILABILITY& a) : availability(a) {}
|
||||
MotorAvailability(MotorAvailability&&) = default;
|
||||
MotorAvailability() : MotorAvailability(AVAILABILITY::REGULAR) {}
|
||||
|
||||
MotorAvailability& operator=(const MotorAvailability&) = default;
|
||||
MotorAvailability& operator=(MotorAvailability&&) = default;
|
||||
|
||||
AVAILABILITY availability{AVAILABILITY::REGULAR};
|
||||
std::string str()
|
||||
{
|
||||
@ -59,8 +68,12 @@ public:
|
||||
struct CertOrg
|
||||
{
|
||||
CertOrg(const CERTORG& c) : org(c) {}
|
||||
CertOrg(CertOrg&&) = default;
|
||||
CertOrg() : CertOrg(CERTORG::UNC) {}
|
||||
|
||||
CertOrg& operator=(const CertOrg&) = default;
|
||||
CertOrg& operator=(CertOrg&&) = default;
|
||||
|
||||
CERTORG org{CERTORG::UNC};
|
||||
std::string str()
|
||||
{
|
||||
@ -72,16 +85,22 @@ public:
|
||||
return std::string("National Association of Rocketry");
|
||||
else if(org == CERTORG::TRA)
|
||||
return std::string("Tripoli Rocketry Association, Inc.");
|
||||
else // Uncertified
|
||||
else if(org == CERTORG::UNC)
|
||||
return std::string("Uncertified");
|
||||
else // UNK - Unknown
|
||||
return std::string("Unkown");
|
||||
}
|
||||
};
|
||||
|
||||
struct MotorType
|
||||
{
|
||||
MotorType(const MOTORTYPE& t) : type(t) {}
|
||||
MotorType(MotorType&&) = default;
|
||||
MotorType() : MotorType(MOTORTYPE::SU) {}
|
||||
|
||||
MotorType& operator=(const MotorType&) = default;
|
||||
MotorType& operator=(MotorType&&) = default;
|
||||
|
||||
MOTORTYPE type;
|
||||
std::string str()
|
||||
{
|
||||
@ -95,7 +114,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
// TODO: make these private. Public just for testing
|
||||
//private:
|
||||
// Needed for boost serialize
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
@ -112,16 +132,16 @@ private:
|
||||
int diameter{0};
|
||||
std::string impulseClass; // 'A', 'B', '1/2A', 'M', etc
|
||||
std::string infoUrl{""};
|
||||
int length;
|
||||
std::string manufacturer;
|
||||
double length{0.0};
|
||||
std::string manufacturer{""};
|
||||
|
||||
double maxThrust{0.0};
|
||||
std::string motorIdTC{""}; // 24 character hex string used by thrustcurve to ID a motor
|
||||
std::string propType{""}; // black powder, etc
|
||||
double propWeight{0.0};
|
||||
bool sparky{false};
|
||||
double totalImpulse;
|
||||
double totalWeight;
|
||||
double totalImpulse{0.0};
|
||||
double totalWeight{0.0};
|
||||
MotorType type{MOTORTYPE::SU};
|
||||
std::string lastUpdated{""};
|
||||
|
||||
|
@ -20,6 +20,8 @@ public:
|
||||
* for all requested times.
|
||||
*/
|
||||
Thrustcurve();
|
||||
Thrustcurve(const Thrustcurve&) = default;
|
||||
Thrustcurve(Thrustcurve&&) = default;
|
||||
~Thrustcurve();
|
||||
|
||||
Thrustcurve& operator=(const Thrustcurve& rhs)
|
||||
@ -31,7 +33,14 @@ public:
|
||||
ignitionTime = rhs.ignitionTime;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Thrustcurve& operator=(Thrustcurve&& rhs)
|
||||
{
|
||||
thrustCurve = std::move(rhs.thrustCurve);
|
||||
maxTime = std::move(rhs.maxTime);
|
||||
ignitionTime = std::move(rhs.ignitionTime);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,6 +31,7 @@ SOURCES += \
|
||||
utils/BinMap.cpp \
|
||||
utils/CurlConnection.cpp \
|
||||
utils/Logger.cpp \
|
||||
utils/RSEDatabaseLoader.cpp \
|
||||
utils/ThreadPool.cpp \
|
||||
utils/ThrustCurveAPI.cpp \
|
||||
utils/math/Quaternion.cpp \
|
||||
@ -63,6 +64,7 @@ HEADERS += \
|
||||
utils/BinMap.h \
|
||||
utils/CurlConnection.h \
|
||||
utils/Logger.h \
|
||||
utils/RSEDatabaseLoader.h \
|
||||
utils/TSQueue.h \
|
||||
utils/ThreadPool.h \
|
||||
utils/ThrustCurveAPI.h \
|
||||
|
104
utils/RSEDatabaseLoader.cpp
Normal file
104
utils/RSEDatabaseLoader.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
#include "RSEDatabaseLoader.h"
|
||||
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
namespace utils {
|
||||
|
||||
RSEDatabaseLoader::RSEDatabaseLoader(const std::string& filename)
|
||||
: motors(),
|
||||
tree()
|
||||
{
|
||||
boost::property_tree::read_xml(filename, tree);
|
||||
|
||||
// Get the first engine
|
||||
for(boost::property_tree::ptree::value_type& v : tree.get_child("engine-database.engine-list"))
|
||||
{
|
||||
buildAndAppendMotorModel(v.second);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RSEDatabaseLoader::~RSEDatabaseLoader()
|
||||
{}
|
||||
|
||||
void RSEDatabaseLoader::buildAndAppendMotorModel(boost::property_tree::ptree& v)
|
||||
{
|
||||
MotorModel mm;
|
||||
mm.availability = MotorModel::MotorAvailability(MotorModel::AVAILABILITY::REGULAR);
|
||||
mm.avgThrust = v.get<double>("<xmlattr>.avgThrust", 0.0);
|
||||
mm.burnTime = v.get<double>("<xmlattr>.burn-time", 0.0);
|
||||
mm.certOrg = MotorModel::CertOrg(MotorModel::CERTORG::UNK);
|
||||
mm.commonName = v.get<std::string>("<xmlattr>.code", "");
|
||||
|
||||
// mm.delays = extract vector from csv list
|
||||
|
||||
// mm.designation = What is this?
|
||||
|
||||
// This is in the form of dia="18.", or dia="38."
|
||||
{
|
||||
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
|
||||
// of the commonName since it isn't given explicity in the RSE file
|
||||
mm.impulseClass = mm.commonName[0];
|
||||
|
||||
// infoUrl not present in RSE file
|
||||
mm.infoUrl = "";
|
||||
mm.length = v.get<double>("<xmlattr>.len", 0.0);
|
||||
mm.manufacturer = v.get<std::string>("<xmlattr>.mfg", "");
|
||||
mm.maxThrust = v.get<double>("<xmlattr>.peakThrust", 0.0);
|
||||
mm.propWeight = v.get<double>("<xmlattr>.propWt", 0.0);
|
||||
mm.totalImpulse = v.get<double>("<xmlattr>.Itot", 0.0);
|
||||
|
||||
{
|
||||
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
|
||||
std::vector<std::pair<double, double>> thrustData;
|
||||
for(boost::property_tree::ptree::value_type& w : v.get_child("data"))
|
||||
{
|
||||
double tdata = w.second.get<double>("<xmlattr>.t");
|
||||
double fdata = w.second.get<double>("<xmlattr>.f");
|
||||
thrustData.push_back(std::make_pair(tdata, fdata));
|
||||
}
|
||||
std::cout << "\n--------------------------------------------\n";
|
||||
std::cout << "name: " << mm.commonName << 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));
|
||||
}
|
||||
|
||||
|
||||
} // namespace utils
|
30
utils/RSEDatabaseLoader.h
Normal file
30
utils/RSEDatabaseLoader.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef UTILS_RSEDATABASELOADER_H
|
||||
#define UTILS_RSEDATABASELOADER_H
|
||||
|
||||
#include "model/MotorModel.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
namespace utils {
|
||||
|
||||
class RSEDatabaseLoader
|
||||
{
|
||||
public:
|
||||
RSEDatabaseLoader(const std::string& filename);
|
||||
~RSEDatabaseLoader();
|
||||
|
||||
private:
|
||||
|
||||
std::vector<MotorModel> motors;
|
||||
|
||||
void buildAndAppendMotorModel(boost::property_tree::ptree& v);
|
||||
|
||||
boost::property_tree::ptree tree;
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
|
||||
#endif // UTILS_RSEDATABASELOADER_H
|
Loading…
x
Reference in New Issue
Block a user