iMSTK
Interactive Medical Simulation Toolkit
imstkRigidObjectController.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkSceneObjectController.h"
10 
11 namespace imstk
12 {
13 class RigidObject2;
14 
26 {
27 public:
28  RigidObjectController(const std::string& name = "RigidObjectController") : SceneObjectController(name) { }
29  ~RigidObjectController() override = default;
30 
31  void setControlledObject(std::shared_ptr<SceneObject> obj) override;
32 
36  double getLinearKd() const { return m_linearKd; }
37  void setLinearKd(const double kd) { m_linearKd = kd; }
39 
43  double getAngularKd() const { return m_angularKd; }
44  void setAngularKd(const double kd) { m_angularKd = kd; }
46 
50  const Vec3d& getLinearKs() const { return m_linearKs; }
51  void setLinearKs(const Vec3d& ks) { m_linearKs = ks; }
52  void setLinearKs(const double ks) { m_linearKs = Vec3d(ks, ks, ks); }
54 
58  const Vec3d& getAngularKs() const { return m_angularKs; }
59  void setAngularKs(const Vec3d& ks) { m_angularKs = ks; }
60  void setAngularKs(const double ks) { m_angularKs = Vec3d(ks, ks, ks); }
62 
66  double getForceScaling() const { return m_forceScaling; }
67  void setForceScaling(const double forceScaling) { m_forceScaling = forceScaling; }
69 
73  bool getUseSpring() const { return m_useSpring; }
74  void setUseSpring(const bool useSpring) { m_useSpring = useSpring; }
76 
81  bool getUseForceSmoothening() const { return m_forceSmoothening; }
82  void setUseForceSmoothening(const bool useForceSmoothening) { m_forceSmoothening = useForceSmoothening; }
84 
90  bool getUseCritDamping() const { return m_useCriticalDamping; }
91  void setUseCritDamping(const bool useCritDamping) { m_useCriticalDamping = useCritDamping; }
93 
98  int getSmoothingKernelSize() const { return m_smoothingKernelSize; }
99  void setSmoothingKernelSize(const int kernelSize) { m_smoothingKernelSize = kernelSize; }
101 
105  Vec3d getDeviceForce() const { return (m_fS + m_fD) * m_forceScaling; }
106 
110  Vec3d getSpringForce() const { return m_fS; }
111 
115  Vec3d getDamperForce() const { return m_fD; }
116 
120  Vec3d getDeviceTorque() const { return m_tS + m_tD; }
121 
125  Vec3d getSpringTorque() const { return m_tS; }
126 
130  Vec3d getDamperTorque() const { return m_tD; }
131 
132 public:
136  void update(const double& dt) override;
137 
141  void applyForces() override;
142 
143 protected:
144  std::shared_ptr<RigidObject2> m_rigidObject;
145 
146  double m_linearKd = 10000.0;
147  double m_angularKd = 300.0;
148  Vec3d m_linearKs = Vec3d(8000000.0, 8000000.0, 8000000.0);
149  Vec3d m_angularKs = Vec3d(10000.0, 10000.0, 10000.0);
150 
151  // Linear spring force and damper force
152  Vec3d m_fS = Vec3d::Zero();
153  Vec3d m_fD = Vec3d::Zero();
154 
155  // Angular spring force and damper force
156  Vec3d m_tS = Vec3d::Zero();
157  Vec3d m_tD = Vec3d::Zero();
158 
159  double m_forceScaling = 0.0000075;
160  bool m_useSpring = true;
161  bool m_useCriticalDamping = true;
162 
163  bool m_forceSmoothening = true;
164  int m_smoothingKernelSize = 15;
165  std::deque<Vec3d> m_forces;
166  Vec3d m_forceSum = Vec3d::Zero();
167 };
168 } // namespace imstk
double m_angularKd
Damping coefficient, rotational.
Vec3d getDamperForce() const
Returns damper force.
bool m_useCriticalDamping
If on, kd is automatically computed.
bool m_useSpring
If off, pos & orientation directly set.
double getForceScaling() const
Set/Get the scaling of the force on the device, set to 0 for no force.
bool getUseCritDamping() const
Set/Get whether to use critical damping (default on) Critical damping automatically computes linear &...
Vec3d getSpringTorque() const
Returns spring torque, without damper.
double m_linearKd
Damping coefficient, linear.
const Vec3d & getAngularKs() const
Set/Get the rotationl spring coefficient. Default (10000.0, 10000.0, 10000.0)
Vec3d getSpringForce() const
Returns spring force, without damper.
Compound Geometry.
double getAngularKd() const
Set/Get the angular damping coefficient. Default 10000.0.
This class implements once tracking controller controlling one scene object.
const Vec3d & getLinearKs() const
Set/Get the linear spring coefficient. Default (8000000.0, 8000000.0, 8000000.0)
double getLinearKd() const
Set/Get the linear damping coefficient. Default 10000.0.
This class uses the provided device to control the provided rigid object via virtual coupling...
bool getUseSpring() const
Set/Get whether to use spring or not.
void applyForces() override
Apply forces to the haptic device.
int getSmoothingKernelSize() const
Set/Get the kernel size.
Vec3d m_angularKs
Spring coefficient, rotational.
void update(const double &dt) override
Update controlled scene object using latest tracking information.
Vec3d getDeviceTorque() const
Return the device applied torque (scaled)
Vec3d getDamperTorque() const
Returns damper torque.
Vec3d getDeviceForce() const
Return the device applied force (scaled)
bool getUseForceSmoothening() const
Set/Get whether to use force smoothening Force smoothening averages the force used on the device over...
Vec3d m_linearKs
Spring coefficient, linear.