25 #ifndef INCLUDED_ConfigurationParser_h_GUID_933C79EE_3392_4C8D_74D5_D9A72580DA6A
26 #define INCLUDED_ConfigurationParser_h_GUID_933C79EE_3392_4C8D_74D5_D9A72580DA6A
35 #include <boost/optional.hpp>
36 #include <json/value.h>
39 #include <initializer_list>
44 inline const char *getConfigStringForTargetSet(BuiltInTargetSets target) {
46 case osvr::vbtracker::BuiltInTargetSets::HDK1xChassis:
49 case osvr::vbtracker::BuiltInTargetSets::HDK2Chassis:
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>>
58 getEnumFromStringParameter(
59 Json::Value
const &root,
const char memberName[],
60 StringifyFunctor &&stringifyEnum,
61 std::initializer_list<EnumType>
const &possibleValues) {
63 std::pair<boost::optional<EnumType>, boost::optional<std::string>>;
65 if (!root.isMember(memberName)) {
68 auto &member = root[memberName];
69 if (!member.isString()) {
72 std::string str = member.asString();
74 for (
auto enumVal : possibleValues) {
75 if (str == stringifyEnum(enumVal)) {
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) {
90 config.
debug = root.get(
"showDebug",
false).asBool();
93 auto targetSet = getEnumFromStringParameter(root,
"targetSet",
94 getConfigStringForTargetSet,
95 AllBuiltInTargetSets);
96 if (targetSet.first) {
97 config.targetSet = *targetSet.first;
98 }
else if (targetSet.second) {
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."
109 getOptionalParameter(config.backPanelMeasurementError, root,
110 "backPanelMeasurementError");
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");
123 if (config.includeRearPanel) {
124 config.offsetToCentroid =
false;
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."
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."
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");
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");
166 getOptionalParameter(config.offsetToCentroid, root,
"offsetToCentroid");
167 if (!config.offsetToCentroid) {
168 getOptionalParameter(config.manualBeaconOffset, root,
169 "manualBeaconOffset");
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.";
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");
197 getOptionalParameter(config.boundingBoxFilterRatio, root,
198 "boundingBoxFilterRatio");
200 outputUnless(std::cout, root[
"boundingBoxFilterRatio"].
isNull())
201 << MESSAGE_PREFIX << PARAMNAME(
"boundingBoxFilterRatio")
202 <<
" parameter not actively used";
204 getOptionalParameter(config.maxZComponent, root,
"maxZComponent");
205 getOptionalParameter(config.shouldSkipBrightLeds, root,
206 "shouldSkipBrightLeds");
207 getOptionalParameter(config.brightLedVariancePenalty, root,
208 "brightLedVariancePenalty");
211 getOptionalParameter(config.softResets, root,
"softResets");
212 getOptionalParameter(config.softResetPositionVarianceScale, root,
213 "softResetPositionVarianceScale");
214 getOptionalParameter(config.softResetOrientationVariance, root,
215 "softResetOrientationVariance");
218 if (root.isMember(
"blobParams")) {
219 parseBlobParams(root[
"blobParams"], config.blobParams);
222 parseEdgeHoleExtractorParams(root[
"blobParams"],
223 config.extractParams);
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,
232 getOptionalParameter(config.imu.useOrientation, imu,
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");
251 #endif // INCLUDED_ConfigurationParser_h_GUID_933C79EE_3392_4C8D_74D5_D9A72580DA6A
bool isNull(PathElement const &elt)
Returns true if the path element provided is a NullElement.
bool debug
Whether to show the debug windows and debug messages.