AP_ExternalAHRS: SBG: add SITL simulator, unit tests and autotest coverage#33776
Open
tolesam wants to merge 5 commits into
Open
AP_ExternalAHRS: SBG: add SITL simulator, unit tests and autotest coverage#33776tolesam wants to merge 5 commits into
tolesam wants to merge 5 commits into
Conversation
tolesam
force-pushed
the
dev/sbg-add-test
branch
from
July 20, 2026 13:38
c9cfc98 to
f8d396f
Compare
added 5 commits
July 20, 2026 17:46
Sends sbgECom logs built from SITL flight dynamics and answers device info requests. Frames are dropped whole when the buffer is full, as partial frames desync the driver parser at high sim speedups. GNSS logs go first and at 10Hz to keep AP_GPS healthy, and baro data gets noise so AP_Baro does not flag it as stuck.
Attach with --serialN=sim:SBG.
Open the UART immediately instead of waiting for system init: boot barometer calibration only calibrates instances already producing data, so the external baro instance failed arming forever. Fix an off-by-one in parse_byte that dropped a payload of exactly SBG_PACKET_PAYLOAD_SIZE_MAX bytes. Make the sbgECom struct header independent of AP_EXTERNAL_AHRS_SBG_ENABLED so the SITL simulator can reuse the definitions without the backend. Unit tests cover the packet parser, frame sending, GPS week and status decoding, using a friend test class like AP_GPS_NMEA.
Plane SBGEAHRS mission test (75m final waypoint threshold) and SBG in the AHRS trim backend list.
tolesam
force-pushed
the
dev/sbg-add-test
branch
from
July 20, 2026 16:04
f8d396f to
5874cce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a simulated SBG INS (sbgECom protocol) to SITL, unit tests for the
SBG ExternalAHRS driver, and autotest coverage (Plane SBGEAHRS mission
test + SBG in the AHRS trim backend sweep). Also fixes two driver bugs
found while writing the tests.
Classification & Testing (check all that apply and add your own)
Testing done:
./waf --targets tests/test_sbg && build/sitl/tests/test_sbg: 22/22 passTools/autotest/autotest.py build.Plane test.Plane.SBGEAHRS: passes(prearm, arm, takeoff, waypoints, landing)
--serial4=sim:SBG, EAHRS_TYPE=8, GPS1_TYPE=21,AHRS_EKF_TYPE=11): driver init and device info exchange OK, GPS 3D fix,
position/attitude tracking home, SYS_STATUS GPS/baro/prearm bits stable
at --speedup 1, 8 and 20
Description
One commit per subsystem:
SIM_SBGSerialDevice sendingsbgECom logs (IMU_SHORT, MAG, EKF_QUAT, EKF_NAV, AIR_DATA at 25/10Hz;
GPS1_POS/GPS1_VEL/UTC_TIME at 10Hz) built from SITL flight dynamics,
and answering SBG_ECOM_CMD_INFO. Frames are dropped whole when the
buffer is full since partial frames desync the driver parser at high
sim speedups; GNSS logs are sent first and at 10Hz because AP_GPS
requires an average message delta below 215ms to report a healthy GPS;
baro data gets noise so AP_Baro does not flag the sensor as stuck.
--serialN=sim:SBG.sim-on-hardware, guarded by
AP_SIM_EAHRS_SBG_ENABLED.the update thread waited for system init before opening the UART, but
boot barometer calibration runs before that and only calibrates
instances already producing data, so the external baro could never
become healthy. Also fixes an off-by-one in parse_byte that dropped
a payload of exactly SBG_PACKET_PAYLOAD_SIZE_MAX bytes,
and makes the sbgECom struct header independent of
AP_EXTERNAL_AHRS_SBG_ENABLED so the SITL simulator can
reuse the definitions without compiling in the backend. Unit tests cover
the packet parser state machine (CRC rejection/recovery, resync,
oversized/truncated frames, full-size payload), frame sending and round
trip, GPS week computation, EKF/GPS status decoding and the message
copy helper, via a friend test class following the AP_GPS_NMEA pattern.
SBGEAHRSmission test (75m final waypoint distance threshold) and SBG entry in the
ExternalAHRS AHRS-trim backend configurations.