iMSTK
Interactive Medical Simulation Toolkit
Public Member Functions | Protected Attributes | List of all members
imstk::PbdObjectController Class Reference

This class uses the provided device to control the provided rigid object via virtual coupling. That is, it applies forces+torques to the rigid body that will help move it to desired position/orientation. It has linear and angular spring scales as well as damping You may also use force smoothening for the force applied back on the device. More...

#include <imstkPbdObjectController.h>

Inheritance diagram for imstk::PbdObjectController:
Inheritance graph
[legend]
Collaboration diagram for imstk::PbdObjectController:
Collaboration graph
[legend]

Public Member Functions

 PbdObjectController (const std::string &name="PbdObjectController")
 
void setControlledObject (std::shared_ptr< SceneObject > obj) override
 
double getLinearKd () const
 Set/Get the linear damping coefficient. Default 10000.0.
 
void setLinearKd (const double kd)
 
Vec3d getDeviceForce () const
 Return the device applied force (scaled)
 
Vec3d getSpringForce () const
 Returns spring force, without damper.
 
Vec3d getDamperForce () const
 Returns damper force.
 
Vec3d getDeviceTorque () const
 Return the device applied torque (scaled)
 
Vec3d getSpringTorque () const
 Returns spring torque, without damper.
 
Vec3d getDamperTorque () const
 Returns damper torque.
 
void update (const double &dt) override
 Update controlled scene object using latest tracking information. More...
 
void applyForces () override
 Apply forces to the haptic device.
 
double getAngularKd () const
 Set/Get the angular damping coefficient. Default 10000.0.
 
void setAngularKd (const double kd)
 
const Vec3d & getLinearKs () const
 Set/Get the linear spring coefficient. Default (8000000.0, 8000000.0, 8000000.0)
 
void setLinearKs (const Vec3d &ks)
 
void setLinearKs (const double ks)
 
const Vec3d & getAngularKs () const
 Set/Get the rotationl spring coefficient. Default (10000.0, 10000.0, 10000.0)
 
void setAngularKs (const Vec3d &ks)
 
void setAngularKs (const double ks)
 
double getForceScaling () const
 Set/Get the scaling of the force on the device, set to 0 for no force.
 
void setForceScaling (const double forceScaling)
 
bool getUseSpring () const
 Set/Get whether to use spring or not.
 
void setUseSpring (const bool useSpring)
 
bool getUseForceSmoothening () const
 Set/Get whether to use force smoothening Force smoothening averages the force used on the device over kernel size.
 
void setUseForceSmoothening (const bool useForceSmoothening)
 
bool getUseCritDamping () const
 Set/Get whether to use critical damping (default on) Critical damping automatically computes linear & angular kd values. It may be turned off as it is sometimes useful to overdamp depending on other factors.
 
void setUseCritDamping (const bool useCritDamping)
 
int getSmoothingKernelSize () const
 Set/Get the kernel size. More...
 
void setSmoothingKernelSize (const int kernelSize)
 
Vec3d getHapticOffset () const
 Set/Get the haptic manipuladum offset. This is a local offset on the object for which haptics are felt and force is exerted on the body. By default this is the center of mass of the object.
 
void setHapticOffset (const Vec3d &offset)
 
- Public Member Functions inherited from imstk::SceneObjectController
 SceneObjectController (const std::string &name="SceneObjectController")
 
void update (const double &dt) override
 Update controlled scene object using latest tracking information.
 
std::shared_ptr< SceneObjectgetControlledObject () const
 Get/Set controlled scene object.
 
- Public Member Functions inherited from imstk::TrackingDeviceControl
const Quatd & getEffectorRotationOffset ()
 Get/Set the roation applied to the end effector, this can be used to register the device in virtual space with regard to the users point of view.
 
void setEffectorRotationOffset (const Quatd &r)
 
virtual bool updateTrackingData (const double dt)
 Update tracking data.
 
const Vec3d & getPosition () const
 Set/Get the position of the tracker.
 
void setPosition (const Vec3d &pos)
 
const Quatd & getOrientation () const
 Set/Get the orientation of the tracker.
 
void setOrientation (const Quatd &orientation)
 
void setComputeVelocity (const bool computeVelocity)
 Set/Get whether to compute the velocity from previous and current samples Useful if a device does not provide the quantity.
 
bool getComputeVelocity () const
 
