37 #include <boost/optional.hpp>
40 #include <util/Stride.h>
47 using BodyStateHistoryEntry = StateHistoryEntry<BodyState>;
51 HistoryContainer<BodyStateHistoryEntry> stateHistory;
52 HistoryContainer<CannedIMUMeasurement> imuMeasurements;
53 bool everHadPose =
false;
56 : m_system(system), m_id(id), m_impl(new
Impl) {
59 m_state.setErrorCovariance(StateVec::Constant(10).asDiagonal());
62 getParams().angularVelocityDecayCoefficient);
63 m_processModel.setNoiseAutocorrelation(
70 TrackedBody::createIntegratedIMU(
double orientationVariance,
71 double angularVelocityVariance) {
76 m_imu.reset(
new TrackedBodyIMU{*
this, orientationVariance,
77 angularVelocityVariance});
92 targetToBody, setupData,
TargetId{0}});
93 return m_target.get();
108 auto it = m_impl->stateHistory.closest_not_newer(desiredTime);
109 if (m_impl->stateHistory.end() == it) {
114 it->second.restore(outState);
119 getOldestPossibleMeasurementSource(
TrackedBody const &body,
126 auto imuTimestamp = body.
getIMU().getLastUpdate();
127 if (imuTimestamp < oldest) {
128 oldest = imuTimestamp;
136 static ::util::Stride s(100);
138 std::cout <<
"stateHistory High water mark: "
139 << m_impl->stateHistory.highWaterMark() << std::endl;
140 std::cout <<
"imuMeasurements High water mark: "
141 << m_impl->imuMeasurements.highWaterMark() << std::endl;
145 if (m_impl->stateHistory.empty()) {
149 auto oldest = getOldestPossibleMeasurementSource(*
this, videoTime);
151 if (m_impl->stateHistory.newest_timestamp() < oldest) {
156 oldest = m_impl->stateHistory.newest_timestamp();
159 m_impl->stateHistory.pop_before(oldest);
161 m_impl->imuMeasurements.pop_before(oldest);
167 #if !(defined(OSVR_UVBI_ASSUME_SINGLE_CAMERA) && \
168 defined(OSVR_UVBI_ASSUME_CAMERA_ALWAYS_SLOWER))
169 #error "Current code assumes that all we have to replay is IMU measurements."
170 #endif // !(defined(OSVR_UVBI_ASSUME_SINGLE_CAMERA) &&
174 auto numPopped = m_impl->stateHistory.pop_after(origTime);
180 m_stateTime = newTime;
181 if (m_impl->stateHistory.is_valid_to_push_newest(m_stateTime)) {
186 auto numReplayed = std::size_t{0};
188 m_impl->imuMeasurements.get_range_newer_than(newTime)) {
189 applyIMUMeasurement(imuHist.first, imuHist.second);
194 void TrackedBody::pushState() {
195 m_impl->stateHistory.push_newest(m_stateTime,
201 if (!getSystem().isRoomCalibrationComplete()) {
205 if (meas.orientationValid()) {
206 Eigen::Quaterniond quat;
207 meas.restoreQuat(quat);
213 if (!m_impl->imuMeasurements.is_valid_to_push_newest(tv)) {
216 throw std::runtime_error(
"Got out of order timestamps from IMU!");
223 if (hasEverHadPoseEstimate()) {
224 applyIMUMeasurement(tv, meas);
227 m_impl->imuMeasurements.push_newest(tv, meas);
233 if (m_impl->stateHistory.is_valid_to_push_newest(tv)) {
234 applyIMUToState(getSystem(), m_stateTime, m_state, m_processModel,
250 bool TrackedBody::hasEverHadPoseEstimate()
const {
251 if (m_impl->everHadPose) {
255 forEachTarget([&ret](TrackedBodyTarget &target) {
256 ret = ret || target.hasPoseEstimate();
258 m_impl->everHadPose = ret;
Eigen::Matrix< Scalar, n, 1 > Vector
A vector of length n.
osvr::util::time::TimeValue getStateTime() const
Get timestamp associated with current state.
bool hasPoseEstimate() const
Do we have a pose estimate for this body in general?
A way for targets to access internals of a tracked body.
TrackedBody(TrackingSystem &system, BodyId id)
Constructor.
Vector< Dimension< T >::value > DimVector
A vector of length = dimension of T.
void setDamping(double posDamping, double oriDamping)
Set the damping - must be in (0, 1)
void pruneHistory(OSVR_TimeValue const &videoTime)
BodyId getId() const
Gets the body ID within the tracking system.
void replaceStateSnapshot(osvr::util::time::TimeValue const &origTime, osvr::util::time::TimeValue const &newTime, BodyState const &newState)
TrackedBodyIMU & getIMU()
Get the IMU - only valid if hasIMU is true.
TrackedBodyTarget * createTarget(Eigen::Vector3d const &targetToBody, TargetSetupData const &setupData)
ConfigParams const & getParams() const
ConfigParams const & getParams() const
General configuration parameters.
bool hasPoseEstimate() const
~TrackedBody()
Destructor - explicit so we can use unique_ptr for our pimpls.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
bool hasIMU() const
Does this tracked body have an IMU?
void calibrationHandleIMUData(BodyId id, util::time::TimeValue const &tv, Eigen::Quaterniond const &quat)
bool getStateAtOrBefore(osvr::util::time::TimeValue const &desiredTime, osvr::util::time::TimeValue &outTime, BodyState &outState)
void incorporateNewMeasurementFromIMU(util::time::TimeValue const &tv, CannedIMUMeasurement const &meas)