HITL/SITL X-Plane improvements (merge of #11253)#11566
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
There was a problem hiding this comment.
Pull request overview
This PR merges and backports X-Plane HITL/SITL improvements into maintenance-9.x, introducing an updated MSP_SIMULATOR v3 protocol and adding INAV-XITL (DataRef-based) support to improve simulator integration and enable additional simulated sensors/RC features.
Changes:
- Adds MSP_SIMULATOR v3 support (2-byte flags + new HITL capability bits) and refactors simulator MSP handling for clarity.
- Extends HITL/SITL functionality (simulated current sensor, rangefinder, RC input/RSSI/failsafe, SITL-mode behavior toggles).
- Implements an INAV-XITL DataRef-based connection/state machine for X-Plane SITL, plus documentation updates for plugin usage.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/target/SITL/target.h | Removes SITL-only feature defines now promoted to common for hardware HITL use. |
| src/main/target/SITL/sim/xplane.h | Adds missing stdbool.h include and exposes simXPlaneClose(). |
| src/main/target/SITL/sim/xplane.c | Adds INAV-XITL DataRef support, connection state machine, and simulator sensor/RC injection via DataRefs. |
| src/main/target/common.h | Promotes USE_RX_SIM / USE_RANGEFINDER_FAKE to common to support HITL on non-SITL targets. |
| src/main/sensors/battery.c | Injects simulated current into current meter when HITL current sensor flag is active. |
| src/main/rx/sim.h | Updates RX sim API (const correctness) and adds failsafe setter. |
| src/main/rx/sim.c | Adds failsafe reporting for simulated RX frames. |
| src/main/navigation/navigation_pos_estimator.c | Adjusts velNED handling so MSP HITL-provided velNED is not discarded while keeping SITL workaround. |
| src/main/io/displayport_msp_osd.c | Attempts to enable OSD behavior in SITL mode through a HITL flag. |
| src/main/fc/runtime_config.h | Adds MSP v3 constants and new HITL flags; extends simulatorData_t with RC/current/rangefinder fields. |
| src/main/fc/runtime_config.c | Initializes new simulator data fields. |
| src/main/fc/fc_msp.c | Refactors MSP_SIMULATOR handling into helpers and adds v3 parsing + new HITL feature handling. |
| docs/SITL/X-Plane.md | Documents INAV-XITL plugin option for advanced SITL features. |
| docs/SITL/SITL.md | Adds SITL docs link/reference for INAV-XITL plugin alongside HITL plugin. |
| docs/development/Hardware In The Loop (HITL) plugin for X-Plane.md | Mentions INAV-XITL as the newer plugin option for recent INAV versions. |
Comments suppressed due to low confidence (2)
src/main/target/SITL/sim/xplane.c:364
- exchangeDataWithXPlane() treats only EWOULDBLOCK as the timeout case for recvfrom(), but SO_RCVTIMEO commonly yields EAGAIN. Consider accepting both EAGAIN and EWOULDBLOCK so a receive timeout doesn’t prematurely abort the exchange loop.
recvLen = recvfrom(sockFd, buf, sizeof(buf), 0,
(struct sockaddr*)&remoteAddr, &slen);
if (recvLen < 0 && errno != EWOULDBLOCK) {
return;
src/main/io/displayport_msp_osd.c:251
- drawScreen() unconditionally overwrites vtxActive based on HITL_SITL_MODE. This fights with the existing heartbeat/timeout logic (checkVtxPresent/processMspCommand) and will force vtxActive=false in normal operation, preventing MSP displayport output. Gate this assignment to SITL-only behavior, or combine it with the existing vtxActive state instead of overwriting it each frame.
static int drawScreen(displayPort_t *displayPort) // 250Hz
{
vtxActive = SIMULATOR_HAS_OPTION(HITL_SITL_MODE);
static uint8_t counter = 0;
if ((!cmsInMenu && IS_RC_MODE_ACTIVE(BOXOSD)) || (counter++ % DRAW_FREQ_DENOM)) { // 62.5Hz
return 0;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Test firmware build ready — commit Download firmware for PR #11566 234 targets built. Find your board's
|
- MSP_SIMULATOR v2/v3 protocol: refactor into readMspSimulatorValues() and mspProcessSimulatorCommand(); v3 uses 2-byte flags field - New HITL flags: HITL_RANGEFINDER, HITL_CURRENT_SENSOR, HITL_SIM_RC_INPUT, HITL_FAILSAFE_TRIGGERED, HITL_SITL_MODE - Fix GPS velocity: exclude HITL mode from validVelNE path (same as SITL) - battery.c: inject simulated current when HITL_CURRENT_SENSOR active - displayport_msp_osd.c: enable OSD vtxActive in SITL mode - runtime_config: add SIMULATOR_MSP_VERSION_3 and new HITL flag bits - common.h: promote RX_SIM and RANGEFINDER_FAKE out of SITL-only target.h - xplane.h: add stdbool.h include and simXPlaneClose() declaration - xplane.c: INAV-XITL plugin with DataRef state machine; add atomic thread safety and simXPlaneClose() from maintenance-9.x
81d5f59 to
5522945
Compare
Summary
Merges PR #11253 (Scavanger's HITL/SITL X-Plane improvements) into
maintenance-9.x, with conflict resolution and several correctness fixes identified during review.HITL_RANGEFINDER,HITL_CURRENT_SENSOR,HITL_SIM_RC_INPUT,HITL_FAILSAFE_TRIGGERED,HITL_SITL_MODEreadMspSimulatorValues()andmspProcessSimulatorCommand()for clarityHITL_CURRENT_SENSORactiveHITL_SITL_MODEflagSIMULATOR_MSP_VERSION_3constant and new HITL flag bitsUSE_RX_SIMandUSE_RANGEFINDER_FAKEpromoted from SITL-onlytarget.hto common (needed for HITL on hardware targets)stdbool.hinclude andsimXPlaneClose()declaration_Atomic connectionState_tthread safety andsimXPlaneClose()Conflict resolution
xplane.cwas the only file with merge conflicts. The PR's XITL DataRef state machine was taken and the base's improvements were applied on top:_Atomic connectionState_tfor safe cross-thread accesssimXPlaneClose()for clean resource releaseexit(0)replaced withreturn NULLsopthread_joininsimXPlaneClosecompletes cleanlysimXPlaneInitwait loop handlesDISCONNECTEDstate reached during initFixes applied during review
Several issues were identified and corrected beyond the original PR:
connectionStatedata race — declared_Atomic(xplane.c)exit(0)in listenWorker — replaced withreturn NULLfor clean shutdown (xplane.c)simXPlaneInitdisconnect handling — wait loop now exits onDISCONNECTEDand returnsfalse(xplane.c)initalized,shouldStopListenThread,initMutex,initCondwere added from the base but never read by the new state machine; removed (xplane.c)navigation_pos_estimator.c)flags=0stop packet now correctly clearsSIMULATOR_MODE_HITLand callsdisarm()instead of being a no-op (fc_msp.c)readMspSimulatorValuesis called, preserving compatibility with existing minimum-size payloads (fc_msp.c)isFailsafevolatile —USE_RX_SIMnow compiles into all hardware HITL targets; addedvolatileto prevent register caching across scheduler tasks (rx/sim.c)// dA (deciamperes; * 10 = cA)tosimulatorData.currentto match documentation style of other fields (runtime_config.h)Testing
maintenance-9.x) and PR buildCode review
Reviewed with
inav-code-reviewagent before PR creation. All identified issues addressed above.