OSVR-Core
TrackedBodyTarget.h
Go to the documentation of this file.
1 
11 // Copyright 2016 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_TrackedBodyTarget_h_GUID_E4315530_5C4F_4DB4_2497_11686F0F6E0E
26 #define INCLUDED_TrackedBodyTarget_h_GUID_E4315530_5C4F_4DB4_2497_11686F0F6E0E
27 
28 // Internal Includes
29 #include "BeaconIdTypes.h"
30 #include "BeaconSetupData.h"
31 #include "BodyIdTypes.h"
32 #include "LedMeasurement.h"
33 #include "ModelTypes.h"
34 #include "Types.h"
35 
36 // Library/third-party includes
37 #include <boost/assert.hpp>
39 #include <osvr/Util/TimeValue.h>
40 
41 // Standard includes
42 #include <iosfwd>
43 #include <vector>
44 
45 namespace osvr {
46 namespace vbtracker {
47  struct CameraParameters;
48 
50  struct BeaconData {
51  bool seen = false;
52  double size = 0;
53  cv::Point2d measurement = {0, 0};
54  cv::Point2d residual = {0, 0};
55  double variance = 0;
56  void reset() { *this = BeaconData{}; }
57  };
58 
59  class TrackedBody;
60  struct BodyTargetInterface;
61 
62  enum class TargetStatusMeasurement {
65  MaxPosErrorVariance,
68  PosErrorVarianceLimit,
70  NumUsableLeds,
72  NumUsedLeds
73  };
74 
78  public:
80  BodyTargetInterface const &bodyIface,
81  Eigen::Vector3d const &targetToBody,
82  TargetSetupData const &setupData, TargetId id);
84  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
85 
86  std::vector<BeaconData> const &getBeaconDebugData() const {
87  return m_beaconDebugData;
88  }
89 
90  UnderlyingBeaconIdType getNumBeacons() const {
91  return static_cast<UnderlyingBeaconIdType>(m_numBeacons);
92  }
93 
94  TrackedBody &getBody() { return m_body; }
95  TrackedBody const &getBody() const { return m_body; }
96 
98  TargetId getId() const { return m_id; }
99 
101  BodyTargetId getQualifiedId() const;
102 
105  Eigen::Vector3d getBeaconAutocalibPosition(ZeroBasedBeaconId i) const;
108  Eigen::Vector3d getBeaconAutocalibVariance(ZeroBasedBeaconId i) const;
109 
111  void resetBeaconAutocalib();
112 
118  std::size_t
119  processLedMeasurements(LedMeasurementVec const &undistortedLeds);
120 
123  void disableKalman();
124 
127  void permitKalman();
128 
131  bool updatePoseEstimateFromLeds(
132  CameraParameters const &camParams,
133  osvr::util::time::TimeValue const &tv, BodyState &bodyState,
134  osvr::util::time::TimeValue const &startingTime,
135  bool validStateAndTime);
136 
154  bool uncalibratedRANSACPoseEstimateFromLeds(
155  CameraParameters const &camParams, Eigen::Vector3d &xlate,
156  Eigen::Quaterniond &quat, int skipBrightsCutoff = -1,
157  std::size_t iterations = 5);
158 
161  bool hasPoseEstimate() const { return m_hasPoseEstimate; }
162 
163  osvr::util::time::TimeValue const &getLastUpdate() const;
164 
167  Eigen::Vector3d const &getBeaconOffset() const {
168  return m_beaconOffset;
169  }
170 
172  LedGroup const &leds() const;
173 
175  LedPtrList const &usableLeds() const;
176 
179  std::size_t numTrackingResets() const;
180 
183  double
184  getInternalStatusMeasurement(TargetStatusMeasurement measurement) const;
185 
186  Eigen::Vector3d const &getTargetToBody() const {
187  return m_targetToBody;
188  }
189 
191  Eigen::Vector3d getStateCorrection() const;
192 
193  static Eigen::Vector3d
194  computeTranslationCorrection(Eigen::Vector3d const &bodyFrameOffset,
195  Eigen::Quaterniond const &orientation);
196 
197  Eigen::Vector3d computeTranslationCorrectionToBody(
198  Eigen::Quaterniond const &orientation) const;
199 
200  private:
201  std::ostream &msg() const;
202  void enterKalmanMode();
203  void enterRANSACMode();
204  void enterRANSACKalmanMode();
205 
206  void dumpBeaconsToConsole() const;
207 
208  LedGroup &leds();
209 
211  void updateUsableLeds();
212 
213  LedPtrList &usableLeds();
214 
215  ConfigParams const &getParams() const;
216  void m_verifyInvariants() const {
217  BOOST_ASSERT_MSG(m_beacons.size() ==
218  m_beaconMeasurementVariance.size(),
219  "Must have the same number of beacons as default "
220  "measurement variances.");
221  BOOST_ASSERT_MSG(
222  m_beacons.size() == m_beaconFixed.size(),
223  "Must have the same number of beacons as beacon fixed flags.");
224  BOOST_ASSERT_MSG(m_beacons.size() ==
225  m_beaconEmissionDirection.size(),
226  "Must have the same number of beacons as beacon "
227  "emission directions.");
228  }
230  using BeaconStateVec = std::vector<std::unique_ptr<BeaconState>>;
231 
233  TrackedBody &m_body;
234 
236  const TargetId m_id;
237 
240  Eigen::Vector3d m_targetToBody;
241 
242  const std::size_t m_numBeacons;
247  BeaconStateVec m_beacons;
248  std::vector<double> m_beaconMeasurementVariance;
250  std::vector<bool> m_beaconFixed;
251  Vec3Vector m_beaconEmissionDirection;
254  std::vector<BeaconData> m_beaconDebugData;
255 
256  BeaconStateVec m_origBeacons;
257 
258  Eigen::Vector3d m_beaconOffset;
259 
260  bool m_hasPoseEstimate = false;
261 
263  struct Impl;
264  std::unique_ptr<Impl> m_impl;
265  };
266 } // namespace vbtracker
267 } // namespace osvr
268 
269 #endif // INCLUDED_TrackedBodyTarget_h_GUID_E4315530_5C4F_4DB4_2497_11686F0F6E0E
A way for targets to access internals of a tracked body.
Definition: BodyTargetInterface.h:41
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
std::pair< BodyId, TargetId > BodyTargetId
Type-safe zero-based target ID qualified with its body ID.
Definition: BodyIdTypes.h:67
Header.
Definition: CameraParameters.h:41
TargetId getId() const
Get the target id within this body.
Definition: TrackedBodyTarget.h:98
Definition: TypeSafeId.h:41
Corresponds to a rigid arrangements of discrete beacons detected by video-based tracking - typically ...
Definition: TrackedBodyTarget.h:77
General configuration parameters.
Definition: ConfigParams.h:82
bool hasPoseEstimate() const
Did this target yet, or last time it was asked to, compute a pose estimate?
Definition: TrackedBodyTarget.h:161
Data for a full target (all the beacons), unswizzled into a "struct of vectors".
Definition: BeaconSetupData.h:53
Definition: TrackedBodyTarget.h:50
Header providing a C++ wrapper around TimeValueC.h.
This is the class representing a tracked rigid body in the system.
Definition: TrackedBody.h:56
Eigen::Vector3d const & getBeaconOffset() const
Get the offset that was subtracted from all beacon positions upon initialization. ...
Definition: TrackedBodyTarget.h:167
Definition: Quaternion.h:47
Header.
int UnderlyingBeaconIdType
All beacon IDs, whether 0 or 1 based, are ints on the inside.
Definition: BeaconIdTypes.h:49
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
A very simple (3D by default) vector state with no velocity, ideal for use as a position, with ConstantProcess for beacon autocalibration.
Definition: PureVectorState.h:40
Definition: TrackedBodyTarget.cpp:143