Skip to content

Commit f565fc8

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 7530920 commit f565fc8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

phidgets_spatial/launch/spatial-launch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def generate_launch_description():
3838
'ahrs_bias_time': 1.25,
3939

4040
# optional param algorithm_magnetometer_gain, default is 0.005
41-
'algorithm_magnetometer_gain': 0.005,
41+
# WARNING: do not set on PhidgetSpatial MOT0110 onwards (not supported)!
42+
# 'algorithm_magnetometer_gain': 0.005,
4243

4344
# optional param heating_enabled, not modified by default
4445
'heating_enabled': False,

phidgets_spatial/src/spatial_ros_i.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,14 @@ SpatialRosI::SpatialRosI(const rclcpp::NodeOptions &options)
9292
this->get_parameter("ahrs_bias_time", ahrsBiasTime);
9393

9494
double algorithm_magnetometer_gain;
95+
bool set_algorithm_magnetometer_gain = true;
9596
if (!this->get_parameter("algorithm_magnetometer_gain",
9697
algorithm_magnetometer_gain))
9798
{
98-
algorithm_magnetometer_gain =
99-
0.005; // default to 0.005 (similar to phidgets api)
99+
algorithm_magnetometer_gain = 0.0;
100+
set_algorithm_magnetometer_gain =
101+
false; // if parameter not set, do not call api (because this
102+
// function is not available from MOT0110 onwards)
100103
}
101104

102105
bool heating_enabled;
@@ -267,7 +270,9 @@ SpatialRosI::SpatialRosI(const rclcpp::NodeOptions &options)
267270
ahrsBiasTime);
268271
}
269272

270-
spatial_->setAlgorithmMagnetometerGain(algorithm_magnetometer_gain);
273+
if (set_algorithm_magnetometer_gain)
274+
spatial_->setAlgorithmMagnetometerGain(
275+
algorithm_magnetometer_gain);
271276
}
272277

273278
if (has_compass_params)

0 commit comments

Comments
 (0)