40 static const double VELOCITY_DT = 0.02;
41 static const std::size_t REPORT_QUEUE_SIZE = 16;
48 template <
typename Derived>
49 inline Eigen::Quaterniond
50 angVelVecToQuat(Eigen::Quaterniond
const &orientation,
double dt,
51 Eigen::MatrixBase<Derived>
const &vec) {
52 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
54 Eigen::Quaterniond result =
55 orientation * angVelVecToIncRot(vec, dt) * orientation.conjugate();
62 assignStateToBodyReport(BodyState
const &state, BodyReport &report,
63 Eigen::Isometry3d
const &trackerToRoom) {
64 Eigen::Isometry3d output = trackerToRoom * state.getIsometry();
65 Eigen::Quaterniond orientation =
66 Eigen::Quaterniond(output.rotation()).normalized();
67 util::eigen_interop::map(report.pose).rotation() = orientation;
68 util::eigen_interop::map(report.pose).translation() =
71 util::eigen_interop::map(
72 report.vel.angularVelocity.incrementalRotation) =
73 angVelVecToQuat(orientation, VELOCITY_DT, state.angularVelocity());
74 report.vel.angularVelocity.dt = VELOCITY_DT;
75 report.vel.angularVelocityValid =
OSVR_TRUE;
77 util::eigen_interop::map(report.vel.linearVelocity) =
78 trackerToRoom * state.velocity();
79 report.vel.linearVelocityValid =
OSVR_TRUE;
90 QueueValueType queueVal;
93 while (m_queue.read(queueVal)) {
101 m_dataTime = queueVal.timestamp;
102 Eigen::Map<QueueValueVec> valMap(queueVal.stateData.data());
103 m_state.incrementalOrientation() = Eigen::Vector3d::Zero();
104 m_state.position() = valMap.head<3>();
105 m_state.
setQuaternion(Eigen::Quaterniond(valMap.segment<4>(3)));
106 m_state.velocity() = valMap.segment<3>(7);
107 m_state.angularVelocity() = valMap.tail<3>();
111 bool doingPrediction =
112 m_hasProcessModel && (m_state.
stateVector().tail<6>() !=
115 if (doingPrediction) {
121 dt += additionalPrediction;
127 m_state.postCorrect();
130 report.timestamp = currentTime + std::chrono::duration<double>(
131 additionalPrediction);
133 report.timestamp = m_dataTime;
135 assignStateToBodyReport(m_state, report, m_trackerToRoom);
136 report.status = ReportStatus::Valid;
144 QueueValueVec::Map(val.stateData.data()) << state.position(),
145 state.getQuaternion().coeffs(), state.velocity(),
146 state.angularVelocity();
149 return m_queue.write(std::move(val));
154 m_hasProcessModel =
true;
159 m_trackerToRoom = xform;
162 BodyReporting::BodyReporting()
163 : m_trackerToRoom(
Eigen::Isometry3d::Identity()),
164 m_queue(REPORT_QUEUE_SIZE) {}
Eigen::Matrix< Scalar, n, 1 > Vector
A vector of length n.
OSVR_EXTERN_C_END double osvrTimeValueDurationSeconds(const OSVR_TimeValue *tvA, const OSVR_TimeValue *tvB)
Compute the difference between the two time values, returning the duration as a double-precision floa...
StateVector const & stateVector() const
xhat
void setQuaternion(Eigen::Quaterniond const &quaternion)
Intended for startup use.
bool getReport(double additionalPrediction, BodyReport &report)
void getNow(TimeValue &tv)
Set the given TimeValue to the current time.
Header wrapping include of and for warning quieting.
#define OSVR_TRUE
Canonical "true" value for OSVR_CBool.
void setTrackerToRoomTransform(Eigen::Isometry3d const &xform)
bool updateState(util::time::TimeValue const &tv, BodyState const &state)
StateVector computeEstimate(State &state, double dt) const
static std::unique_ptr< BodyReporting > make()
Factory function.
Header for interoperation between the Eigen math library, the internal mini math library, and VRPN's quatlib.
void initProcessModel(BodyProcessModel const &process)
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
void setStateVector(StateVector const &state)
set xhat