opensurgsim
RigidRepresentation.h
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_RIGIDREPRESENTATION_H
17 #define SURGSIM_PHYSICS_RIGIDREPRESENTATION_H
18 
19 #include "SurgSim/DataStructures/BufferedValue.h"
20 #include "SurgSim/Framework/Macros.h"
21 #include "SurgSim/Framework/ObjectFactory.h"
22 #include "SurgSim/Math/Vector.h"
23 #include "SurgSim/Math/Matrix.h"
24 #include "SurgSim/Physics/RigidRepresentationBase.h"
25 
26 namespace SurgSim
27 {
28 
29 namespace Physics
30 {
31 class RigidState;
32 class Localization;
33 
34 typedef RigidLocalization RigidLocalization;
35 
36 SURGSIM_STATIC_REGISTRATION(RigidRepresentation);
37 
43 {
44 public:
47  explicit RigidRepresentation(const std::string& name);
48 
50  virtual ~RigidRepresentation();
51 
52  SURGSIM_CLASSNAME(SurgSim::Physics::RigidRepresentation);
53 
56  void setLinearVelocity(const SurgSim::Math::Vector3d& linearVelocity);
57 
60  void setAngularVelocity(const SurgSim::Math::Vector3d& angularVelocity);
61 
69  void addExternalGeneralizedForce(const SurgSim::Math::Vector6d& generalizedForce,
70  const SurgSim::Math::Matrix66d& K = SurgSim::Math::Matrix66d::Zero(),
71  const SurgSim::Math::Matrix66d& D = SurgSim::Math::Matrix66d::Zero());
72 
82  const SurgSim::Math::Vector6d& generalizedForce,
83  const SurgSim::Math::Matrix66d& K = SurgSim::Math::Matrix66d::Zero(),
84  const SurgSim::Math::Matrix66d& D = SurgSim::Math::Matrix66d::Zero());
85 
88 
91 
94 
95  void beforeUpdate(double dt) override;
96 
97  void update(double dt) override;
98 
99  void afterUpdate(double dt) override;
100 
101  void applyCorrection(double dt, const Eigen::VectorBlock<SurgSim::Math::Vector>& deltaVelocity) override;
102 
106 
107 protected:
112 
117 
120 
125  SurgSim::Math::Matrix66d m_externalGeneralizedStiffness;
126  SurgSim::Math::Matrix66d m_externalGeneralizedDamping;
128 
129 private:
130  bool doInitialize() override;
131 
134  void computeComplianceMatrix(double dt);
135 
138  void updateGlobalInertiaMatrices(const RigidState& state) override;
139 };
140 
141 }; // Physics
142 }; // SurgSim
143 
144 #endif // SURGSIM_PHYSICS_RIGIDREPRESENTATION_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
virtual ~RigidRepresentation()
Destructor.
Definition: RigidRepresentation.cpp:53
RigidRepresentation(const std::string &name)
Constructor.
Definition: RigidRepresentation.cpp:36
Eigen::Matrix< double, 6, 1 > Vector6d
A 6D matrix of doubles.
Definition: Vector.h:65
const SurgSim::Math::Matrix66d & getExternalGeneralizedDamping() const
Definition: RigidRepresentation.cpp:191
SurgSim::Math::Matrix33d m_globalInertia
Inertia matrices in global coordinates.
Definition: RigidRepresentation.h:109
A Location defines a local position w.r.t.
Definition: Location.h:39
SurgSim::DataStructures::BufferedValue< SurgSim::Math::Vector6d > & getExternalGeneralizedForce()
Definition: RigidRepresentation.cpp:181
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
The RigidRepresentation class defines the dynamic rigid body representation Note that the rigid repre...
Definition: RigidRepresentation.h:42
bool m_hasExternalGeneralizedForce
External generalized force, stiffness and damping applied on the rigid representation.
Definition: RigidRepresentation.h:123
The RigidRepresentationBase class defines the base class for all rigid motion based representations (...
Definition: RigidRepresentationBase.h:38
void setAngularVelocity(const SurgSim::Math::Vector3d &angularVelocity)
Set the current angular velocity of the rigid representation.
Definition: RigidRepresentation.cpp:470
The RigidState class describes a state (position and velocity information).
Definition: RigidState.h:31
Eigen::Matrix< double, 6, 6, Eigen::RowMajor > Matrix66d
A 6x6 matrix of doubles.
Definition: Matrix.h:59
SurgSim::Math::Vector3d m_force
Current force applied on the rigid representation (in N)
Definition: RigidRepresentation.h:114
SurgSim::Math::Matrix66d m_C
Compliance matrix (size of the number of Dof = 6)
Definition: RigidRepresentation.h:119
void setLinearVelocity(const SurgSim::Math::Vector3d &linearVelocity)
Set the current linear velocity of the rigid representation.
Definition: RigidRepresentation.cpp:465
Definitions of small fixed-size square matrix types.
SurgSim::Math::Matrix33d m_invGlobalInertia
Inverse of inertia matrix in global coordinates.
Definition: RigidRepresentation.h:111
Definitions of small fixed-size vector types.
void addExternalGeneralizedForce(const SurgSim::Math::Vector6d &generalizedForce, const SurgSim::Math::Matrix66d &K=SurgSim::Math::Matrix66d::Zero(), const SurgSim::Math::Matrix66d &D=SurgSim::Math::Matrix66d::Zero())
Add an external generalized force applied to the rigid representation&#39;s mass center.
Definition: RigidRepresentation.cpp:57
void afterUpdate(double dt) override
Postprocessing done after the update call This needs to be called from the outside usually from a Com...
Definition: RigidRepresentation.cpp:314
void beforeUpdate(double dt) override
Preprocessing done before the update call This needs to be called from the outside usually from a Com...
Definition: RigidRepresentation.cpp:196
SurgSim::Math::Vector3d m_torque
Current torque applied on the rigid representation (in N.m)
Definition: RigidRepresentation.h:116
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
void applyCorrection(double dt, const Eigen::VectorBlock< SurgSim::Math::Vector > &deltaVelocity) override
Update the Representation&#39;s current position and velocity using a time interval, dt, and change in velocity, deltaVelocity.
Definition: RigidRepresentation.cpp:338
const SurgSim::Math::Matrix66d & getComplianceMatrix() const
Retrieve the rigid body 6x6 compliance matrix.
Definition: RigidRepresentation.cpp:404
const SurgSim::Math::Matrix66d & getExternalGeneralizedStiffness() const
Definition: RigidRepresentation.cpp:186
void update(double dt) override
Update the representation state to the current time step.
Definition: RigidRepresentation.cpp:210