This source file shows how to implement a linear spring. It has no states, and most "work" is done in the outputport functions. See also the class documentation.
#include "CLinearSpring.h"
#include <cmath>
: SimObject(sSimObjectName)
{
#ifdef FH_VISUALIZATION
m_iNumPoints = 2;
#endif
pCreator->AddInport("PosA", 3, &m_pInPosA);
pCreator->AddInport("PosB", 3, &m_pInPosB);
pCreator->GetDoubleParam("Stiffness", &m_dStiffness);
pCreator->GetDoubleParam("RelaxedLength", &m_dRelaxedLength);
}
{
#ifdef FH_VISUALIZATION
#endif
}
{
const double* adPosA =
m_pInPosA->GetPortValue(dT, adX);
const double* adPosB =
m_pInPosB->GetPortValue(dT, adX);
double adDeltaPos[3];
double dL = 0;
for (int i = 0; i < 3; i++) {
adDeltaPos[i] = adPosA[i] - adPosB[i];
dL += adDeltaPos[i] * adDeltaPos[i];
}
if (dL <= 0.0) {
for (int i = 0; i < 3; i++) {
}
} else {
dL = sqrt(dL);
for (int i = 0; i < 3; i++) {
}
}
}
{
}
{
}
#ifdef FH_VISUALIZATION
void CLinearSpring::RenderInit(Ogre::Root* const pOgreRoot, ISimObjectCreator* const pCreator)
{
auto scenemgr = pOgreRoot->getSceneManager("main");
m_pLines = new C3DLine(scenemgr, Ogre::RenderOperation::OT_LINE_LIST, 2);
}
void CLinearSpring::RenderUpdate(const double dT, const double* const adX)
{
const double*
const adPos1In =
m_pInPosA->GetPortValue(dT, adX);
const double*
const adPos2In =
m_pInPosB->GetPortValue(dT, adX);
m_pLines->SetPoint(0, adPos1In[0], adPos1In[1], adPos1In[2]);
m_pLines->SetPoint(1, adPos2In[0], adPos2In[1], adPos2In[2]);
m_pLines->Update();
}
#endif
CLinearSpring(std::string sSimObjectName, ISimObjectCreator *pCreator)
The constructor sets the pointer to the output object and the parser object.
const double * ForceA(const double dT, const double *const adX)
Calculates the end force A.
double m_adOutForceB[3]
Force vector on point B.
Definition CLinearSpring.h:61
ICommonComputation * m_CalcOutputs
Common computation for outputs.
Definition CLinearSpring.h:63
ISignalPort * m_pInPosB
Input for position B.
Definition CLinearSpring.h:59
const double * ForceB(const double dT, const double *const adX)
Calculates the end force B.
~CLinearSpring()
The destructor cleans up dynamically allocated memory.
double m_adOutForceA[3]
Force vector on point A.
Definition CLinearSpring.h:60
ISignalPort * m_pInPosA
Input for position A.
Definition CLinearSpring.h:58
double m_dStiffness
The linear stiffness of the spring.
Definition CLinearSpring.h:56
void CalcOutput(const double dT, const double *const adX) const
< Sets the parameters of the spring.
double m_dRelaxedLength
the relaxed length of the spring.
Definition CLinearSpring.h:57