RigidRepresentationBase.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_PHYSICS_RIGIDREPRESENTATIONBASE_H
17 #define SURGSIM_PHYSICS_RIGIDREPRESENTATIONBASE_H
18 
20 #include "SurgSim/Math/Shape.h"
23 
24 namespace SurgSim
25 {
26 
27 namespace Collision
28 {
29 class Representation;
30 }
31 
32 namespace Physics
33 {
34 class Localization;
35 
39 {
40 public:
43  explicit RigidRepresentationBase(const std::string& name);
44 
46  virtual ~RigidRepresentationBase();
47 
51  void setInitialState(const RigidRepresentationState& state);
53  void resetState();
54 
64 
65  std::shared_ptr<Localization> createLocalization(const SurgSim::DataStructures::Location& location);
66 
69  void setDensity(double rho);
70 
73  double getDensity() const;
74 
77  double getMass() const;
78 
82 
86 
89  void setLinearDamping(double linearDamping);
90 
93  double getLinearDamping() const;
94 
97  void setAngularDamping(double angularDamping);
98 
101  double getAngularDamping() const;
102 
106  void setShape(const std::shared_ptr<SurgSim::Math::Shape> shape);
107 
110  const std::shared_ptr<SurgSim::Math::Shape> getShape() const;
111 
117  virtual void setCollisionRepresentation(
118  std::shared_ptr<SurgSim::Collision::Representation> representation) override;
119 
120  virtual void beforeUpdate(double dt) override;
121  virtual void afterUpdate(double dt) override;
122 
123 protected:
124  virtual bool doInitialize() override;
125  virtual bool doWakeUp() override;
126 
135 
138 
140  double m_rho;
141 
143  double m_mass;
144 
147 
150 
153 
156 
158  std::shared_ptr<SurgSim::Math::Shape> m_shape;
159 
164  template <class T>
165  std::shared_ptr<T> createTypedLocalization(const SurgSim::DataStructures::Location& location);
166 
167 private:
169  void updateProperties();
170 
171  virtual void updateGlobalInertiaMatrices(const RigidRepresentationState& state) = 0;
172 };
173 
174 }; // Physics
175 }; // SurgSim
176 
178 
179 #endif // SURGSIM_PHYSICS_RIGIDREPRESENTATIONBASE_H
double m_angularDamping
Angular damping parameter (in N.m.s.rad-1)
Definition: RigidRepresentationBase.h:149
virtual ~RigidRepresentationBase()
Destructor.
Definition: RigidRepresentationBase.cpp:60
virtual void setCollisionRepresentation(std::shared_ptr< SurgSim::Collision::Representation > representation) override
Set the collision representation for this physics representation, when the collision object is involv...
Definition: RigidRepresentationBase.cpp:216
Definition: DriveElementFromInputBehavior.cpp:27
RigidRepresentationBase(const std::string &name)
Constructor.
Definition: RigidRepresentationBase.cpp:35
std::shared_ptr< SurgSim::Math::Shape > m_shape
Shape to be used for the mass/inertia calculation.
Definition: RigidRepresentationBase.h:158
void updateProperties()
Updates mass, mass center and inertia when density and/or shape used for mass inertia is updated...
Definition: RigidRepresentationBase.cpp:187
RigidRepresentationState m_finalState
Last valid/final rigid representation state.
Definition: RigidRepresentationBase.h:134
const SurgSim::Math::Vector3d & getMassCenter() const
Get the mass center of the rigid body.
Definition: RigidRepresentationBase.cpp:143
void setInitialState(const RigidRepresentationState &state)
Set the initial state of the rigid representation.
Definition: RigidRepresentationBase.cpp:86
SurgSim::Math::Matrix33d m_localInertia
Inertia matrix in local coordinates.
Definition: RigidRepresentationBase.h:155
The Representation class defines the base class for all physics objects.
Definition: Representation.h:56
Definition: Location.h:31
void setLinearDamping(double linearDamping)
Set the linear damping parameter.
Definition: RigidRepresentationBase.cpp:153
void resetState()
Reset the rigid representation state to its initial state.
Definition: RigidRepresentationBase.cpp:95
RigidRepresentationState m_initialState
Initial rigid representation state (useful for reset)
Definition: RigidRepresentationBase.h:128
double getLinearDamping() const
Get the linear damping parameter.
Definition: RigidRepresentationBase.cpp:158
void setShape(const std::shared_ptr< SurgSim::Math::Shape > shape)
Set the shape to use internally for physical parameters computation.
Definition: RigidRepresentationBase.cpp:173
std::shared_ptr< Localization > createLocalization(const SurgSim::DataStructures::Location &location)
Computes a localized coordinate w.r.t this representation, given a Location object.
Definition: RigidRepresentationBase.cpp:121
The RigidRepresentationBase class defines the base class for all rigid motion based representations (...
Definition: RigidRepresentationBase.h:38
double getMass() const
Get the mass of the rigid body.
Definition: RigidRepresentationBase.cpp:138
double m_mass
Total mass of the object (in Kg)
Definition: RigidRepresentationBase.h:143
virtual bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: RigidRepresentationBase.cpp:75
const SurgSim::Math::Matrix33d & getLocalInertia() const
Get the local inertia 3x3 matrix of the rigid body.
Definition: RigidRepresentationBase.cpp:148
double m_rho
Density of the object (in Kg.m-3)
Definition: RigidRepresentationBase.h:140
RigidRepresentationState m_currentState
Current rigid representation state.
Definition: RigidRepresentationBase.h:132
bool m_parametersValid
Validity of the parameters.
Definition: RigidRepresentationBase.h:137
std::shared_ptr< T > createTypedLocalization(const SurgSim::DataStructures::Location &location)
Creates typed localization.
Definition: RigidRepresentationBase-inl.h:26
const RigidRepresentationState & getCurrentState() const
Get the current state of the rigid representation.
Definition: RigidRepresentationBase.cpp:111
double m_linearDamping
Linear damping parameter (in N.s.m-1 or Kg.s-1)
Definition: RigidRepresentationBase.h:146
SurgSim::Math::Vector3d m_massCenter
Mass-center of the object.
Definition: RigidRepresentationBase.h:152
const RigidRepresentationState & getPreviousState() const
Get the previous state of the rigid representation.
Definition: RigidRepresentationBase.cpp:116
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
virtual void beforeUpdate(double dt) override
Preprocessing done before the update call This needs to be called from the outside usually from a Com...
Definition: RigidRepresentationBase.cpp:205
const std::shared_ptr< SurgSim::Math::Shape > getShape() const
Get the shape used internally for physical parameters computation.
Definition: RigidRepresentationBase.cpp:182
double getAngularDamping() const
Get the angular damping parameter.
Definition: RigidRepresentationBase.cpp:168
const RigidRepresentationState & getInitialState() const
Get the initial state of the rigid representation.
Definition: RigidRepresentationBase.cpp:106
void setDensity(double rho)
Set the mass density of the rigid representation.
Definition: RigidRepresentationBase.cpp:127
virtual bool doInitialize() override
Interface to be implemented by derived classes.
Definition: RigidRepresentationBase.cpp:64
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:56
double getDensity() const
Get the mass density of the rigid representation.
Definition: RigidRepresentationBase.cpp:133
The RigidRepresentationState class describes a state (position and velocity information).
Definition: RigidRepresentationState.h:31
virtual void updateGlobalInertiaMatrices(const RigidRepresentationState &state)=0
void setAngularDamping(double angularDamping)
Set the angular damping parameter.
Definition: RigidRepresentationBase.cpp:163
RigidRepresentationState m_previousState
Previous rigid representation state.
Definition: RigidRepresentationBase.h:130
virtual void afterUpdate(double dt) override
Postprocessing done after the update call This needs to be called from the outside usually from a Com...
Definition: RigidRepresentationBase.cpp:210