mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-26 22:00:34 +08:00
sensor_mag.msg: add is_external flag & set it in the mag drivers
With this we don't have to use the ioctl MAGIOCGEXTERNAL, which does not work on POSIX (eg. RPi).
This commit is contained in:
@@ -406,6 +406,7 @@ void VotedSensorsUpdate::parameters_update()
|
||||
}
|
||||
|
||||
int topic_device_id = report.device_id;
|
||||
bool is_external = (bool)report.is_external;
|
||||
_mag_device_id[topic_instance] = topic_device_id;
|
||||
|
||||
// find the driver handle that matches the topic_device_id
|
||||
@@ -465,28 +466,25 @@ void VotedSensorsUpdate::parameters_update()
|
||||
|
||||
(void)sprintf(str, "CAL_MAG%u_ROT", i);
|
||||
|
||||
if (h.isValid()) { //FIXME: get the 'is external' information via uorb topic
|
||||
if (h.ioctl(MAGIOCGEXTERNAL, 0) <= 0) {
|
||||
/* mag is internal - reset param to -1 to indicate internal mag */
|
||||
int32_t minus_one;
|
||||
param_get(param_find(str), &minus_one);
|
||||
if (is_external) {
|
||||
int32_t mag_rot;
|
||||
param_get(param_find(str), &mag_rot);
|
||||
|
||||
if (minus_one != MAG_ROT_VAL_INTERNAL) {
|
||||
minus_one = MAG_ROT_VAL_INTERNAL;
|
||||
param_set_no_notification(param_find(str), &minus_one);
|
||||
}
|
||||
/* check if this mag is still set as internal, otherwise leave untouched */
|
||||
if (mag_rot < 0) {
|
||||
/* it was marked as internal, change to external with no rotation */
|
||||
mag_rot = 0;
|
||||
param_set_no_notification(param_find(str), &mag_rot);
|
||||
}
|
||||
|
||||
} else {
|
||||
/* mag is external */
|
||||
int32_t mag_rot;
|
||||
param_get(param_find(str), &mag_rot);
|
||||
} else {
|
||||
/* mag is internal - reset param to -1 to indicate internal mag */
|
||||
int32_t minus_one;
|
||||
param_get(param_find(str), &minus_one);
|
||||
|
||||
/* check if this mag is still set as internal, otherwise leave untouched */
|
||||
if (mag_rot < 0) {
|
||||
/* it was marked as internal, change to external with no rotation */
|
||||
mag_rot = 0;
|
||||
param_set_no_notification(param_find(str), &mag_rot);
|
||||
}
|
||||
if (minus_one != MAG_ROT_VAL_INTERNAL) {
|
||||
minus_one = MAG_ROT_VAL_INTERNAL;
|
||||
param_set_no_notification(param_find(str), &minus_one);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,6 +156,7 @@ void UavcanMagnetometerBridge::mag_sub_cb(const uavcan::ReceivedDataStructure<ua
|
||||
*/
|
||||
_report.timestamp = hrt_absolute_time();
|
||||
_report.device_id = _device_id.devid;
|
||||
_report.is_external = true;
|
||||
|
||||
_report.x = (msg.magnetic_field_ga[0] - _scale.x_offset) * _scale.x_scale;
|
||||
_report.y = (msg.magnetic_field_ga[1] - _scale.y_offset) * _scale.y_scale;
|
||||
|
||||
Reference in New Issue
Block a user