How nickrehm/drehmflight works
Project type and purpose
• This is an embedded, Arduino-style flight controller for VTOL (vertical take-off and landing) aircraft, running on a Teensy 4.0/4.1 microcontroller.
• It stabilizes multirotor and VTOL airframes by reading IMU data, processing control loops, and driving motors/servos.
File structure
• Top-level:
• LICENSE, README.md, documentation PDF
• Versions/…: Separate Beta releases, each contains two .ino sketches and a src/ directory
• .ino files:
• dRehmFlight_Teensy_BETA_x.x.ino – main application (setup, loop, control algorithm)
• radioComm.ino – telemetry & radio-link routines
• src/ subdirectories: Modular hardware drivers and utility code for each version:
• MPU6050, MPU9250 – IMU drivers
• SBUS, DSMRX – RC receiver protocols
• TFMPlus – motor-mixing library
• elapsedMillis.h – timing utility
Key insights from README
• Hardware: Teensy 4.x MCU, MPU6050 IMU, optional Spektrum DSM
• Software: Arduino IDE + Teensyduino
• Purpose: rapid-prototype, educational flight controller with on-board calibration & arming
Main components
a. Hardware layer
• Teensy 4.x MCU (CPU, Memory, GPIO)
• Power supply / voltage regulators
• IMU sensors (MPU6050 / MPU9250) connected via I2C
• RC input (SBUS or DSM satellite) on UART or dedicated pin
• ESC/motor outputs (PWM or digital)
• Telemetry radio (optional serial link)
b. Software layer
• Boot & Initialization (pin mapping, sensor init, calibration routines)
• Sensor Drivers (I2Cdev, MPU6050, MPU9250 modules)
• RC Receiver Drivers (SBUS.cpp/h, DSMRX.cpp/h)
• Control Core (flight stabilization loop, PID controllers, mixer via TFMPlus)
• RadioComm module (telemetry packet formatting, serial comms)
• Utility modules (elapsedMillis timer, math helpers)
Relationships and interactions
• On each loop iteration:
1. Read raw IMU data via sensor drivers → filter/scale
2. Read pilot stick commands from RC driver → map to desired attitudes
3. Pass sensor + pilot inputs to Control Core → compute motor/servo outputs
4. Use TFMPlus mixer to convert attitude commands into ESC/servo PWM signals
5. Send telemetry out via radioComm module
• Calibration & arming routines run in setup or on special stick commands
Architectural patterns & design principles
• Modular driver layer: each hardware interface isolated in its own .cpp/.h
• Single-threaded, periodic main loop (typical embedded control loop)
• Separation of concerns: drivers vs. control logic vs. comms
• Versioning via separate directories to maintain backward compatibility
• Clear labels for each hardware and software component
• A boundary around the MCU block delineating “on-board software modules” vs. external peripherals