void setComputeAngularVelocity (const bool computeAngularVelocity)
 Set/Get whether to compute the anular velocity from previous and current samples Useful if the device does not provide the quantity.
 
bool getComputeAngularVelocity () const
 
const Vec3d & getAngularVelocity () const
 Get/Set the angular velocity.
 
void setAngularVelocity (const Vec3d &angularVelocity)
 
const Vec3d & getVelocity () const
 Get/Set the linear velocity.
 
void setVelocity (const Vec3d &velocity)
 
double getTranslationScaling () const
 Get/Set the current scaling factor.
 
void setTranslationScaling (const double scaling)
 
const Vec3d & getTranslationOffset () const
 Get/Set the translation offset.
 
void setTranslationOffset (const Vec3d &t)
 
const Quatd & getRotationOffset ()
 Get/Set the rotation offset, this rotation is applied to the overall device coordinate system.
 
void setRotationOffset (const Quatd &r)
 
unsigned char getInversionFlags ()
 Get/Set the inversion flags, when set the corresponding axis coordinates or rotation angle will be negated.
 
void setInversionFlags (const unsigned char f)
 
- Public Member Functions inherited from imstk::DeviceControl
 SIGNAL (DeviceControl, modified)
 
virtual void printControls ()
 Prints the controls.
 
std::shared_ptr< DeviceClientgetDevice () const
 Set/Get the device client used in the control.
 
virtual void setDevice (std::shared_ptr< DeviceClient > device)
 
- Public Member Functions inherited from imstk::Behaviour< UpdateInfo >
virtual void update (const UpdateInfo &imstkNotUsed(updateData))
 
virtual void visualUpdate (const UpdateInfo &imstkNotUsed(updateData))
 
void initTaskGraphEdges ()
 Setup the edges/connections of the TaskGraph.
 
std::shared_ptr< TaskGraphgetTaskGraph () const
 
- Public Member Functions inherited from imstk::Component
const std::string & getName () const
 
void setName (const std::string &name)
 
std::weak_ptr< EntitygetEntity () const
 Get parent entity.
 
void initialize ()
 Initialize the component, called at a later time after all component construction is complete.
 
- Public Member Functions inherited from imstk::EventObject
template<typename T >
void postEvent (const T &e)
 Emits the event Direct observers will be immediately called, in sync Queued observers will receive the Command in their queue for later execution, reciever must implement doEvent.
 
template<typename T >
void queueEvent (const T &e)
 Queues event directly to this.
 
void doEvent ()
 Do an event, if none exists return.
 
void doAllEvents ()
 Do all the events in the event queue.
 
void foreachEvent (std::function< void(Command cmd)> func)
 Thread safe loop over all event commands, one can implement a custom handler.
 
void rforeachEvent (std::function< void(Command cmd)> func)
 thread safe reverse loop over all event commands, one can implement a custom handler
 
void clearEvents ()
 Removes all events from queue cleans up copies of the event.
 

Protected Attributes

std::shared_ptr< PbdObjectm_pbdObject
 
double m_linearKd = 10000.0
 Damping coefficient, linear.
 
double m_angularKd = 300.0
 Damping coefficient, rotational.
 
Vec3d m_linearKs = Vec3d(8000000.0, 8000000.0, 8000000.0)
 Spring coefficient, linear.
 
Vec3d m_angularKs = Vec3d(10000.0, 10000.0, 10000.0)
 Spring coefficient, rotational.
 
Vec3d m_fS = Vec3d::Zero()
 
Vec3d m_fD = Vec3d::Zero()
 
Vec3d m_tS = Vec3d::Zero()
 
Vec3d m_tD = Vec3d::Zero()
 
Vec3d m_hapticOffset = Vec3d::Zero()
 
double m_forceScaling = 0.0000075
 
bool m_useSpring = true
 If off, pos & orientation directly set.
 
bool m_useCriticalDamping = true
 If on, kd is automatically computed.
 
Vec3d m_inversionParams = Vec3d(1.0, 1.0, 1.0)
 Inversion parameters for each axis.
 
bool m_forceSmoothening = true
 
int m_smoothingKernelSize = 15
 
std::deque< Vec3d > m_forces
 
Vec3d m_forceSum = Vec3d::Zero()
 
bool m_firstRun = true
 
