7 #include "imstkTrackingDeviceControl.h" 8 #include "imstkDeviceClient.h" 9 #include "imstkLogger.h" 10 #include "imstkMath.h" 16 TrackingDeviceControl::TrackingDeviceControl(
const std::string& name) :
18 m_translationOffset(Vec3d::Zero()),
19 m_rotationOffset(Quatd::Identity())
26 if (m_deviceClient ==
nullptr)
28 LOG(WARNING) <<
"warning: no controlling device set.";
33 const Vec3d prevPos = m_currentPos;
34 const Quatd prevOrientation = m_currentOrientation;
36 m_currentPos = m_deviceClient->getPosition();
37 m_currentOrientation = m_deviceClient->getOrientation();
38 m_currentVelocity = m_deviceClient->getVelocity();
39 m_currentAngularVelocity = m_deviceClient->getAngularVelocity();
44 m_currentPos[0] = -m_currentPos[0];
45 m_currentVelocity[0] = -m_currentVelocity[0];
49 m_currentPos[1] = -m_currentPos[1];
50 m_currentVelocity[1] = -m_currentVelocity[1];
54 m_currentPos[2] = -m_currentPos[2];
55 m_currentVelocity[2] = -m_currentVelocity[2];
59 m_currentOrientation.y() = -m_currentOrientation.y();
60 m_currentOrientation.z() = -m_currentOrientation.z();
61 m_currentAngularVelocity[0] = -m_currentAngularVelocity[0];
65 m_currentOrientation.x() = -m_currentOrientation.x();
66 m_currentOrientation.z() = -m_currentOrientation.z();
67 m_currentAngularVelocity[1] = -m_currentAngularVelocity[1];
71 m_currentOrientation.x() = -m_currentOrientation.x();
72 m_currentOrientation.y() = -m_currentOrientation.y();
73 m_currentAngularVelocity[2] = -m_currentAngularVelocity[2];
81 m_currentVelocity = m_currentVelocity *
m_scaling;
91 m_currentDisplacement = (m_currentPos - prevPos);
92 m_currentVelocity = m_currentDisplacement / dt;
97 Rotd currentR = Rotd(m_currentOrientation);
100 Vec3d basis = { 1.0, 0.0, 0.0 };
103 Vec3d vec1 = m_currentOrientation.normalized().toRotationMatrix() * basis;
104 Vec3d vec2 = prevOrientation.normalized().toRotationMatrix() * basis;
107 auto angle = std::acos(std::min(1.0, std::max(-1.0, vec1.dot(vec2)))) / dt;
109 m_currentAngularVelocity = (angle * currentR.axis());
122 TrackingDeviceControl::setPosition(
const Vec3d& pos)
124 this->m_currentPos = pos;
130 return m_currentOrientation;
134 TrackingDeviceControl::setOrientation(
const Quatd& orientation)
136 this->m_currentOrientation = orientation;
146 TrackingDeviceControl::getComputeVelocity()
const 158 TrackingDeviceControl::getComputeAngularVelocity()
const 166 return m_currentAngularVelocity;
170 TrackingDeviceControl::setAngularVelocity(
const Vec3d& angularVelocity)
172 m_currentAngularVelocity = angularVelocity;
178 return m_currentVelocity;
182 TrackingDeviceControl::setVelocity(
const Vec3d& velocity)
184 m_currentVelocity = velocity;
194 TrackingDeviceControl::setTranslationScaling(
const double scaling)
206 TrackingDeviceControl::setTranslationOffset(
const Vec3d& t)
218 TrackingDeviceControl::setRotationOffset(
const Quatd& r)
230 TrackingDeviceControl::setEffectorRotationOffset(
const Quatd& r)
242 TrackingDeviceControl::setInversionFlags(
const unsigned char f)
Vec3d m_translationOffset
Translation concatenated to the device translation.
virtual bool updateTrackingData(const double dt)
Update tracking data.
double m_scaling
Scaling factor for physical to virtual translations.
unsigned char m_invertFlags
Invert flags to be masked with DeviceTracker::InvertFlag.
const Vec3d & getAngularVelocity() const
Get/Set the angular velocity.
const Vec3d & getTranslationOffset() const
Get/Set the translation offset.
void setComputeAngularVelocity(const bool computeAngularVelocity)
Set/Get whether to compute the anular velocity from previous and current samples Useful if the device...
Quatd m_effectorRotationOffset
Rotation prefixed to the device rotation.
void setComputeVelocity(const bool computeVelocity)
Set/Get whether to compute the velocity from previous and current samples Useful if a device does not...
bool m_computeAngularVelocity
If true, will use current and previous rotations to produce angular velocity, if off, will ask device for angular velocity.
const Quatd & getOrientation() const
Set/Get the orientation of the tracker.
const Quatd & getRotationOffset()
Get/Set the rotation offset, this rotation is applied to the overall device coordinate system...
Quatd m_rotationOffset
Rotation concatenated to the device rotation.
const Vec3d & getPosition() const
Set/Get the position of the tracker.
const Quatd & getEffectorRotationOffset()
Get/Set the roation applied to the end effector, this can be used to register the device in virtual s...
bool m_computeVelocity
If true, will use current and previous positions to produce velocity, if off, will ask device for vel...
const Vec3d & getVelocity() const
Get/Set the linear velocity.
double getTranslationScaling() const
Get/Set the current scaling factor.
unsigned char getInversionFlags()
Get/Set the inversion flags, when set the corresponding axis coordinates or rotation angle will be ne...