✦ ESP8266 DELTA-WING FLIGHT CONTROLLER ✦

F-22 NX4 EVO

ELEVON CONTROLLER · MASTERCLASS SIMULATOR · BUG-FIXED

250 Hz LOOP
MPU-6050 IMU
COMPLEMENTARY FILTER
ELEVON MIXING
AXIS SWAP FIXED
M = STAB TOGGLE
SCROLL TO EXPLORE
// LIVE SIM

F-22 Raptor 3D Masterclass Simulator

■ PASSTHROUGH
CAM: ORBIT
ALTITUDE
0m
THROTTLE
0%
ROLL
0.0°
PITCH
0.0°
L-ELEV
1500µs
R-ELEV
1500µs
L-ELEV
R-ELEV
←→Roll ↑↓Pitch W/SThr MMode TabCam RReset
Roll(fused) Pitch(fused) Gyro(raw) Accel(raw) Wind
⚙ FLIGHT CONTROLS
AILERON1500µs
ELEVATOR1500µs
THROTTLE0%
WIND GUST0%
FLIGHT MODE  M
PASSTHROUGH — raw RC
STABILISE TUNING
MAX ANGLE
P GAIN8.0
α FILTER0.980
CAMERA  Tab
ORBIT
TOP
CHASE
SIDE
FRONT
KEYBOARD
Roll   Pitch   WS Throttle (Takeoff > 50%)
M Toggle Mode   Tab Camera   Space Centre   G Gust
// 01

Architecture & Hardware

The F-22 NX4 EVO is a custom digital flight controller for RC delta-wing aircraft running on the ESP8266 with onboard 802.11 Wi-Fi. It implements elevon mixing, sensor fusion, and proportional angle-hold stabilisation in a 250 Hz control loop.

BUG FIXED — Aileron/Pitch Swap: The original simulation had swapped aerodynamic responses. Root cause: the physical F-22 right servo is mechanically reversed (revRight=true). Simulation must apply physR = −(rightOut−1500)/500 before computing moments. Without this, aileron input produces pitch moment and vice-versa.
250
Hz
Control Loop
0.98
α
Filter Coeff
8.0
µs/°
P-Gain
SignalNodeMCUGPIODirProtocolNotes
MPU-6050 SDAD2GPIO4BidirI²C DataAddr 0x68
MPU-6050 SCLD1GPIO5OutI²C Clock400 kHz fast mode
CH1 AileronD7GPIO13InRC PWM1000–2000 µs @ 50 Hz
CH2 ElevatorD8GPIO15InRC PWM1000–2000 µs @ 50 Hz
CH3 ThrottleD5GPIO14InRC PWM1000–2000 µs @ 50 Hz
CH5 ModeD0GPIO16InRC PWM<1300 PASS · ≥1300 STAB
Left ElevonD4GPIO2OutServo PWM50 Hz; revLeft configurable
Right ElevonD3GPIO0OutServo PWM50 Hz; revRight=true in hardware!
ESC/ThrottleD6GPIO12OutESC PWMDirect CH3 passthrough
// 02

Elevon Aerodynamics

The F-22 uses elevons: combined elevator+aileron surfaces. A tailless delta wing has no dedicated horizontal stabiliser, so the single trailing-edge surface pair must generate both pitch and roll simultaneously.

Pitch UP (reflex): Both elevons trailing-edge DOWN → symmetric → increases aft camber → shifts lift behind CoG → nose-up moment.

Roll RIGHT: Left elevon DOWN, right elevon UP → differential lift → rolling moment.

SERVO REVERSAL KEY: Right servo installed physically reversed. Same PWM that moves left elevon DOWN also moves right elevon DOWN — correct for pitch. The reversal creates the symmetric pitch response automatically.
PITCH — Symmetric
ROLL — Differential
// 03

Sensor Fusion & Control Math

3.1 — Complementary Filter

Two sensor sources with complementary error profiles are blended: gyro is fast but drifts; accelerometer is drift-free but noisy. The filter weights them by frequency band.

// α = 0.98, dt = 0.004s (250 Hz)
θ_fused = α·(θ_fused + ω·dt) + (1−α)·θ_accel
// Accel angle via gravity projection
θ_roll = atan2(ay, az) × 180/π
θ_pitch = atan2(−ax, az) × 180/π
SensorFast?Drifts?Noisy?
Gyro ±500°/s✓ YesLow
Accel ±4g✗ NeverHigh
CF Fused✓ CorrectedLow

Live Filter Graphs (from simulation)

Roll Axis
Pitch Axis
Fused (CF output) Gyro-only (drifts!) Accel-only (noisy)

3.2 — Corrected Aerodynamic Decoupling

// Apply servo reversal FIRST float physL = (leftOut - 1500) / 500.0f; float physR =-(rightOut - 1500) / 500.0f; // ← NEGATED // Correct decomposition float pitchSig = (physL + physR) * 0.5f; // symmetric float rollSig = (physL - physR) * 0.5f; // differential pitchMoment = pitchSig * PITCH_AUTH; rollMoment = rollSig * ROLL_AUTH;
// Angle-hold P-controller
targetAngle = (RC−1500)/500 × maxStickAngle
error = targetAngle − fusedAngle
correction = error × K_P [µs]
// Elevon mixer
Left = Neutral + PitchCorr + RollCorr
Right = Neutral − PitchCorr + RollCorr

3.3 — Interactive Mixer

MIXER INPUTS
PITCH CORR0
ROLL CORR0
TRIM L0
TRIM R0
Pitch: opposite signs L/R → symmetric → pitch.
Roll: same sign both → differential → roll.
// 04

Software & Web UI

Dual Flight Modes

PASSTHROUGH  CH5 < 1300 µs   [M key]

Raw RC deviation (±500 µs) passes directly to elevon mixer. IMU updates silently — always primed.

STABILISE  CH5 ≥ 1300 µs   [M key]

Angle-hold P-controller. Stick maps to ±maxStickAngle° target. Autopilot closes error every 4 ms. Max authority ±400 µs.

EEPROM Layout (64 bytes)

MAGIC 4B TRIM 2B BOOL 1B FLOAT 4B UNUSED
ConstantDefaultIncrease effectDecrease effect
COMP_FILTER_ALPHA0.98More gyro → faster, more driftMore accel → less drift, more noise
HOLD_P_GAIN8.0 µs/°Stronger → risk oscillationWeaker → sluggish levelling
MAX_STICK_ANGLE3.0°More agile, harder to flyGentle, strong self-levelling
MAX_CORRECTION400 µsMore autopilot authorityLimits recovery force

Wi-Fi Web UI — 192.168.4.1

09:41●●● ▲
✈ F-22 NX4 EVO
MODE: STABILISE
◈ IMU ANGLES
0.0°
0.0°
◈ CALIBRATION
Calibrate MPU
◈ SERVO TRIMS
◈ REVERSE FLAGS
Rev Left
Rev Right (hardware!)
Rev Pitch Logic
💾 Save Settings