Skip to content

Commit 8d53692

Browse files
committed
feat(ekf2): add RangingBeacon to new mavlink-CTRL logic
1 parent 17e8e29 commit 8d53692

File tree

8 files changed

+33
-17
lines changed

8 files changed

+33
-17
lines changed

msg/EstimatorFusionControl.msg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ uint8 rng_intended
1010
uint8 drag_intended
1111
uint8 mag_intended
1212
uint8 aspd_intended
13+
uint8 rngbcn_intended
1314

1415
# whether the estimator is actively fusing data from each source
1516
uint8 gps_active
@@ -21,3 +22,4 @@ bool rng_active
2122
bool drag_active
2223
bool mag_active
2324
bool aspd_active
25+
bool rngbcn_active

msg/versioned/VehicleCommand.msg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ uint8 FUSION_SOURCE_BARO = 5 # Barometer (EKF2_BARO_CTRL)
119119
uint8 FUSION_SOURCE_RNG = 6 # Range Finder (EKF2_RNG_CTRL)
120120
uint8 FUSION_SOURCE_DRAG = 7 # Drag (EKF2_DRAG_CTRL)
121121
uint8 FUSION_SOURCE_MAG = 8 # Magnetometer (EKF2_MAG_TYPE)
122-
uint8 FUSION_SOURCE_ASPD = 9 # Airspeed (EKF2_ARSP_THR)
122+
uint8 FUSION_SOURCE_ASPD = 9 # Airspeed (EKF2_ARSP_THR)
123+
uint8 FUSION_SOURCE_RNGBCN = 10 # Ranging Beacon (EKF2_RNGBC_CTRL)
123124

124125
# PX4 vehicle commands (beyond 16 bit MAVLink commands).
125126
uint32 VEHICLE_CMD_PX4_INTERNAL_START = 65537 # Start of PX4 internal only vehicle commands (> UINT16_MAX).

src/modules/ekf2/EKF/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ struct FusionControl {
289289
FusionSensor drag;
290290
FusionSensor mag{false, 5}; // MagFuseType::NONE
291291
FusionSensor aspd;
292+
FusionSensor rngbcn;
292293
};
293294

294295
struct parameters {

src/modules/ekf2/EKF2.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ void EKF2::VerifyParams()
978978
void EKF2::initFusionControl()
979979
{
980980
_sens_en_param = param_find("EKF2_SENS_EN");
981-
int32_t sens_en = 4095; // default: all enabled
981+
int32_t sens_en = 16383; // default: all enabled
982982

983983
if (_sens_en_param != PARAM_INVALID) {
984984
param_get(_sens_en_param, &sens_en);
@@ -1001,7 +1001,7 @@ void EKF2::initFusionControl()
10011001
}
10021002
};
10031003

1004-
// bit layout: 0..1=GPS0..1 2=OF 3=EV 4..7=AGP0..3 8=BARO 9=RNG 10=DRAG 11=MAG 12=ASPD
1004+
// bit layout: 0..1=GPS0..1 2=OF 3=EV 4..7=AGP0..3 8=BARO 9=RNG 10=DRAG 11=MAG 12=ASPD 13=RNGBCN
10051005
#if defined(CONFIG_EKF2_GNSS)
10061006
add(_fc.gps, 0, vehicle_command_s::FUSION_SOURCE_GPS, -1, _param_ekf2_gps_ctrl.handle());
10071007
// TODO: gps[1] reserved — no param yet, add second GPS instance here when multi-GPS CTRL is implemented
@@ -1041,6 +1041,9 @@ void EKF2::initFusionControl()
10411041
#if defined(CONFIG_EKF2_AIRSPEED)
10421042
add(_fc.aspd, 12, vehicle_command_s::FUSION_SOURCE_ASPD, -1, _param_ekf2_arsp_thr.handle());
10431043
#endif
1044+
#if defined(CONFIG_EKF2_RANGING_BEACON)
1045+
add(_fc.rngbcn, 13, vehicle_command_s::FUSION_SOURCE_RNGBCN, -1, _param_ekf2_rngbc_ctrl.handle());
1046+
#endif
10441047
}
10451048

10461049
void EKF2::updateFusionIntended()
@@ -2027,11 +2030,12 @@ void EKF2::PublishFusionControl(const hrt_abstime &timestamp)
20272030
msg.agp_intended[i] = _fc.agp[i].intended;
20282031
}
20292032

2030-
msg.baro_intended = _fc.baro.intended;
2031-
msg.rng_intended = _fc.rng.intended;
2032-
msg.drag_intended = _fc.drag.intended;
2033-
msg.mag_intended = _fc.mag.intended;
2034-
msg.aspd_intended = _fc.aspd.intended;
2033+
msg.baro_intended = _fc.baro.intended;
2034+
msg.rng_intended = _fc.rng.intended;
2035+
msg.drag_intended = _fc.drag.intended;
2036+
msg.mag_intended = _fc.mag.intended;
2037+
msg.aspd_intended = _fc.aspd.intended;
2038+
msg.rngbcn_intended = _fc.rngbcn.intended;
20352039

