From f172c2fd036be67b845d72bbdfbb1241732db95e Mon Sep 17 00:00:00 2001 From: rishabsingh3003 Date: Thu, 10 Apr 2025 17:10:39 -0400 Subject: [PATCH] AP_NavEKF: Allow EK3 cores to run different sources --- libraries/AP_NavEKF/AP_NavEKF_Source.cpp | 62 ++++++++++++------------ libraries/AP_NavEKF/AP_NavEKF_Source.h | 36 ++++++++++---- 2 files changed, 57 insertions(+), 41 deletions(-) diff --git a/libraries/AP_NavEKF/AP_NavEKF_Source.cpp b/libraries/AP_NavEKF/AP_NavEKF_Source.cpp index ececde2d870..2608a14bced 100644 --- a/libraries/AP_NavEKF/AP_NavEKF_Source.cpp +++ b/libraries/AP_NavEKF/AP_NavEKF_Source.cpp @@ -134,8 +134,8 @@ const AP_Param::GroupInfo AP_NavEKF_Source::var_info[] = { // @Param: _OPTIONS // @DisplayName: EKF Source Options - // @Description: EKF Source Options - // @Bitmask: 0:FuseAllVelocities, 1:AlignExtNavPosWhenUsingOptFlow + // @Description: EKF Source Options. Bit 0: Fuse all velocity sources present in EK3_SRCx_VEL_. Bit 1: Align external navigation position when using optical flow. Bit 3: Use SRC per core. By default, EKF source selection is controlled via the EK3_SRC parameters, allowing only one source to be active at a time across all cores (switchable via MAVLink, Lua, or RC). Enabling this bit maps EKF core 1 to SRC1, core 2 to SRC2, etc., allowing each core to run independently with a dedicated source. + // @Bitmask: 0:FuseAllVelocities, 1:AlignExtNavPosWhenUsingOptFlow, 3: UsePerCoreEKFSources // @User: Advanced AP_GROUPINFO("_OPTIONS", 16, AP_NavEKF_Source, _options, (int16_t)SourceOptions::FUSE_ALL_VELOCITIES), @@ -165,14 +165,14 @@ void AP_NavEKF_Source::setPosVelYawSourceSet(AP_NavEKF_Source::SourceSetSelectio } // true/false of whether velocity source should be used -bool AP_NavEKF_Source::useVelXYSource(SourceXY velxy_source) const +bool AP_NavEKF_Source::useVelXYSource(SourceXY velxy_source, uint8_t core_index) const { - if (velxy_source == _source_set[active_source_set].velxy) { + if (velxy_source == _source_set[getActiveSourceSet(core_index)].velxy) { return true; } // check for fuse all velocities - if (_options.get() & (uint16_t)(SourceOptions::FUSE_ALL_VELOCITIES)) { + if (option_is_set(SourceOptions::FUSE_ALL_VELOCITIES)) { for (uint8_t i=0; i= AP_NAKEKF_SOURCE_SET_MAX) { + // we need to return a valid source set + return active_source_set; + } + return core_index; + } + return active_source_set; + } + // get current position source - SourceXY getPosXYSource() const { return _source_set[active_source_set].posxy; } - SourceZ getPosZSource() const; + SourceXY getPosXYSource(uint8_t core_index) const { return _source_set[getActiveSourceSet(core_index)].posxy; } + + SourceZ getPosZSource(uint8_t core_index) const; // set position, velocity and yaw sources to either 0=primary, 1=secondary, 2=tertiary void setPosVelYawSourceSet(SourceSetSelection source_set_idx); uint8_t getPosVelYawSourceSet() const { return active_source_set; } // get/set velocity source - SourceXY getVelXYSource() const { return _source_set[active_source_set].velxy; } - SourceZ getVelZSource() const { return _source_set[active_source_set].velz; } + SourceXY getVelXYSource(uint8_t core_index) const { return _source_set[getActiveSourceSet(core_index)].velxy; } + SourceZ getVelZSource(uint8_t core_index) const { return _source_set[getActiveSourceSet(core_index)].velz; } // true/false of whether velocity source should be used - bool useVelXYSource(SourceXY velxy_source) const; - bool useVelZSource(SourceZ velz_source) const; + bool useVelXYSource(SourceXY velxy_source, uint8_t core_index) const; + bool useVelZSource(SourceZ velz_source, uint8_t core_index) const; // true if a velocity source is configured - bool haveVelZSource() const; + bool haveVelZSource(uint8_t core_index) const; // get yaw source - SourceYaw getYawSource() const; + SourceYaw getYawSource(uint8_t core_index) const; // align position of inactive sources to ahrs void align_inactive_sources(); @@ -88,7 +104,7 @@ public: // sensor-specific helper functions // true if any source is GPS - bool usingGPS() const; + bool usingGPS(uint8_t core_index) const; // true if source parameters have been configured (used for parameter conversion) bool configured();