25 #ifndef INCLUDED_MakeHDKTrackingSystem_h_GUID_B7C07A08_2BF8_45B2_4545_39979BA637E5 26 #define INCLUDED_MakeHDKTrackingSystem_h_GUID_B7C07A08_2BF8_45B2_4545_39979BA637E5 48 #undef OSVR_UVBI_DISABLE_AUTOCALIB 49 #undef OSVR_UVBI_DEBUG_EMISSION_DIRECTION 50 #undef DEBUG_REAR_BEACON_TRANSFORM 59 static const std::vector<std::string>
60 OsvrHdkLedIdentifier_SENSOR0_PATTERNS = {
99 static const std::vector<std::string>
100 OsvrHdkLedIdentifier_SENSOR1_PATTERNS = {
108 static const auto SCALE_FACTOR = std::milli::den;
110 template <
typename Scalar>
using cvMatx33 = cv::Matx<Scalar, 3, 3>;
113 template <
typename Scalar>
inline cvMatx33<Scalar> get180AboutY() {
114 auto ret = cvMatx33<Scalar>::eye();
123 template <
typename Scalar>
inline cvMatx33<Scalar> getTransform() {
127 return get180AboutY<Scalar>();
131 template <
typename Scalar>
132 inline cvMatx33<Scalar> getTransformAndScale() {
133 return getTransform<Scalar>() * (
Scalar(1) /
Scalar(SCALE_FACTOR));
137 template <
typename Scalar>
138 inline cv::Point3_<Scalar>
139 transformFromHDKData(cv::Point3_<Scalar> input) {
140 static const cvMatx33<Scalar> xformMatrix =
141 getTransformAndScale<Scalar>();
142 return xformMatrix * input;
146 template <
typename Scalar>
147 inline cv::Vec<Scalar, 3>
148 transformFromHDKData(cv::Vec<Scalar, 3> input) {
149 static const cvMatx33<Scalar> xformMatrix = getTransform<Scalar>();
150 return xformMatrix * input;
153 inline LocationPoint rotatePoint180AboutY(LocationPoint pt) {
167 auto calibratedLocations = tryLoadingArrayOfPointsFromFile(filename);
169 auto n = calibratedLocations.size();
170 const auto numFrontBeacons = getNumHDKFrontPanelBeacons();
171 const auto numRearBeacons = getNumHDKRearPanelBeacons();
174 if (n == numFrontBeacons || n == (numFrontBeacons + numRearBeacons)) {
178 calibratedLocations.resize(numFrontBeacons);
180 calibratedLocations, begin(data.locations),
181 [](LocationPoint pt) { return transformFromHDKData(pt); });
184 for (std::size_t i = 0; i < numFrontBeacons; ++i) {
185 data.initialAutocalibrationErrors[i] *=
186 BEACON_AUTOCALIB_ERROR_SCALE_IF_CALIBRATED;
195 case BuiltInTargetSets::HDK1xChassis:
196 return OsvrHdkLedLocations_SENSOR0;
198 case BuiltInTargetSets::HDK2Chassis:
206 case BuiltInTargetSets::HDK1xChassis:
207 return OsvrHdkLedLocations_SENSOR1;
209 case BuiltInTargetSets::HDK2Chassis:
210 return OsvrHdk2LedLocations_SENSOR1;
215 inline std::unique_ptr<TrackingSystem>
217 auto silent = params.
silent;
220 #ifdef OSVR_UVBI_DEBUG_EMISSION_DIRECTION 222 auto xform = getTransform<float>();
223 std::cout <<
"Transform matrix:\n" << xform << std::endl;
226 auto sampleBeacons = {5, 32, 9, 10};
229 auto hmd = sys->createTrackedBody();
231 throw std::runtime_error(
232 "Could not create a tracked body for the HMD!");
235 const auto numFrontBeacons = getNumHDKFrontPanelBeacons();
236 const auto numRearBeacons = getNumHDKRearPanelBeacons();
238 const auto numBeacons =
239 numFrontBeacons + (useRear ? numRearBeacons : 0);
243 data.setBeaconCount(numBeacons, BaseMeasurementVariance,
247 data.patterns = OsvrHdkLedIdentifier_SENSOR0_PATTERNS;
251 data.patterns.insert(end(data.patterns),
252 begin(OsvrHdkLedIdentifier_SENSOR1_PATTERNS),
253 end(OsvrHdkLedIdentifier_SENSOR1_PATTERNS));
259 getTarget0Locations(params.
targetSet), begin(data.locations),
260 [](LocationPoint pt) { return transformFromHDKData(pt); });
267 messages::loadedCalibFileSuccessfully(
283 auto transformBackPoints =
284 [distanceBetweenPanels](LocationPoint pt) {
285 auto p = rotatePoint180AboutY(pt) -
286 LocationPoint(0, 0, distanceBetweenPanels);
287 return transformFromHDKData(p);
290 transformBackPoints);
291 #ifdef DEBUG_REAR_BEACON_TRANSFORM 292 std::cout <<
"Front beacon position (id 32): " 293 << data.locations[32 - 1] <<
" (originally " 294 << OsvrHdkLedLocations_SENSOR0[32 - 1] <<
")" 296 std::cout <<
"Back beacon position (id 40): " 297 << data.locations[40 - 1] <<
" (originally " 298 << OsvrHdkLedLocations_SENSOR1.back() <<
")" << std::endl;
304 OsvrHdkLedDirections_SENSOR0, begin(data.emissionDirections),
305 [](EmissionDirectionVec v) { return transformFromHDKData(v); });
310 data.emissionDirections.resize(numFrontBeacons);
311 data.emissionDirections.resize(
313 transformFromHDKData(EmissionDirectionVec(0, 0, -1)));
315 #ifdef OSVR_UVBI_DEBUG_EMISSION_DIRECTION 316 for (
auto &beaconOneBased : sampleBeacons) {
317 std::cout <<
"Beacon ID " << beaconOneBased
318 <<
" emission direction " 319 << data.emissionDirections[beaconOneBased - 1]
324 #ifdef OSVR_UVBI_DISABLE_AUTOCALIB 325 for (decltype(numBeacons) i = 0; i < numBeacons; ++i) {
330 for (
auto idx : {16, 17, 19, 20}) {
341 begin(data.baseMeasurementVariances));
345 if (params.
targetSet == BuiltInTargetSets::HDK2Chassis) {
346 for (
auto id : getOneBasedIDsOfMissingBeaconsHDK2()) {
352 auto summary = data.cleanAndValidate(params.
silent);
354 auto opticalTarget = hmd->createTarget(
356 Eigen::Vector3d(0, 0, 0.04141),
358 Eigen::Vector3d::Zero(),
362 if (!opticalTarget) {
363 throw std::runtime_error(
364 "Could not create a tracked target for the HMD!");
368 !params.
imu.path.empty() &&
376 throw std::runtime_error(
"Could not create an integrated " 377 "IMU object for the HMD!");
390 #endif // INCLUDED_MakeHDKTrackingSystem_h_GUID_B7C07A08_2BF8_45B2_4545_39979BA637E5
bool silent
For optimization usage.
Definition: ConfigParams.h:89
const std::vector< double > OsvrHdkLedVariances_SENSOR0
generated by python script in this directory.
Definition: HDKData.cpp:182
bool includeRearPanel
If true, this will replace the two sensors with just a single one, including the beacons at the back ...
Definition: ConfigParams.h:183
std::string calibrationFile
If non-empty, the file to load (or save to) for calibration data.
Definition: ConfigParams.h:251
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
std::unique_ptr< TrackingSystem > makeHDKTrackingSystem(ConfigParams const ¶ms)
Definition: MakeHDKTrackingSystem.h:216
double initialBeaconError
Initial beacon error for autocalibration (units: m^2).
Definition: ConfigParams.h:130
Definition: ForwardDeclarations.h:236
Definition: TrackingSystem.h:54
bool tryLoadingCalibration(std::string const &filename, TargetSetupData &data)
returns true if it actually did load one.
Definition: MakeHDKTrackingSystem.h:161
const Point3Vector OsvrHdk2LedLocations_SENSOR0
Locations on the HDK2 chassis - for LEDs that the HDK2 lacks, the HDK1 values were used as placeholde...
Definition: HDKData.cpp:95
IMUInputParams imu
IMU input-related parameters.
Definition: ConfigParams.h:254
BuiltInTargetSets targetSet
When using hard-coded target sets, which one to use.
Definition: ConfigParams.h:108
General configuration parameters.
Definition: ConfigParams.h:82
Data for a full target (all the beacons), unswizzled into a "struct of vectors".
Definition: BeaconSetupData.h:53
OneBasedBeaconId makeOneBased(ZeroBasedBeaconId id)
Overloaded conversion function to turn any beacon ID into one-based, respecting the convention that n...
Definition: BeaconIdTypes.h:79
double cameraPosition[3]
x, y, z, with y up, all in meters.
Definition: ConfigParams.h:257
float computeDistanceBetweenPanels(ConfigParams const &config)
distance between front and back panel target origins, in mm.
Definition: SetupSensors.h:68
double headCircumference
Head circumference at the head strap, in cm - 55.75 is our estimate for an average based on some hat ...
Definition: ConfigParams.h:188
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
double headToFrontBeaconOriginDistance
This is the distance fron the front of the head to the origin of the front sensor coordinate system i...
Definition: ConfigParams.h:194
BuiltInTargetSets
If you add an entry here, must also update both getConfigStringForTargetSet and AllBuiltInTargetSets ...
Definition: ConfigParams.h:79