7 releases
new 0.2.2 | Feb 18, 2025 |
---|---|
0.2.1 | Feb 18, 2025 |
0.1.3 | Feb 16, 2025 |
#21 in Robotics
449 downloads per month
81KB
1.5K
SLoC
Overview
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.
This Rust library interfaces with RealFlight Link, enabling external flight controllers to interact with the simulator. It allows developers to:
- Send control commands to simulated aircraft.
- Receive real-time simulated flight data for state estimation and control.
- Test stabilization and autonomy algorithms in a controlled environment.
Custom aircraft models can also be created to closely match real-world designs, providing a more precise testing and development platform.
Prerequisites
- RealFlight simulator (tested with RealFlight Evolution)
- RealFlight Link enabled in simulator settings
- Open RealFlight
- Go to Settings > Physics -> Quality -> RealFlight Link Enabled
- Enable RealFlight Link
Install
To add realflight_bridge
to your Rust project, include the following in your Cargo.toml
:
[dependencies]
realflight-bridge = "0.2.1"
scopeguard = "1.2" # For safe cleanup in examples
Example Usage
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};
use scopeguard;
pub fn main() -> Result<(), Box<dyn Error>> {
// Creates bridge with default configuration (connects to 127.0.0.1:18083)
let bridge = RealFlightBridge::new(&Configuration::default())?;
// Reset the simulation to start from a known state
bridge.reset_aircraft()?;
// Disable RC input and enable external control
bridge.disable_rc()?;
// Ensure RC control is restored even if we panic
let _cleanup = scopeguard::guard((), |_| {
if let Err(e) = bridge.enable_rc() {
eprintln!("Error restoring RC control: {}", e);
}
});
// Initialize control inputs (12 channels available)
let mut controls: ControlInputs = ControlInputs::default();
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%
}
}
Control Channels
The ControlInputs struct provides 12 channels for aircraft control. Each channel value should be set between 0.0 and 1.0, where:
- 0.0 represents the minimum value (0%)
- 1.0 represents the maximum value (100%)
SimulatorState
The SimulatorState struct provides comprehensive flight data including:
-
Position and Orientation
- Aircraft position (X, Y coordinates)
- Orientation quaternion (X, Y, Z, W)
- Heading, pitch, and roll angles
-
Velocities and Accelerations
- Airspeed and groundspeed
- Body and world frame velocities
- Linear and angular accelerations
-
Environment
- Altitude (ASL and AGL)
- Wind conditions (X, Y, Z components)
-
System Status
- Battery voltage and current
- Fuel remaining
- Engine state
- Aircraft status messages
All physical quantities use SI units through the uom
crate.
Architecture Notes
The bridge must run on the same computer as the RealFlight simulator. The RealFlight Link SOAP API requires a new connection for each request, which introduces significant overhead. As a result, running the bridge on a remote host will severely limit communication throughput.
For remote operation, it is recommended to create your own efficient communication protocol between the remote host and the bridge.
Sources
The following sources were useful in understanding the RealFlight Link SOAP API:
- RealFlight developer forums
- ArduPilot RealFlight SITL: SIM_FlightAxis.h, SIM_FlightAxis.cpp
- Python Flight Axis implementation
License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~3.5MB
~58K SLoC