Skip to content

Commit 51a4ec0

Browse files
committed
Only set magnetometer gain if param is set
This is required because the function `PhidgetSpatial_setAlgorithmMagnetometerGain` is present in the Phidgets Spatial MOT0109 API (https://www.phidgets.com/?prodid=1204#Tab_API), but was removed in the MOT0110 API (https://www.phidgets.com/?prodid=1205#Tab_API). This caused an exception to be thrown on the MOT0110 (ros-drivers#168 (comment)). This commit allows not setting the parameter on the MOT0110 and onwards, thereby avoiding the function call and the exception.
1 parent 20512de commit 51a4ec0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

phidgets_spatial/launch/spatial.launch

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<param name="ahrs_bias_time" value="1.25"/> -->
4040

4141
# optional param algorithm_magnetometer_gain, default is 0.005
42+
# WARNING: do not set on PhidgetSpatial MOT0110 onwards (not supported)!
4243
<!-- <param name="algorithm_magnetometer_gain" value="0.005"/> -->
4344

4445
# optional param heating_enabled, not modified by default

phidgets_spatial/src/spatial_ros_i.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@ SpatialRosI::SpatialRosI(ros::NodeHandle nh, ros::NodeHandle nh_private)
9696
nh_private_.getParam("ahrs_bias_time", ahrsBiasTime);
9797

9898
double algorithm_magnetometer_gain;
99+
bool set_algorithm_magnetometer_gain = true;
99100
if (!nh_private_.getParam("algorithm_magnetometer_gain",
100101
algorithm_magnetometer_gain))
101102
{
102-
algorithm_magnetometer_gain =
103-
0.005; // default to 0.005 (similar to phidgets api)
103+
algorithm_magnetometer_gain = 0.0;
104+
set_algorithm_magnetometer_gain =
105+
false; // if parameter not set, do not call api (because this
106+
// function is not available from MOT0110 onwards)
104107
}
105108

106109
bool heating_enabled;
@@ -272,7 +275,9 @@ SpatialRosI::SpatialRosI(ros::NodeHandle nh, ros::NodeHandle nh_private)
272275
ahrsBiasTime);
273276
}
274277

275-
spatial_->setAlgorithmMagnetometerGain(algorithm_magnetometer_gain);
278+
if (set_algorithm_magnetometer_gain)
279+
spatial_->setAlgorithmMagnetometerGain(
280+
algorithm_magnetometer_gain);
276281
}
277282

278283
if (has_compass_params)

0 commit comments

Comments
 (0)