X-Plane SITL Testing
Test INAV firmware with X-Plane 12's realistic physics simulation for reproducing flight-related bugs.
Quick Start
Prerequisites Check
- X-Plane 12 (or X-Plane 11 demo) installed
- INAV-X-Plane-HITL plugin installed
- FlyWithLua NG+ with SlewMode (for mid-air start)
Start Testing Session
Start SITL:
cd inav/build_sitl ./bin/SITL.elfLaunch X-Plane 12:
- Select INAV Surfwing aircraft
- Choose location/airport
Connect plugin:
- Plugins → INAV HITL → Link → Connect to Flight Controller
Position aircraft (optional):
- Enable slew mode:
flightwusel/SlewMode/Toggle - Position at desired altitude
- Disable slew mode
- Enable slew mode:
Monitor via mspapi2:
from mspapi2 import MSPApi with MSPApi(tcp_endpoint="localhost:5760") as api: info, status = api.get_inav_status() print(status)
Starting Mid-Air
X-Plane doesn't have built-in mid-air start. Options:
Slew Mode Plugin (recommended):
- Install FlyWithLua NG+ for X-Plane 12
- Install SlewMode plugin from GitHub
- Toggle with
flightwusel/SlewMode/Toggle
Save/Load Situation:
- Fly to altitude, File → Save Situation
- Load situation to resume at that position
Final Approach:
- Select 3NM or 10NM final approach from airport menu
Configuration
SITL Command Line (Alternative to HITL plugin)
./bin/SITL.elf --sim=xp \
--simip=127.0.0.1 \
--simport=49000 \
--chanmap=M01-01,S01-03,S03-02,S04-04
X-Plane Settings
- Settings → General → Flight models per frame: 10
- Settings → Network → Accept incoming connections: Enabled
- Note UDP port (default 49000)
Joystick Mapping
| INAV | X-Plane |
|---|---|
| Roll | Roll |
| Pitch | Pitch |
| Throttle | Cowl Flap 1 |
| Yaw | Yaw |
| AUX1-4 | Cowl Flap 2-5 |
X-Plane REST API
Available at http://localhost:8086/api/v2/ (X-Plane 12.1.1+):
import requests
# Read aircraft position
r = requests.get('http://localhost:8086/api/v2/datarefs/sim/flightmodel/position/latitude')
# Set control surface
requests.put('http://localhost:8086/api/v2/datarefs/sim/cockpit2/controls/yoke_roll_ratio',
json={'value': 0.5})
Critical: Stopping SITL Safely
IMPORTANT: Killing SITL while the HITL plugin is connected will freeze X-Plane!
Before killing/restarting SITL:
- In X-Plane: Plugins → INAV-X-Plane-HITL → Disable
- Wait for plugin to disconnect
- Now safe to kill SITL
- After SITL restarts, re-enable the plugin
Helper script: inav/build_sitl/disconnect_xplane_hitl.py
Virtual Joystick Daemon
For automated testing without a physical joystick, use the virtual joystick daemon.
IMPORTANT: Always use the safe wrapper script to prevent lockups from FIFO blocking.
Safe Wrapper Script
Location: inav/build_sitl/xplane_scripts/joystick_cmd.sh
# Start daemon
./joystick_cmd.sh start
# Check status (verify running before sending commands!)
./joystick_cmd.sh status
# Send commands safely (includes timeout protection)
./joystick_cmd.sh calibrate # Full axis sweep for X-Plane calibration
./joystick_cmd.sh center # Center all sticks
./joystick_cmd.sh axis 0 16000 # Set roll axis
./joystick_cmd.sh axis 2 -32768 # Throttle min
./joystick_cmd.sh axis 4 32767 # AUX1 (arm) high
# Stop daemon
./joystick_cmd.sh stop
Axis Mapping
| Axis | Function | Range |
|---|---|---|
| 0 | Roll | -32768 to 32767 |
| 1 | Pitch | -32768 to 32767 |
| 2 | Throttle | -32768 to 32767 |
| 3 | Yaw | -32768 to 32767 |
| 4 | AUX1 (ARM) | -32768 to 32767 |
| 5 | AUX2 | -32768 to 32767 |
FIFO Safety Warning
NEVER write directly to /tmp/inav_joystick_cmd - this can block forever!
- If daemon isn't running, writes block indefinitely
- If FIFO was deleted while daemon runs, daemon can't receive commands
- Always use
joystick_cmd.shwhich checks state and uses timeout
See inav/build_sitl/xplane_scripts/FIFO_NOTES.md for detailed lockup prevention.
Troubleshooting
| Issue | Solution |
|---|---|
| X-Plane frozen | Killed SITL without disconnecting HITL - must restart X-Plane |
| No connection | Check UDP port 49000, firewall |
| No RC input | Verify joystick calibration in X-Plane |
| Sensors not working | Set sensor types to "FAKE" in Configurator |
| Aircraft unresponsive | Check channel mapping, ARM switch |
| SITL in FAILSAFE | HITL plugin needs joystick for RC input (see MSP RX workaround) |
| Joystick command hangs | Use joystick_cmd.sh wrapper, never write to FIFO directly |
| Virtual joystick not seen | Run ./joystick_cmd.sh start, check status before calibrating |
Full Documentation
See: claude/developer/docs/testing/xplane-sitl-testing.md
Related Skills
- build-sitl - Build SITL firmware
- msp-protocol - MSP communication with SITL
- sitl-arm - Arm SITL for testing