- Protected Attributes inherited from imstk::SceneObjectController
std::shared_ptr< SceneObjectm_sceneObject
 SceneObject controlled by the Tracker.
 
- Protected Attributes inherited from imstk::TrackingDeviceControl
double m_scaling = 1.0
 Scaling factor for physical to virtual translations.
 
Vec3d m_translationOffset = Vec3d::Zero()
 Translation concatenated to the device translation.
 
Quatd m_rotationOffset = Quatd::Identity()
 Rotation concatenated to the device rotation.
 
Quatd m_effectorRotationOffset = Quatd::Identity()
 Rotation prefixed to the device rotation.
 
unsigned char m_invertFlags = 0x00
 Invert flags to be masked with DeviceTracker::InvertFlag.
 
Vec3d m_currentPos = Vec3d::Zero()
 
Quatd m_currentOrientation = Quatd::Identity()
 
Vec3d m_currentVelocity = Vec3d::Zero()
 
Vec3d m_currentAngularVelocity = Vec3d::Zero()
 
Vec3d m_currentDisplacement = Vec3d::Zero()
 
Quatd m_currentRotation = Quatd::Identity()
 
bool m_computeVelocity = false
 If true, will use current and previous positions to produce velocity, if off, will ask device for velocity.
 
bool m_computeAngularVelocity = false
 If true, will use current and previous rotations to produce angular velocity, if off, will ask device for angular velocity.
 
- Protected Attributes inherited from imstk::DeviceControl
std::shared_ptr< DeviceClientm_deviceClient
 
- Protected Attributes inherited from imstk::Behaviour< UpdateInfo >
std::shared_ptr< TaskGraphm_taskGraph = nullptr
 
- Protected Attributes inherited from imstk::Component
std::string m_name
 
std::weak_ptr< Entitym_entity
 Parent entity this component exists on.
 
- Protected Attributes inherited from imstk::EventObject
ParallelUtils::SpinLock eventQueueLock
 
std::deque< CommandeventQueue
 
std::vector< std::pair< std::string, std::vector< Observer > > > queuedObservers
 
std::vector< std::pair< std::string, std::vector< Observer > > > directObservers
 

Additional Inherited Members

- Public Types inherited from imstk::TrackingDeviceControl
enum  InvertFlag {
  transX = 0x01, transY = 0x02, transZ = 0x04, rotX = 0x08,
  rotY = 0x10, rotZ = 0x20
}
 
- Public Types inherited from imstk::EventObject
using Observer = std::tuple< bool, std::weak_ptr< EventObject >, std::function< void(Event *)> >
 
- Protected Member Functions inherited from imstk::TrackingDeviceControl
 TrackingDeviceControl (const std::string &name="TrackingDeviceControl")
 
- Protected Member Functions inherited from imstk::DeviceControl
 DeviceControl (const std::string &name="DeviceControl")
 
- Protected Member Functions inherited from imstk::Behaviour< UpdateInfo >
 Behaviour (const std::string &name="Behaviour")
 
 Behaviour (const bool useTaskGraph, const std::string &name="Behaviour")
 
virtual void initGraphEdges (std::shared_ptr< TaskNode > imstkNotUsed(source), std::shared_ptr< TaskNode > imstkNotUsed(sink))
 Setup the edges/connections of the TaskGraph. More...
 
- Protected Member Functions inherited from imstk::Component
 Component (const std::string &name="Component")
 
virtual void init ()
 Initialize the component, called at a later time after all component construction is complete.
 

Detailed Description

This class uses the provided device to control the provided rigid object via virtual coupling. That is, it applies forces+torques to the rigid body that will help move it to desired position/orientation. It has linear and angular spring scales as well as damping You may also use force smoothening for the force applied back on the device.

The PbdObjectController is not perfectly smooth yet

Definition at line 26 of file imstkPbdObjectController.h.

Member Function Documentation

◆ getSmoothingKernelSize()

int imstk::PbdObjectController::getSmoothingKernelSize ( ) const
inline

Set/Get the kernel size.

Todo:
: Vary with dt as performance of program will effect the size/number of samples

Definition at line 100 of file imstkPbdObjectController.h.

◆ update()

void imstk::PbdObjectController::update ( const double &  dt)
override

Update controlled scene object using latest tracking information.

< Slightly overdamp to account for numerical error with forward euler integration

Definition at line 27 of file imstkPbdObjectController.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: