iMSTK
Interactive Medical Simulation Toolkit
imstkPbdObjectController.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 PbdObject;
14 
27 {
28 public:
29  PbdObjectController(const std::string& name = "PbdObjectController") : SceneObjectController(name) { }
30  ~PbdObjectController() override = default;
31 
32 public:
33  void setControlledObject(std::shared_ptr<SceneObject> obj) override;
34 
38  double getLinearKd() const { return m_linearKd; }
39  void setLinearKd(const double kd) { m_linearKd = kd; }
41 
45  double getAngularKd() const { return m_angularKd; }
46  void setAngularKd(const double kd) { m_angularKd = kd; }
48 
52  const Vec3d& getLinearKs() const { return m_linearKs; }
53  void setLinearKs(const Vec3d& ks) { m_linearKs = ks; }
54  void setLinearKs(const double ks) { m_linearKs = Vec3d(ks, ks, ks); }
56 
60  const Vec3d& getAngularKs() const { return m_angularKs; }
61  void setAngularKs(const Vec3d& ks) { m_angularKs = ks; }
62  void setAngularKs(const double ks) { m_angularKs = Vec3d(ks, ks, ks); }
64 
68  double getForceScaling() const { return m_forceScaling; }
69  void setForceScaling(const double forceScaling) { m_forceScaling = forceScaling; }
71 
75  bool getUseSpring() const { return m_useSpring; }
76  void setUseSpring(const bool useSpring) { m_useSpring = useSpring; }
78 
83  bool getUseForceSmoothening() const { return m_forceSmoothening; }
84  void setUseForceSmoothening(const bool useForceSmoothening) { m_forceSmoothening = useForceSmoothening; }
86 
92  bool getUseCritDamping() const { return m_useCriticalDamping; }
93  void setUseCritDamping(const bool useCritDamping) { m_useCriticalDamping = useCritDamping; }
95 
100  int getSmoothingKernelSize() const { return m_smoothingKernelSize; }
101  void setSmoothingKernelSize(const int kernelSize) { m_smoothingKernelSize = kernelSize; }
103 
109  Vec3d getHapticOffset() const { return m_hapticOffset; }
110  void setHapticOffset(const Vec3d& offset) { m_hapticOffset = offset; }
112 
116  Vec3d getDeviceForce() const { return (m_fS + m_fD) * m_forceScaling; }
117 
121  Vec3d getSpringForce() const { return m_fS; }
122 
126  Vec3d getDamperForce() const { return m_fD; }
127 
131  Vec3d getDeviceTorque() const { return m_tS + m_tD; }
132 
136  Vec3d getSpringTorque() const { return m_tS; }
137 
141  Vec3d getDamperTorque() const { return m_tD; }
142 
143 public:
147  void update(const double& dt) override;
148 
152  void applyForces() override;
153 
154 protected:
155  std::shared_ptr<PbdObject> m_pbdObject;
156 
157  double m_linearKd = 10000.0;
158  double m_angularKd = 300.0;
159  Vec3d m_linearKs = Vec3d(8000000.0, 8000000.0, 8000000.0);
160  Vec3d m_angularKs = Vec3d(10000.0, 10000.0, 10000.0);
161 
162  // Linear spring force and damper force
163  Vec3d m_fS = Vec3d::Zero();
164  Vec3d m_fD = Vec3d::Zero();
165 
166  // Angular spring force and damper force
167  Vec3d m_tS = Vec3d::Zero();
168  Vec3d m_tD = Vec3d::Zero();
169 
170  Vec3d m_hapticOffset = Vec3d::Zero();
171  double m_forceScaling = 0.0000075;
172  bool m_useSpring = true;
173  bool m_useCriticalDamping = true;
174  Vec3d m_inversionParams = Vec3d(1.0, 1.0, 1.0);
175 
176  bool m_forceSmoothening = true;
177  int m_smoothingKernelSize = 15;
178  std::deque<Vec3d> m_forces;
179  Vec3d m_forceSum = Vec3d::Zero();
180 
181  // Flag for initialization position during first call
182  bool m_firstRun = true;
183 };
184 } // namespace imstk
bool m_useSpring
If off, pos & orientation directly set.
int getSmoothingKernelSize() const
Set/Get the kernel size.
void applyForces() override
Apply forces to the haptic device.
Vec3d m_angularKs
Spring coefficient, rotational.
This class uses the provided device to control the provided rigid object via virtual coupling...
Vec3d getDeviceTorque() const
Return the device applied torque (scaled)
Compound Geometry.
double m_angularKd
Damping coefficient, rotational.
double getLinearKd() const
Set/Get the linear damping coefficient. Default 10000.0.
bool getUseCritDamping() const
Set/Get whether to use critical damping (default on) Critical damping automatically computes linear &...
void update(const double &dt) override
Update controlled scene object using latest tracking information.
double getAngularKd() const
Set/Get the angular damping coefficient. Default 10000.0.
Vec3d getDeviceForce() const
Return the device applied force (scaled)
Vec3d getDamperForce() const
Returns damper force.
This class implements once tracking controller controlling one scene object.
bool getUseSpring() const
Set/Get whether to use spring or not.
const Vec3d & getAngularKs() const
Set/Get the rotationl spring coefficient. Default (10000.0, 10000.0, 10000.0)
double m_linearKd
Damping coefficient, linear.
Vec3d getDamperTorque() const
Returns damper torque.
bool m_useCriticalDamping
If on, kd is automatically computed.
bool getUseForceSmoothening() const
Set/Get whether to use force smoothening Force smoothening averages the force used on the device over...
Vec3d m_inversionParams
Inversion parameters for each axis.
double getForceScaling() const
Set/Get the scaling of the force on the device, set to 0 for no force.
Vec3d getSpringForce() const
Returns spring force, without damper.
Vec3d getSpringTorque() const
Returns spring torque, without damper.
Vec3d m_linearKs
Spring coefficient, linear.
const Vec3d & getLinearKs() const
Set/Get the linear spring coefficient. Default (8000000.0, 8000000.0, 8000000.0)
Vec3d getHapticOffset() const
Set/Get the haptic manipuladum offset. This is a local offset on the object for which haptics are fel...