OSVR-Core
ConfigurationParser.h
Go to the documentation of this file.
1 
11 // Copyright 2015 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_ConfigurationParser_h_GUID_933C79EE_3392_4C8D_74D5_D9A72580DA6A
26 #define INCLUDED_ConfigurationParser_h_GUID_933C79EE_3392_4C8D_74D5_D9A72580DA6A
27 
28 // Internal Includes
29 #include "GetOptionalParameter.h"
30 #include "OptionalStream.h"
31 #include "Types.h"
32 #include <ParseBlobParams.h>
33 
34 // Library/third-party includes
35 #include <boost/optional.hpp>
36 #include <json/value.h>
37 
38 // Standard includes
39 #include <initializer_list>
40 #include <iostream>
41 
42 namespace osvr {
43 namespace vbtracker {
44  inline const char *getConfigStringForTargetSet(BuiltInTargetSets target) {
45  switch (target) {
46  case osvr::vbtracker::BuiltInTargetSets::HDK1xChassis:
47  return "HDK1x";
48  break;
49  case osvr::vbtracker::BuiltInTargetSets::HDK2Chassis:
50  return "HDK2";
51  break;
52  }
53  }
54  static const std::initializer_list<BuiltInTargetSets> AllBuiltInTargetSets =
55  {BuiltInTargetSets::HDK1xChassis, BuiltInTargetSets::HDK2Chassis};
56  template <typename EnumType, typename StringifyFunctor>
57  inline std::pair<boost::optional<EnumType>, boost::optional<std::string>>
59  Json::Value const &root, const char memberName[],
60  StringifyFunctor &&stringifyEnum,
61  std::initializer_list<EnumType> const &possibleValues) {
62  using ReturnType =
63  std::pair<boost::optional<EnumType>, boost::optional<std::string>>;
64  ReturnType ret;
65  if (!root.isMember(memberName)) {
66  return ret;
67  }
68  auto &member = root[memberName];
69  if (!member.isString()) {
70  return ret;
71  }
72  std::string str = member.asString();
73  ret.second = str;
74  for (auto enumVal : possibleValues) {
75  if (str == stringifyEnum(enumVal)) {
77  ret.first = enumVal;
78  return ret;
79  }
80  }
81  // didn't find it. But, they get a string back anyway.
82  return ret;
83  }
84 
85  static const auto MESSAGE_PREFIX =
86  "[Unified Tracker] Configuration Parsing WARNING: ";
87 #define PARAMNAME(X) "'" << X << "'"
88  inline ConfigParams parseConfigParams(Json::Value const &root) {
89  ConfigParams config;
90  config.debug = root.get("showDebug", false).asBool();
91 
92  // Target set, first and foremost.
93  auto targetSet = getEnumFromStringParameter(root, "targetSet",
94  getConfigStringForTargetSet,
95  AllBuiltInTargetSets);
96  if (targetSet.first) {
97  config.targetSet = *targetSet.first;
98  } else if (targetSet.second) {
99  // some string that we couldn't turn into an enum
101  // right now, we just warn
102  std::cout << MESSAGE_PREFIX << PARAMNAME("targetSet")
103  << " contained a string, \"" << *(targetSet.second)
104  << "\", that was not recognized as a known target set. "
105  "Using the default instead."
106  << std::endl;
107  }
108 
110  "backPanelMeasurementError");
111 
113  getOptionalParameter(config.includeRearPanel, root, "includeRearPanel");
114  getOptionalParameter(config.headCircumference, root,
115  "headCircumference");
116  getOptionalParameter(config.headToFrontBeaconOriginDistance, root,
117  "headToFrontBeaconOriginDistance");
118  getOptionalParameter(config.backPanelMeasurementError, root,
119  "backPanelMeasurementError");
120 
121  // If we include the rear panel, we default to not offsetting to
122  // centroid since it causes strange tracking.
123  if (config.includeRearPanel) {
124  config.offsetToCentroid = false;
125  }
126 
128  getOptionalParameter(config.logRawBlobs, root, "logRawBlobs");
129  if (config.logRawBlobs) {
130  std::cout << MESSAGE_PREFIX << PARAMNAME("logRawBlobs")
131  << " is enabled - existing raw blob data file will be "
132  "overwritten, and there is a slight chance of "
133  "performance impacts."
134  << std::endl;
135  }
136  getOptionalParameter(config.logUsableLeds, root, "logUsableLeds");
137  if (config.logUsableLeds) {
138  std::cout << MESSAGE_PREFIX << PARAMNAME("logUsableLeds")
139  << " is enabled - existing 'usable LED' data file will "
140  "be overwritten, and there is a slight chance of "
141  "performance impacts."
142  << std::endl;
143  }
144 
145  getOptionalParameter(config.continuousReporting, root,
146  "continuousReporting");
147  getOptionalParameter(config.extraVerbose, root, "extraVerbose");
148  getOptionalParameter(config.highGain, root, "highGain");
149  getOptionalParameter(config.calibrationFile, root, "calibrationFile");
150 
151  getOptionalParameter(config.additionalPrediction, root,
152  "additionalPrediction");
153  getOptionalParameter(config.maxResidual, root, "maxResidual");
154  getOptionalParameter(config.initialBeaconError, root,
155  "initialBeaconError");
156  getOptionalParameter(config.blobMoveThreshold, root,
157  "blobMoveThreshold");
158  getOptionalParameter(config.blobsKeepIdentity, root,
159  "blobsKeepIdentity");
160  getOptionalParameter(config.numThreads, root, "numThreads");
161  getOptionalParameter(config.cameraMicrosecondsOffset, root,
162  "cameraMicrosecondsOffset");
163  getOptionalParameter(config.streamBeaconDebugInfo, root,
164  "streamBeaconDebugInfo");
165 
166  getOptionalParameter(config.offsetToCentroid, root, "offsetToCentroid");
167  if (!config.offsetToCentroid) {
168  getOptionalParameter(config.manualBeaconOffset, root,
169  "manualBeaconOffset");
170  }
171 
173  getOptionalParameter(config.cameraPosition, root, "cameraPosition");
174  getOptionalParameter(config.cameraIsForward, root, "cameraIsForward");
175  outputUnless(std::cout, root["eyeHeight"].isNull())
176  << MESSAGE_PREFIX << PARAMNAME("eyeHeight")
177  << " is deprecated/ignored: use 'cameraPosition' for similar "
178  "effects with this plugin.";
179 
181  getOptionalParameter(config.permitKalman, root, "permitKalman");
182  getOptionalParameter(config.beaconProcessNoise, root,
183  "beaconProcessNoise");
184  getOptionalParameter(config.processNoiseAutocorrelation, root,
185  "processNoiseAutocorrelation");
186  getOptionalParameter(config.linearVelocityDecayCoefficient, root,
187  "linearVelocityDecayCoefficient");
188  getOptionalParameter(config.angularVelocityDecayCoefficient, root,
189  "angularVelocityDecayCoefficient");
190  getOptionalParameter(config.noBeaconLinearVelocityDecayCoefficient,
191  root, "noBeaconLinearVelocityDecayCoefficient");
192  getOptionalParameter(config.measurementVarianceScaleFactor, root,
193  "measurementVarianceScaleFactor");
194  getOptionalParameter(config.highResidualVariancePenalty, root,
195  "highResidualVariancePenalty");
196 #if 0
197  getOptionalParameter(config.boundingBoxFilterRatio, root,
198  "boundingBoxFilterRatio");
199 #else
200  outputUnless(std::cout, root["boundingBoxFilterRatio"].isNull())
201  << MESSAGE_PREFIX << PARAMNAME("boundingBoxFilterRatio")
202  << " parameter not actively used";
203 #endif
204  getOptionalParameter(config.maxZComponent, root, "maxZComponent");
205  getOptionalParameter(config.shouldSkipBrightLeds, root,
206  "shouldSkipBrightLeds");
207  getOptionalParameter(config.brightLedVariancePenalty, root,
208  "brightLedVariancePenalty");
209 
211  getOptionalParameter(config.softResets, root, "softResets");
212  getOptionalParameter(config.softResetPositionVarianceScale, root,
213  "softResetPositionVarianceScale");
214  getOptionalParameter(config.softResetOrientationVariance, root,
215  "softResetOrientationVariance");
216 
218  if (root.isMember("blobParams")) {
219  parseBlobParams(root["blobParams"], config.blobParams);
220 
221  // We'll just combine them into one JSON object here.
222  parseEdgeHoleExtractorParams(root["blobParams"],
223  config.extractParams);
224  }
225 
227  if (root.isMember("imu")) {
228  Json::Value const &imu = root["imu"];
229  getOptionalParameter(config.imu.path, imu, "path");
230  getOptionalParameter(config.imu.calibrateAnyway, imu,
231  "calibrateAnyway");
232  getOptionalParameter(config.imu.useOrientation, imu,
233  "useOrientation");
234  getOptionalParameter(config.imu.orientationVariance, imu,
235  "orientationVariance");
236  getOptionalParameter(config.imu.orientationMicrosecondsOffset, imu,
237  "orientationMicrosecondsOffset");
238  getOptionalParameter(config.imu.useAngularVelocity, imu,
239  "useAngularVelocity");
240  getOptionalParameter(config.imu.angularVelocityVariance, imu,
241  "angularVelocityVariance");
242  getOptionalParameter(config.imu.angularVelocityMicrosecondsOffset,
243  imu, "angularVelocityMicrosecondsOffset");
244  }
245 
246  return config;
247  }
248 #undef PARAMNAME
249 } // End namespace vbtracker
250 } // End namespace osvr
251 #endif // INCLUDED_ConfigurationParser_h_GUID_933C79EE_3392_4C8D_74D5_D9A72580DA6A
double angularVelocityVariance
units: (rad/sec)^2
Definition: ConfigParams.h:63
bool streamBeaconDebugInfo
When true, will stream debug info (variance, pixel measurement, pixel residual) on up to the first 34...
Definition: ConfigParams.h:213
double linearVelocityDecayCoefficient
The value used in exponential decay of linear velocity: it&#39;s the proportion of that velocity remainin...
Definition: ConfigParams.h:151
double processNoiseAutocorrelation[6]
This is the autocorrelation kernel of the process noise.
Definition: ConfigParams.h:146
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
int numThreads
How many threads to let OpenCV use.
Definition: ConfigParams.h:141
float boundingBoxFilterRatio
This should be the ratio of lengths of sides that you&#39;ll permit to be filtered in.
Definition: ConfigParams.h:219
std::string calibrationFile
If non-empty, the file to load (or save to) for calibration data.
Definition: ConfigParams.h:251
double highResidualVariancePenalty
This is the multiplicative penalty applied to the variance of measurements with a "bad" residual...
Definition: ConfigParams.h:208
bool logUsableLeds
For recording tuning data - whether we should record the data from just the usable LEDs each frame af...
Definition: ConfigParams.h:97
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
double brightLedVariancePenalty
If shouldSkipBrightLeds is false, we use this value as a factor to increase the measurement variance ...
Definition: ConfigParams.h:235
double backPanelMeasurementError
This used to be different than the other beacons, but now it&#39;s mostly the same.
Definition: ConfigParams.h:198
std::pair< boost::optional< EnumType >, boost::optional< std::string > > getEnumFromStringParameter(Json::Value const &root, const char memberName[], StringifyFunctor &&stringifyEnum, std::initializer_list< EnumType > const &possibleValues)
Definition: ConfigurationParser.h:58
Header.
double noBeaconLinearVelocityDecayCoefficient
The value used in an additional exponential decay of linear velocity when we&#39;ve lost sight of all bea...
Definition: ConfigParams.h:162
ConfigParams parseConfigParams(Json::Value const &root)
Definition: ConfigurationParser.h:88
BlobParams blobParams
Parameters specific to the blob-detection step of the algorithm.
Definition: ConfigParams.h:102
double manualBeaconOffset[3]
Manual beacon offset (in m) - only really sensible if you only have one target, only used if offsetTo...
Definition: ConfigParams.h:177
double initialBeaconError
Initial beacon error for autocalibration (units: m^2).
Definition: ConfigParams.h:130
bool offsetToCentroid
Whether the tracking algorithm internally adjusts beacon positions based on the centroid of the input...
Definition: ConfigParams.h:173
bool extraVerbose
Extra verbose developer debugging messages.
Definition: ConfigParams.h:247
bool isNull(PathElement const &elt)
Returns true if the path element provided is a NullElement.
Definition: PathElementTools.cpp:87
double orientationVariance
units: rad^2
Definition: ConfigParams.h:55
bool logRawBlobs
For recording tuning data - whether we should record the raw blob data.
Definition: ConfigParams.h:93
double blobMoveThreshold
Maximum distance a blob can move, in multiples of its previous "keypoint diameter", and still be considered the same blob.
Definition: ConfigParams.h:134
IMUInputParams imu
IMU input-related parameters.
Definition: ConfigParams.h:254
bool calibrateAnyway
Should we use the IMU orientation data for calibration even if useOrientation is false?
Definition: ConfigParams.h:49
BuiltInTargetSets targetSet
When using hard-coded target sets, which one to use.
Definition: ConfigParams.h:108
General configuration parameters.
Definition: ConfigParams.h:82
double beaconProcessNoise
This is the process-model noise in the beacon-auto-calibration, in mm^2/s.
Definition: ConfigParams.h:204
bool permitKalman
Should we permit the whole system to enter Kalman mode? Not doing so is usually a bad idea...
Definition: ConfigParams.h:266
double maxResidual
Max residual, in meters at the expected XY plane of the beacon in space, for a beacon before applying...
Definition: ConfigParams.h:123
void getOptionalParameter(T &dest, Json::Value const &obj, const char *key)
Gets an optional parameter from a JSON object: if it&#39;s not present, the existing value is left there...
Definition: GetOptionalParameter.h:60
double cameraPosition[3]
x, y, z, with y up, all in meters.
Definition: ConfigParams.h:257
bool shouldSkipBrightLeds
Should we attempt to skip bright-mode LEDs? The alternative is to just give them slightly higher vari...
Definition: ConfigParams.h:229
bool softResets
Should we permit a reset to be "soft" (blended by a Kalman) rather than a hard state setting...
Definition: ConfigParams.h:275
bool highGain
Should we open the camera in high-gain mode?
Definition: ConfigParams.h:116
bool debug
Whether to show the debug windows and debug messages.
Definition: ConfigParams.h:137
double measurementVarianceScaleFactor
The measurement variance (units: m^2) is included in the plugin along with the coordinates of the bea...
Definition: ConfigParams.h:169
bool useAngularVelocity
Should angular velocity reports be used once calibration completes?
Definition: ConfigParams.h:60
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 softResetPositionVarianceScale
Soft reset data incorporation parameter: Positional variance scale - multiplied by the square of the ...
Definition: ConfigParams.h:279
double additionalPrediction
Seconds beyond the current time to predict, using the Kalman state.
Definition: ConfigParams.h:119
bool continuousReporting
Should we have the tracking thread update the reporting vector for every (IMU) message, instead of waiting/buffering for a few milliseconds between updates?
Definition: ConfigParams.h:113
bool blobsKeepIdentity
If this option is set to true, then while some of the pattern identifier is run each frame...
Definition: ConfigParams.h:244
std::int32_t cameraMicrosecondsOffset
Time offset for the camera timestamp, in microseconds.
Definition: ConfigParams.h:270
bool useOrientation
Should orientation reports be used once calibration completes?
Definition: ConfigParams.h:52
double maxZComponent
This should be a negative number - it&#39;s the largest the z component of the camera-space LED emission ...
Definition: ConfigParams.h:225
bool cameraIsForward
Whether we should adjust transforms to assume the camera looks along the YZ plane in the +Z direction...
Definition: ConfigParams.h:261
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
double softResetOrientationVariance
Soft reset data incorporation parameter: Orientation variance.
Definition: ConfigParams.h:282
double angularVelocityDecayCoefficient
The value used in exponential decay of angular velocity: it&#39;s the proportion of that velocity remaini...
Definition: ConfigParams.h:156
EdgeHoleParams extractParams
Parameters specific to the edge hole based LED extraction algorithm.
Definition: ConfigParams.h:105