FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
CBall.h
1
2#ifndef CBALL_H
3#define CBALL_H
4
88// Includes
89#include "sfh/timers/Timer.h"
90
91#include <Eigen/Core>
92#include <Eigen/Geometry>
93
94#include <fhsim/simobject/SimObject.h>
95#include <limits>
96#include <ostream>
97#include <string>
98#include <vector>
99
100class CBall : public SimObject
101{
102 public:
114 CBall(std::string simObjectName, ISimObjectCreator* creator);
115
116 ~CBall();
117
118#ifdef FH_VISUALIZATION
119
121 virtual void RenderInit(Ogre::Root* const OgreRoot, ISimObjectCreator* const creator);
122
124 virtual void RenderUpdate(const double T, const double* const X);
125#endif
126
138 void OdeFcn(const double T, const double* const X, double* const XDot) const;
139
140 bool HasJacobians() const override;
141 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
142 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
143
153 const double* ForceOut(const double T, const double* const X);
154
155 protected:
165 void CalcForces(const double T, const double* const X) const;
166
175 void ForceInterBall(const double T, const double* const X) const;
176
184 virtual const double* Position(const double T, const double* const X);
185
193 virtual const double* Velocity(const double T, const double* const X);
194
195 // Member variables
196 int m_count;
197 double m_gravity;
198 double* m_mass;
199 double* m_radius;
200 double* m_stiffness;
201 double m_boxDim[3];
202 Eigen::Vector3d m_norms[6];
203 mutable int m_planeSide[6];
204 mutable Eigen::VectorXd m_forces;
205 mutable Eigen::VectorXd m_interForces;
206
207 ISignalPort* m_inBoxPos;
208 ISignalPort* m_inBoxRot;
211
212 mutable double m_outForce[3];
213 mutable double m_time;
214
215
216#ifdef FH_VISUALIZATION
217 std::string m_material;
218 std::string m_meshName;
219 double m_scale;
220 Ogre::SceneManager* m_sceneMgr;
221 std::vector<Ogre::SceneNode*> m_renderNodes;
222 std::vector<Ogre::Entity*> m_renderEntities;
223#endif
224};
225
226#endif
Definition CBall.h:101
Eigen::VectorXd m_interForces
3-DOF force acting on each ball i (col(F_i)) from the box. [N]
Definition CBall.h:205
void CalcForces(const double T, const double *const X) const
Calculates contact forces between balls and box.
void OdeFcn(const double T, const double *const X, double *const XDot) const
Cleans up dynamically allocated memory.
virtual const double * Velocity(const double T, const double *const X)
Returns the position of the balls.
void ForceInterBall(const double T, const double *const X) const
Calculates contact forces between the balls.
const double * ForceOut(const double T, const double *const X)
Returns the force acting from the balls on the box.
CBall(std::string simObjectName, ISimObjectCreator *creator)
Reads parameters, registers states, input/output ports and shared resources.
int m_iStatePos
Orientation of the box, Euler angles, x,y,z [rad].
Definition CBall.h:209
Eigen::VectorXd m_forces
Side of the plane, relative normal std::vector (-1: inside, 1: outside, else: undef)
Definition CBall.h:204
double m_time
The force acting on the box. [N].
Definition CBall.h:213
double m_outForce[3]
The index of the velocity state.
Definition CBall.h:212
ISignalPort * m_inBoxPos
3-DOF force acting between each ball i (col(F_i)). [N]
Definition CBall.h:207
double * m_radius
The masses of the balls. [kg].
Definition CBall.h:199
double m_gravity
Number of balls [#].
Definition CBall.h:197
Eigen::Vector3d m_norms[6]
The dimensions of the box Lx, Ly, Lz [m].
Definition CBall.h:202
double * m_mass
The gravity (assumed along z-axis) [kgms^-2].
Definition CBall.h:198
double m_boxDim[3]
The linear stiffnesses of the ball. [N/m].
Definition CBall.h:201
int m_planeSide[6]
Array of box unit normal vectors [-].
Definition CBall.h:203
double * m_stiffness
The radii of the balls. [m].
Definition CBall.h:200
int m_iStateVel
The index of the position state.
Definition CBall.h:210
ISignalPort * m_inBoxRot
Centroid of the box [m].
Definition CBall.h:208
virtual const double * Position(const double T, const double *const X)
Returns the velocity of the balls.