Skip to content

AP_ExternalAHRS: SBG: add SITL simulator, unit tests and autotest coverage#33776

Open
tolesam wants to merge 5 commits into
ArduPilot:masterfrom
SBG-Systems:dev/sbg-add-test
Open

AP_ExternalAHRS: SBG: add SITL simulator, unit tests and autotest coverage#33776
tolesam wants to merge 5 commits into
ArduPilot:masterfrom
SBG-Systems:dev/sbg-add-test

Conversation

@tolesam

@tolesam tolesam commented Jul 20, 2026

Copy link
Copy Markdown

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)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Testing done:

  • ./waf --targets tests/test_sbg && build/sitl/tests/test_sbg: 22/22 pass
  • Tools/autotest/autotest.py build.Plane test.Plane.SBGEAHRS: passes
    (prearm, arm, takeoff, waypoints, landing)
  • Manual SITL (--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:

  • SITL: add simulated SBG INSSIM_SBG SerialDevice sending
    sbgECom 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.
  • HAL_SITL: hook up simulated SBG INS — attach with
    --serialN=sim:SBG.
  • AP_HAL: add simulated SBG INS to SIMState — same hookup for
    sim-on-hardware, guarded by AP_SIM_EAHRS_SBG_ENABLED.
  • AP_ExternalAHRS: SBG: open UART early, fix parser, add unit tests
    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.
  • autotest: add SBG external AHRS coverage — Plane SBGEAHRS
    mission test (75m final waypoint distance threshold) and SBG entry in the
    ExternalAHRS AHRS-trim backend configurations.

Samuel TOLEDANO 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
tolesam force-pushed the dev/sbg-add-test branch from f8d396f to 5874cce Compare July 20, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add SITL integration for SBG EAHRS driver

1 participant