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);
pCreator->AddOutport ("Pos" , 3, PORT_FUNCTION(CMass::Position));
pCreator->AddOutport ("Vel" , 3, PORT_FUNCTION(CMass::Velocity));
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 bool bIsMajorTimeStep)
{
const double*
const adForceIn =
m_pInForce->GetPortValue(dT,adX);
for (int i = 0; i<3 ; i++)
{
if (i==2)
}
}
const double* CMass::Position( const double dT, const double* const adX )
{
}
const double* CMass::Velocity( const double dT, const double* const adX )
{
}
#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:41
int m_IStateVel
The index of the velocity state.
Definition: CMass.h:44
double m_dMass
The mass of the object.
Definition: CMass.h:40
virtual void OdeFcn(const double dT, const double *const adX, double *const adXDot, const bool bIsMajorTimeStep)
Calculates the state derivatives.
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:43
ISignalPort * m_pInForce
A pointer to the input force.
Definition: CMass.h:42