| Crates.io | realflight-bridge |
| lib.rs | realflight-bridge |
| version | 0.4.1 |
| created_at | 2025-02-15 08:14:32.136196+00 |
| updated_at | 2025-03-15 16:08:55.54074+00 |
| description | RealFlightBridge is a Rust library that interfaces with RealFlight Link, enabling external flight controllers to interact with the simulator. |
| homepage | https://github.com/wboayue/realflight-bridge/ |
| repository | https://github.com/wboayue/realflight-bridge/ |
| max_upload_size | |
| id | 1556605 |
| size | 160,530 |
A Rust library to interface external flight controllers with the RealFlight simulator.
RealFlight is a leading RC flight simulator that provides a realistic, physics-based environment for flying fixed-wing aircraft, helicopters, and drones. Used by both hobbyists and professionals, it simulates aerodynamics, wind conditions, and control responses, making it an excellent tool for flight control algorithm validation.
RealFlightBridge is a Rust library that interfaces with RealFlight Link, enabling external flight controllers to interact with the simulator. It allows developers to:
The simulator requires a restart after enabling RealFlight Link.
Use the latest version directly from crates.io:
cargo add realflight-bridge
This library provides two main ways to connect to RealFlight:
RealFlight Link implements a SOAP API that requires a new connection for each request, this introduces significant overhead with non-local connections. Since connecting via the loopback interface has minimal overhead, running the bridge on the same host as the simulator is the recommended approach.
The following example demonstrates how to connect to RealFlight Link, set up the simulation, and send control inputs while receiving simulator state feedback.
use std::error::Error;
use realflight_bridge::{Configuration, ControlInputs, RealFlightBridge, RealFlightLocalBridge};
pub fn main() -> Result<(), Box<dyn Error>> {
// Creates bridge with default configuration (connects to 127.0.0.1:18083)
let bridge = RealFlightLocalBridge::new()?;
// Reset the simulation to start from a known state
bridge.reset_aircraft()?;
// Disable RC input and enable external control
bridge.disable_rc()?;
// Initialize control inputs (12 channels available)
let mut controls: ControlInputs = ControlInputs::default();
// sim_complete is a placeholder condition; replace with your actual simulation completion logic.
let mut sim_complete = false;
loop {
// Send control inputs and receive simulator state
let state = bridge.exchange_data(&controls)?;
// Update control values based on state...
controls.channels[0] = 0.5; // Example: set first channel to 50%
if sim_complete {
bridge.enable_rc()?;
break;
}
}
}
There are some cases where we may want to run the bridge on a computer that is not running the RealFlight simulator. For example, you may be developing on a Mac while RealFlight runs only on Windows. To support this scenario, a proxy with an efficient communication protocol was created to forward messages from a remote computer to the simulator via RealFlightBridge. This still requires a low-latency connection. It works well on wired networks or when a Mac communicates with the simulator hosted in a Parallels VM; however, I could not achieve a high enough loop frequency (you want at least 200Hz) over WiFi.
On the same machine running the RealFlight simulator, install the proxy using the following command.
cargo install realflight-bridge
You can then run it using the following command.
realflight_bridge_proxy
By default, realflight_bridge_proxy binds to 0.0.0.0:8080. This can be changed by passing the --bind-address argument to realflight_bridge_proxy.
The following example shows how your application code connects to the simulator using the proxy.
use std::error::Error;
use realflight_bridge::{RealFlightBridge, RealFlightRemoteBridge, ControlInputs};
fn main() -> Result<(), Box<dyn Error>> {
let mut client = RealFlightRemoteBridge::new("192.168.12.253:8080")?;
// Disable RC input and enable external control
client.disable_rc()?;
// Initialize control inputs
let control = ControlInputs::default();
// Send control inputs and receive update state.
let state = client.exchange_data(&control)?;
Ok(())
}
The ControlInputs struct provides 12 channels for aircraft control. Each channel value should be set between -1.0 and 1.0, where:
For example, a channel controlling a motor might only use values from 0.0 to 1.0, while a channel controlling an elevator might utilize the full range from -1.0 to 1.0.
The SimulatorState struct provides comprehensive flight data including:
Position and Orientation
Velocities and Accelerations
Environment
System Status
All physical quantities use SI units through the uom crate.
The following sources were useful in understanding the RealFlight Link SOAP API:
This project is licensed under the MIT License - see the LICENSE file for details.