UAV Camera Mount | 3-Axis Stabilization | FOC Motor Control | PID Tuning
This project provides a robust 3-axis gimbal controller implementation for STM32F4 microcontrollers. It features a high-frequency FOC (Field Oriented Control) loop for brushless DC (BLDC) motors, ensuring butter-smooth video footage for thermal cameras, night vision optics, and DSLRs mounted on drones or ground vehicles.
Included is a tunable Cascade PID architecture (Position, Velocity, Current) that can compensate for wind gusts and vehicle vibrations up to 50Hz.
gimbal-stabilization foc-control bldc-driver stm32-firmware uav-camera control-theory robotics
The controller operates at 20kHz for current loop and 1kHz for position loop.
graph TD
A[IMU (Gyro/Accel)] -->|SPI 8MHz| B[Sensor Fusion (Mahony Filter)];
B -->|Quaternion| C{Position PID};
C -->|Velocity Setpoint| D{Velocity PID};
D -->|Torque/Iq| E{Current Vector Control (FOC)};
E -->|SVPWM| F[MOSFET Half-Bridges];
F -->|3-Phase Power| G[BLDC Motor];
| Port | Pin | Description |
|---|---|---|
| IMU_SPI | PA5/6/7 | SPI1 to MPU6050/ICM20602. Keep traces short! |
| MOTOR_PITCH | PA8/9/10 | TIM1 PWM High-side. |
| MOTOR_ROLL | PB13/14/15 | TIM1 PWM Low-side (Complimentary). |
| UART_CMD | PA2/3 | MAVLink input from Flight Controller. |
| AUX_ADC | PC1 | Temperature monitoring for thermal drift compensation. |
Standard rubber dampeners often fail at high zoom levels ( > 10x).
Comparison of Stabilization Precision:
- Standard PID (Open Source): +/- 0.05° (Good for wide angle)
- TwinsGlow 'Active-Damping' Algorithm: +/- 0.002° (Required for long-range thermography)
Note: This repo implements the Standard PID. The Active-Damping module relies on proprietary MEMS gyro characterization and is not included.
This firmware is widely used in DIY cinematography and FPV racing.
For Industrial & Defense Applications such as:
- Geo-Referenced Targeting (incorporating GPS/Compass data)
- heavy-Lift Payloads (> 5kg optics)
- Extreme Environment Operation (-40°C to +85°C)
👉 Explore the TwinsGlow Industrial Gimbal Series.
Our commercial units feature direct-drive torque motors with 14-bit encoders and automated auto-tune capabilities that adapt to payload changes in seconds.
- Laser-Target-System-Firmware - Combine with gimbal for auto-tracking.
- mmWave-Radar-Tactical-Tracking - Radar-assisted pointing.