20362040
const auto &cs = _ekf.control_status_flags();
20372041
msg.gps_active = (cs.gnss_pos || cs.gps_hgt || cs.gnss_vel || cs.gnss_yaw) ? 1u : 0u; // TODO: per-instance active tracking
@@ -2041,7 +2045,8 @@ void EKF2::PublishFusionControl(const hrt_abstime &timestamp)
20412045
msg.rng_active = cs.rng_hgt;
20422046
msg.drag_active = (_fc.drag.intended > 0) && cs.wind && cs.in_air && !cs.fake_pos;
20432047
msg.mag_active = cs.mag;
2044-
msg.aspd_active = cs.fuse_aspd;
2048+
msg.aspd_active = cs.fuse_aspd;
2049+
// msg.rngbcn_active = cs.rngbcn_fusion; // waiting for RangeBeacon PR
20452050

20462051
#if defined(CONFIG_EKF2_AUX_GLOBAL_POSITION)
20472052
msg.agp_active = _ekf.getAgpFusingBitmask();

src/modules/ekf2/EKF2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class EKF2 final : public ModuleParams, public px4::ScheduledWorkItem
405405
uint8_t disabled_val;
406406
};
407407

408-
static constexpr uint8_t MAX_SENSOR_TABLE = 9 + (MAX_AGP_INSTANCES - 1); // 12
408+
static constexpr uint8_t MAX_SENSOR_TABLE = 10 + (MAX_AGP_INSTANCES - 1); // 13
409409
FusionEntry _sensor_table[MAX_SENSOR_TABLE] {};
410410
uint8_t _num_sensor_table{0};
411411

src/modules/ekf2/module.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ parameters:
216216
10: Drag
217217
11: Magnetometer
218218
12: Airspeed
219-
default: 8191
219+
13: Ranging beacon
220+
default: 16383
220221
min: 0
221-
max: 8191
222+
max: 16383

src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ EkfWrapper::EkfWrapper(std::shared_ptr<Ekf> ekf):
2323
_fc->mag.intended = static_cast<uint8_t>(_ekf_params->ekf2_mag_type);
2424
_fc->aspd.enabled = true;
2525
_fc->aspd.intended = static_cast<uint8_t>(_ekf_params->ekf2_arsp_thr);
26+
_fc->rngbcn.enabled = true;
27+
_fc->rngbcn.intended = 0; // wait for RangeBeacon PR
2628

2729
for (int i = 0; i < MAX_AGP_INSTANCES; i++) {
2830
_fc->agp[i].enabled = true;

src/modules/mavlink/streams/ESTIMATOR_SENSOR_FUSION_STATUS.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* Array index = ESTIMATOR_SENSOR_FUSION_SOURCE - 1:
4242
* [0] GPS [1] OF [2] EV [3] AGP
43-
* [4] BARO [5] RNG [6] DRAG [7] MAG [8] ASPD
43+
* [4] BARO [5] RNG [6] DRAG [7] MAG [8] ASPD [9] RNGBCN
4444
*
4545
* Each element is a per-instance bitmask (bit 0 = instance 0, etc.).
4646
*/
@@ -71,7 +71,8 @@ class MavlinkStreamEstimatorSensorFusionStatus : public MavlinkStream
7171
static constexpr uint8_t IDX_RNG = 5;
7272
static constexpr uint8_t IDX_DRAG = 6;
7373
static constexpr uint8_t IDX_MAG = 7;
74-
static constexpr uint8_t IDX_ASPD = 8;
74+
static constexpr uint8_t IDX_ASPD = 8;
75+
static constexpr uint8_t IDX_RNGBCN = 9;
7576

7677
explicit MavlinkStreamEstimatorSensorFusionStatus(Mavlink *mavlink) : MavlinkStream(mavlink) {}
7778

@@ -84,7 +85,7 @@ class MavlinkStreamEstimatorSensorFusionStatus : public MavlinkStream
8485
if (_estimator_fusion_control_sub.update(&fc)) {
8586
mavlink_estimator_sensor_fusion_status_t msg{};
8687

87-
for (int i = 0; i < 9; i++) { msg.test_ratio[i] = NAN; }
88+
for (int i = 0; i < 10; i++) { msg.test_ratio[i] = NAN; }
8889

8990
// --- intended: effective CTRL values with runtime overrides ---
9091
for (int i = 0; i < 2; i++) {
@@ -103,7 +104,9 @@ class MavlinkStreamEstimatorSensorFusionStatus : public MavlinkStream
103104

104105
if (fc.mag_intended != 0) { msg.intended[IDX_MAG] = 1; }
105106

106-
if (fc.aspd_intended != 0) { msg.intended[IDX_ASPD] = 1; }
107+
if (fc.aspd_intended != 0) { msg.intended[IDX_ASPD] = 1; }
108+
109+
if (fc.rngbcn_intended != 0) { msg.intended[IDX_RNGBCN] = 1; }
107110

108111
for (int i = 0; i < 4; i++) {
109112
if (fc.agp_intended[i] != 0) { msg.intended[IDX_AGP] |= (1u << i); }
@@ -118,7 +121,8 @@ class MavlinkStreamEstimatorSensorFusionStatus : public MavlinkStream
118121
msg.active[IDX_RNG] = fc.rng_active;
119122
msg.active[IDX_DRAG] = fc.drag_active;
120123
msg.active[IDX_MAG] = fc.mag_active;
121-
msg.active[IDX_ASPD] = fc.aspd_active;
124+
msg.active[IDX_ASPD] = fc.aspd_active;
125+
msg.active[IDX_RNGBCN] = fc.rngbcn_active;
122126

123127
mavlink_msg_estimator_sensor_fusion_status_send_struct(_mavlink->get_channel(), &msg);
124128
return true;

0 commit comments

Comments
 (0)