This source file shows how to implement a mass object. This is only a mass point, with three degrees of freedom. It has six states, position and velocity along global x-, y- and z-axis. Its output is basically the same as its states. Most "work" is done in the OdeFcn. See also the class documentation.
#include "CMass.h"
CMass::CMass(std::string sSimObjectName, ISimObjectCreator* pCreator)
: SimObject(sSimObjectName)
{
pCreator->AddInport("Force", 3, &m_pInForce);
m_IStatePos = pCreator->AddState("Pos", 3);
m_IStateVel = pCreator->AddState("Vel", 3);
pCreator->GetDoubleParam("Mass", &m_dMass);
pCreator->GetDoubleParam("g", &m_dg, 0.0);
if (m_dMass <= 0)
pCreator->ReportParameterError("Mass", "Must be a real number greater than zero.");
#ifdef FH_VISUALIZATION
pCreator->GetStringParam("Material", m_sMaterial, "Simple/Black");
pCreator->GetStringParam("Mesh", m_sMeshName, "fhSphere.mesh");
pCreator->GetDoubleParam("Scale", &m_dScale, 1.0);
#endif
}
double* const adXDot) const
{
const double*
const adForceIn =
m_pInForce->GetPortValue(dT, adX);
for (int i = 0; i < 3; i++) {
if (i == 2)
}
}
{
}
{
}
#ifdef FH_VISUALIZATION
void CMass::RenderInit(Ogre::Root* const pOgreRoot, ISimObjectCreator* const pCreator)
{
m_pSceneMgr = pOgreRoot->getSceneManager("main");
m_pRenderNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode(m_simObjectName + "FollowNode");
m_pRenderEntity = m_pSceneMgr->createEntity(m_simObjectName + "Entity", m_sMeshName);
m_pRenderEntity->setMaterialName(m_sMaterial);
m_pRenderNode->attachObject(m_pRenderEntity);
m_pRenderNode->scale(m_dScale, m_dScale, m_dScale);
}
void CMass::RenderUpdate(const double T, const double* const X)
{
m_pRenderNode->setPosition(
}
#endif
double m_dg
The acceleration of gravity.
Definition CMass.h:51
virtual const double * Velocity(const double dT, const double *const adX)
Returns the current velocity state.
int m_IStateVel
The index of the velocity state.
Definition CMass.h:54
virtual const double * Position(const double dT, const double *const adX)
Returns the current position state.
virtual void OdeFcn(const double dT, const double *const adX, double *const adXDot) const
Calculates the state derivatives.
double m_dMass
The mass of the object.
Definition CMass.h:50
CMass(std::string sSimObjectName, ISimObjectCreator *pCreator)
The constructor sets the pointer to the output object and the parser object.
int m_IStatePos
The index of the position state.
Definition CMass.h:53
ISignalPort * m_pInForce
A pointer to the input force.
Definition CMass.h:52