WIP. Started building model/Part component

This commit is contained in:
Travis Hunter 2023-10-19 08:33:34 -06:00
parent 4da21707b6
commit 9391b85a07
6 changed files with 125 additions and 4 deletions

View File

@ -3,6 +3,8 @@ add_library(model
MotorModel.h
MotorModelDatabase.cpp
MotorModelDatabase.h
Part.cpp
Part.h
Rocket.cpp
Rocket.h
ThrustCurve.cpp

View File

@ -60,6 +60,7 @@ double MotorModel::getMass(double simTime) const
double propMassEnd = i->second;
double slope = (propMassEnd - propMassStart) / (tEnd - tStart);
double currentMass = emptyMass + propMassStart + (thrustTime - tStart) * slope;
utils::Logger::getInstance()->info("simTime: " + std::to_string(simTime) + ": motor mass: " + std::to_string(currentMass));
return currentMass;
}

6
model/Part.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "Part.h"
namespace model
{
} // namespace model

61
model/Part.h Normal file
View File

@ -0,0 +1,61 @@
#ifndef MODEL_PART_H
#define MODEL_PART_H
/// \cond
// C headers
// C++ headers
#include <atomic>
#include <memory>
#include <mutex>
#include <utility>
// 3rd party headers
/// \endcond
// qtrocket headers
#include "utils/math/MathTypes.h"
namespace model
{
class Part
{
public:
Part();
virtual ~Part();
void setMass(double m) { mass = m; }
// Set the inertia tensor
void setI(const Matrix3& I) { inertiaTensor = I; }
void setCm(const Vector3& x) { cm = x; }
// Special version of setCM that assumes the cm lies along the body x-axis
void setCm(double x) { cm = {x, 0.0, 0.0}; }
void setLength(double l) { length = l; }
void setInnerRadius(double r) { innerRadiusTop = r; innerRadiusBottom = r; }
void setOuterRadius(double r) { outerRadiusTop = r; outerRadiusBottom = r; }
private:
Matrix3 inertiaTensor; // moment of inertia tensor with respect to the part's center of mass and
//
double mass; // The moment of inertia tensor also has this, so don't double compute
Vector3 cm; // center of mass wrt middle of component
double length;
double innerRadiusTop;
double outerRadiusTop;
double innerRadiusBottom;
double outerRadiusBottom;
};
}
#endif // MODEL_PART_H

View File

@ -59,12 +59,12 @@ private:
double getForceY();
double getForceZ();
double getTorqueP();
double getTorqueQ();
double getTorqueR();
double getTorqueP(); // yaw
double getTorqueQ(); // pitch
double getTorqueR(); // roll
double getIpitch() { return 1.0; }
double getIyaw() { return 1.0; }
double getIpitch() { return 1.0; }
double getIroll() { return 1.0; }
std::unique_ptr<sim::RK4Solver<Vector3>> linearIntegrator;

View File

@ -2,6 +2,7 @@
#define UTILS_MATH_MATHTYPES_H
#include <Eigen/Dense>
#include <vector>
/// This is not in any namespace. These typedefs are intended to be used throughout QtRocket,
/// so keeping them in the global namespace seems to make sense.
@ -20,4 +21,54 @@ using Matrix4 = MyMatrix<4>;
using Vector3 = MyVector<3>;
using Vector6 = MyVector<6>;
/*
namespace utils
{
std::vector<double> myVectorToStdVector(const Vector3& x)
{
return std::vector<double>{x.coeff(0), x.coeff(1), x.coeff(2)};
}
std::vector<double> myVectorToStdVector(const Vector6& x)
{
return std::vector<double>{x.coeff(0),
x.coeff(1),
x.coeff(2),
x.coeff(3),
x.coeff(4),
x.coeff(5)};
}
}
class Vector3 : public MyVector<3>
{
public:
template<typename... Args>
Vector3(Args&&... args) : MyVector<3>(std::forward<Args>(args)...)
{}
operator std::vector<double>()
{
return std::vector<double>{this->coeff(0), this->coeff(1), this->coeff(2)};
}
};
class Vector6 : public MyVector<6>
{
public:
template<typename... Args>
Vector6(Args&&... args) : MyVector<6>(std::forward<Args>(args)...)
{}
operator std::vector<double>()
{
return std::vector<double>{this->coeff(0),
this->coeff(1),
this->coeff(2),
this->coeff(3),
this->coeff(4),
this->coeff(5)};
}
};
*/
#endif // UTILS_MATH_MATHTYPES_H