fumimaker/drone_meishi

Real-time flight control on a microcontroller is never straightforward, especially when combining high-frequency sensor fusion and motor control with asynchronous web communication. drone_meishi is an ESP32-based micro drone firmware that manages this balance by running a 500 Hz control loop for IMU sensor fusion and PID stabilization, while simultaneously serving a WebSocket-driven Web UI for joystick input and telemetry.

What drone_meishi does and its architecture

drone_meishi is a flight controller firmware written in C++ targeting the ESP32 microcontroller. It implements an inertial measurement unit (IMU) sensor fusion algorithm to estimate the drone’s attitude from gyro and accelerometer data. Using this estimate, it runs PID controllers to stabilize the drone’s orientation, outputting motor commands via 20 kHz PWM signals to the ESCs.

The control loop runs at a fixed frequency of 500 Hz, which means the firmware reads sensor data, performs sensor fusion, runs PID calculations, and updates motor outputs every 2 milliseconds. This tight loop ensures precise and timely control needed for stable flight.

Alongside the control loop, the firmware runs an asynchronous web server using the ESPAsyncWebServer and AsyncTCP libraries within the Arduino IDE toolchain. This server hosts a WebSocket interface for a web-based UI that lets users send joystick commands at 50 Hz and receive telemetry updates at 20 Hz.

The architecture balances real-time control on one core of the ESP32 with asynchronous I/O handled by the networking stack. Sensor calibration routines for gyro and accelerometer are included, along with configurable PID gains exposed via the web UI. Safety features include an arming delay of approximately 800 milliseconds and automatic disarming if the drone tilts beyond about 80 degrees.

Why the real-time concurrency approach stands out

The standout aspect of drone_meishi is how it achieves deterministic timing for its 500 Hz control loop while simultaneously running an asynchronous WebSocket server on the same microcontroller. The ESP32’s dual-core architecture is typically leveraged for concurrency, but drone_meishi carefully manages timing and interrupt priorities to avoid jitter in the control loop.

Running sensor fusion and PID control at 500 Hz demands strict timing because any delay or jitter can destabilize flight. Motor PWM at 20 kHz further requires precise timing to produce smooth motor signals.

Meanwhile, the WebSocket runs at a much lower frequency — joystick input at 50 Hz and telemetry at 20 Hz — but these asynchronous network events can still introduce latency or jitter if not carefully isolated from the control loop.

The tradeoff here is complexity versus resource constraints. Using the ESPAsyncWebServer and AsyncTCP libraries brings robust networking features but requires careful architecture to avoid interrupt or task interference with the real-time loop. drone_meishi manages this by segregating responsibilities and tuning loop priorities.

The code quality shows a focus on minimal dependencies and leveraging the Arduino toolchain familiar to many embedded developers. The inclusion of safety features like auto-disarm on excessive tilt and an arming delay reflects real-world operational considerations.

Explore the project

The repository is in C++ and organized around core firmware files that implement IMU reading, sensor fusion, PID control, motor output, and the WebSocket server. The README provides an overview of features and key metrics:

  • Control loop at 500 Hz
  • Motor PWM output at 20 kHz
  • WebSocket joystick input at 50 Hz
  • Telemetry updates at 20 Hz
  • Arming delay about 800 ms
  • Auto-disarm when tilt exceeds ~80°

The code depends on ESPAsyncWebServer and AsyncTCP, which are standard in ESP32 Arduino projects for asynchronous networking. The firmware builds with the Arduino IDE toolchain.

Since there is no explicit installation or quickstart command list, the best way to get started is to clone the repo, explore the source files focusing on imu.cpp, pid.cpp, motor.cpp, and webserver.cpp (or similarly named files). The README and code comments provide context on calibration and configuration.

Users familiar with ESP32 development and the Arduino environment will find the DX straightforward. Understanding the control loop timing and asynchronous event handling is key to grasping the firmware’s design.

Verdict

drone_meishi is a solid example of embedded real-time flight control firmware that integrates modern asynchronous web communication on a resource-constrained microcontroller. It’s well-suited for developers interested in drone control algorithms, embedded concurrency, and telemetry via WebSocket.

Its main limitation is that it targets a specific hardware platform (ESP32) and assumes familiarity with embedded C++ and Arduino tooling. The project does not provide extensive onboarding or hardware abstraction, so it’s less beginner-friendly.

That said, the codebase is surprisingly clean and pragmatic for its domain. The safety mechanisms and adjustable PID gains exposed through a web UI represent thoughtful real-world considerations. For engineers working on micro drone firmware or real-time embedded systems combining control loops with asynchronous networking, drone_meishi offers valuable insights and a practical reference implementation.

// Example snippet: WebSocket control input frequency
const int WS_CONTROL_INPUT_HZ = 50;
// Control loop at 500 Hz ensures tight flight control timing
const int CONTROL_LOOP_HZ = 500;

void loop() {
  // Run IMU sensor fusion and PID
  runControlLoop();
  // Handle WebSocket events asynchronously
  webSocket.loop();
}

Overall, drone_meishi balances real-time flight control precision with modern web telemetry on a single ESP32 core — a noteworthy technical achievement in embedded drone software.


→ GitHub Repo: fumimaker/drone_meishi ⭐ 162 · C++