Fix crash on motor load

This commit is contained in:
Travis Hunter 2024-03-14 07:05:16 -06:00
parent f4e560fcd9
commit 6a015d9797
4 changed files with 14 additions and 9 deletions

View File

@ -7,6 +7,10 @@ namespace model
Rocket::Rocket()
{
// A rocket needs at least one stage. Upon creation, we need to create at least one stage
currentStage.reset(new Stage("sustainer"));
stages.push_back(currentStage);
}
@ -39,7 +43,7 @@ double Rocket::getMass(double t)
double totalMass = 0.0;
for(const auto& stage : stages)
{
totalMass += stage.second->getMass(t);
totalMass += stage->getMass(t);
}
return totalMass;
}

View File

@ -4,7 +4,7 @@
/// \cond
// C headers
// C++ headers
#include <map>
#include <vector>
#include <memory>
#include <string>
#include <utility> // std::move
@ -57,7 +57,7 @@ public:
* @param t current simulation time
* @return mass in kg
*/
virtual double getMass(double t) override;
double getMass(double t) override;
/**
* @brief setMotorModel
@ -84,8 +84,8 @@ public:
*/
void setName(const std::string& n) { name = n; }
virtual double getDragCoefficient() override { return 1.0; }
virtual void setDragCoefficient(double d) override { }
double getDragCoefficient() override { return 1.0; }
void setDragCoefficient(double d) override { }
void setMass(double m) { }
std::shared_ptr<Stage> getCurrentStage() { return currentStage; }
@ -94,7 +94,7 @@ private:
std::string name; /// Rocket name
std::map<unsigned int, std::shared_ptr<Stage>> stages;
std::vector<std::shared_ptr<Stage>> stages;
std::shared_ptr<Stage> currentStage;
//model::MotorModel mm; /// Current Motor Model

View File

@ -11,7 +11,8 @@
namespace model
{
Stage::Stage()
Stage::Stage(const std::string& inName)
: name(inName)
{}
Stage::~Stage()

View File

@ -21,7 +21,7 @@ namespace model
class Stage : public Propagatable
{
public:
Stage();
Stage(const std::string& inName);
virtual ~Stage();
/**
@ -72,4 +72,4 @@ private:
} // namespace model
#endif // SIM_STAGE_H
#endif // SIM_STAGE_H