2024-06-25.12-36-32.mp4
This project is a drone flight system consisting of custom flight hardware, firmware, a Raspberry Pi-based communication bridge, and a ground control station. The ultimate goal is to build a fully autonomous drone capable of takeoff/landing on a target platform.
The system is composed of three main components:
- Flight Computer with Firmware (Custom PCB with teensy 4.1 microcontroller)
- Communication Bridge (Raspberry Pi 4B)
- Ground Control Station (Desktop application using rust egui)
The flight computer is built on a perfboard with a Teensy 4.1 running custom firmware written in C++. It handles real-time flight control, sensor fusion, and motor control.
- Teensy 4.1 microcontroller
- LSM6DSOX + LIS3DML IMU
- BMP390L Barometer
- ublox M9N GPS
The firmware is modular and consists of several key components:
main.cpp
: The entry point of the firmware, handling initialization and the main control loop.filter.h
: Implements sensor fusion using a Madgwick or Mahony filter to estimate the drone's orientation.pid.h
: Implements a simplified PID controller for only roll control for testing.state.h
: Manages the drone's state and LED indicators.transmitter.h
: Handles communication with the Raspberry Pi.consts.h
: Defines constants used throughout the firmware.baro.h
: Interfaces with the barometric pressure sensor.imu.h
: Interfaces with the IMU sensor for accelerometer and gyroscope data.motor.h
: Controls the drone's motors based on the PID output. Has functions for arming, disarming, and setting motor speeds. I also contains hardware interrupt handlers if the signal is not received for a certain time.
The Raspberry Pi acts as a bridge between the flight computer and the ground control station. It runs a Rust application that:
- Communicates with the flight computer via UART
- Hosts a WebSocket server for real-time communication with the ground control station
- Optionally processes computer vision tasks (e.g., ArUco marker detection)
- Raspberry Pi 4 Model B
- Camera module (for computer vision tasks)
- Wi-Fi module for communication with the ground station
use tokio::net::TcpListener;
use tokio_serial::SerialPortBuilderExt;
use tokio_tungstenite::accept_async;
async fn handle_connection(stream: TcpStream) {
let ws_stream = accept_async(stream).await.unwrap();
let (mut ws_sender, mut ws_receiver) = ws_stream.split();
let serial = tokio_serial::new("/dev/ttyS0", 1_000_000).open_native_async().unwrap();
let (serial_reader, mut serial_writer) = tokio::io::split(serial);
// ... (WebSocket and serial communication logic)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let listener = TcpListener::bind("0.0.0.0:8765").await?;
while let Ok((stream, _)) = listener.accept().await {
tokio::spawn(handle_connection(stream));
}
Ok(())
}
The ground control station is a desktop application written in Rust using the egui. It provides a user interface for monitoring telemetry, controlling the drone, and adjusting flight parameters.
- Real-time telemetry display
- 3D attitude visualization
- PID tuning interface
- RC control emulation
- Command interface for sending instructions to the drone
mod accelerometer_view;
mod app;
mod attitude_view;
mod chat_view;
mod commands_view;
mod data;
mod drone_view;
mod pid_view;
mod rc_control;
mod rc_view;
use app::MyApp;
use eframe::egui;
fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_maximized(true),
..Default::default()
};
eframe::run_native(
"Drone Control",
options,
Box::new(move |cc| {
egui_extras::install_image_loaders(&cc.egui_ctx);
Box::new(MyApp::new())
}),
)
}
The MyApp
struct manages the overall application state and UI layout:
pub struct MyApp {
drone_view: DroneView,
attitude_view: AttitudeView,
accelerometer_view: AccelerometerView,
rc_view: RCView,
rc_control: RCControl,
pid_control: PIDControlView,
chat_view: ChatView,
commands_view: CommandsView,
received_data: Arc<Mutex<ReceivedData>>,
// ... (other fields)
}
To use this system with your own drone project:
-
Flight Computer Setup:
- Flash the custom firmware onto your microcontroller
- Connect sensors and motors according to the pin definitions in
consts.h
-
Raspberry Pi Setup:
- Install Rust locally and run
sudo apt install -y gcc-aarch64-linux-gnu
to cross-compile for the Raspberry Pi - Built the code using
cargo build --release
and copy the binary to the Raspberry Pi - Copy the binary to the Raspberry Pi and run the executable
- Install Rust locally and run
-
Ground Control Station Setup:
- Build and run the application using
cargo run --release
- Build and run the application using
- Implement full attitude control (pitch and yaw in addition to roll)
- Integrate computer vision for target tracking and landing using ArUco markers.
- Add GPS support for position hold and waypoint navigation
This project is licensed under the MIT License - see the LICENSE file for details.