Table of Contents

Camera Gimbal Stabilizer

Introduction

This project is a two-axis camera gimbal stabilizer, created with accessible components and control logic implemented on an STM32 microcontroller. The purpose is to stabilize a camera or mobile device against vibrations or tilting, using orientation data from an MPU6050 sensor processed through advanced filtering algorithms.

Hardware Design

Bill of Materials (BOM)

ComponentQuantitySupplierPrice/UnitLinkDatasheet
NUCLEO-F401RE Development Board1Mouser Electronics€13.13MouserSTM32F401RE Datasheet
MPU6050 Gyroscope/Accelerometer Module1Mouser Electronics€8.55MouserMPU6050 Datasheet
TowerPro MG996R Servo Motor2TowerProRON 25ClesteMG996R Specifications
Module DC-DC Step Down LM2596S2Optimus Digital12.99 RONOptimusModule Specifications
Plusivo Kit1Optimus DigitalRON 40Optimus
Acumulator LiPo GENS ACE G-Tech Soaring 7.4 V/ 2200 mA/ 30C XT601SierraRON 88Sierra

Block Diagram

The diagram above shows the complete architecture of the stabilization system. The main blocks are:

The project consists of the following main modules:

The modules interact as follows: MPU6050 provides orientation data to STM32 via I2C, STM32 processes the data through PID algorithms and generates PWM signals for the servo motors, which provide precise angular corrections to stabilize the camera platform.

The sensor processing pipeline consists of:

1. Raw data acquisition from MPU6050 via I2C
2. Conversion of raw values to physical units
3. Calculation of initial angles from accelerometer data
4. Kalman filtering to combine accelerometer and gyroscope data for stable angle estimation

Electrical Schematics

The complete electrical schematic shows in detail all connections between components, including:

Servo Motor Configuration

The TowerPro MG996R servo motors are high-torque metal gear servos with the following specifications:

The servo motors are powered through the LM2596S DC-DC step-down modules, which provide stable 6V output from a higher voltage input source.

Sensor MPU6050 Schematics

Microcontroller Pin Configuration

The STM32F401RE microcontroller is configured as follows:

Pin GroupPin NumberNameFunctionRole in Project
GPIOBPB8SCLI2C1_SCLClock for I2C communication with MPU6050
GPIOBPB9SDAI2C1_SDAData for I2C communication with MPU6050
GPIOAPA2TXUSART2_TXData transmission for debugging
GPIOAPA3RXUSART2_RXData reception for debugging
GPIOAPA6PWM1TIM3_CH1PWM signal for servo motor control (axis 1)
GPIOAPA7PWM2TIM3_CH2PWM signal for servo motor control (axis 2)
GPIOCPC13B1GPIO_Input User button for input (falling edge trigger)
GPIOAPA5LD2GPIO_OutputIndicator LED for diagnostics

I2C1 Configuration

•  Pins: PB8 (SCL) and PB9 (SDA)
•  GPIO Mode: Alternate Function Open-Drain
•  Speed: Very High Frequency
•  Alternate Function: AF4_I2C1
•  Purpose: Communication with MPU6050 motion sensor

TIM3 Configuration

•  Channels: TIM3_CH1 (PA6) and TIM3_CH2 (PA7)
•  GPIO Mode: Alternate Function Push-Pull
•  Alternate Function: AF2_TIM3
•  Purpose: PWM generation for servo motor control (50Hz, 1-2ms pulse width)

USART2 Configuration

•  Pins: PA2 (TX) and PA3 (RX)
•  GPIO Mode: Alternate Function Push-Pull
•  Alternate Function: AF7_USART2
•  Purpose: Serial debug communication (115200 baud)

I chose these pins because:

Functionality Demonstration

The image above shows the sensor hardware setup, featuring:

I have tested the functionality of the MPU6050 sensor and obtained valid orientation data. After applying the Kalman filter, the data is stable and accurate.

This image shows the servo motor used for Y axis, including the support printed 3D via Fusion 360 and the cross gear.

Here is the almost final state of the project, soldering the motor pins with the corresponding DC-DC modules.

This image represents the 3D printing moment, for supports and platform base.

Power Consumption Calculations

Estimated power consumption of the main components:

Total estimated consumption:

For powering the system, the configuration includes:

This configuration ensures stable operation with sufficient power reserves for dynamic movements and maintains servo precision under varying loads.

Software Design

Development Environment

STM32CubeIDE (includes STM32CubeMX)

Libraries Used

Current Implementation Status

The software implementation currently includes:

Project Structure and Module Interaction

The software is organized into the following modules:

The modules interact in the following sequence:

1. The main.c initializes all peripherals and configures the system clock
2. It initializes the MPU6050 sensor through the dedicated driver
3. Initial accelerometer readings are used to set the starting angles for the Kalman filter
4. Servo motors are initialized with proper PWM signal configuration
5. In the main loop, sensor data is continuously read at approximately 100Hz
6. Raw sensor data is processed through the Kalman filter to produce stable angle estimates
7. Filtered angles control the servo motors to stabilize the gimbal platform
8. Diagnostic data is output via UART for monitoring and debugging

This architecture was validated through systematic testing:

Novel Elements

The primary innovation in this implementation is the adaptation of the Kalman filter specifically for a low-cost servo-based camera gimbal stabilizer. While Kalman filtering is well-established for sensor fusion, this implementation:

This approach enables high-quality stabilization with affordable servo hardware, making professional-grade camera stabilization accessible to hobbyists and small studios while maintaining the precision advantages of servo motors.

Memory Management

The implementation includes a custom memory allocation system:

Sensor Calibration

Initial Angle Determination:

Automatic Bias Correction:

Servo Control System

The servo control implementation includes:

Optimization Techniques

Several optimizations were implemented to improve performance:

These optimizations were applied primarily in the sensor reading and filter processing routines, which represent the most computationally intensive parts of the application. The implementation achieved a stable 100Hz update rate with CPU utilization below 30%.

Laboratory Functionality Integration

The project leverages several functionalities covered in laboratory sessions:

These laboratory concepts were integrated cohesively to create a complete functional system, with each component serving a specific purpose in the overall gimbal stabilization process.

Implemented Algorithms

Kalman Filter Mathematical Model

The implemented Kalman filter follows a standard discrete-time approach for orientation estimation.

State Space Representation

The filter uses a 2×1 state vector: $$ x_k = \begin{bmatrix} \theta_k \\ b_k \end{bmatrix} $$ Where:

Prediction Step

The state prediction equation: $$ \hat{x}_{k|k-1} = F_k \cdot \hat{x}_{k-1|k-1} + B_k \cdot u_k $$ In this implementation: $$ \hat{\theta}_{k|k-1} = \hat{\theta}_{k-1|k-1} + (\omega_k - \hat{b}_{k-1|k-1}) \cdot \Delta t $$ $$ \hat{b}_{k|k-1} = \hat{b}_{k-1|k-1} $$ Where:

Update Step

The Kalman gain is calculated: $$ K_k = P_{k|k-1} \cdot H_k^T \cdot (H_k \cdot P_{k|k-1} \cdot H_k^T + R_k)^{-1} $$ In this implementation: $$ S = P_{00} + R_{measure} $$ $$ K_0 = P_{00} / S $$ $$ K_1 = P_{10} / S $$ The state is updated with the measurement: $$ \hat{x}_{k|k} = \hat{x}_{k|k-1} + K_k \cdot (z_k - H_k \cdot \hat{x}_{k|k-1}) $$ In this implementation: $$ y = \theta_{accel} - \hat{\theta}_{k|k-1} $$ $$ \hat{\theta}_{k|k} = \hat{\theta}_{k|k-1} + K_0 \cdot y $$ $$ \hat{b}_{k|k} = \hat{b}_{k|k-1} + K_1 \cdot y $$ Where:

Tuning Parameters

The filter performance depends on three key parameters:

Stability Demonstration

I used mine dataset witch represents the data read by MPU6050, located in sensor_data.txt. Example:

Raw Accel X: 2904, Y: -672, Z: 13368

Raw Gyro X: -10127, Y: -15612, Z: -1999

Filtered X: 0.78, Y: -5.20

Temp: 26.22 C

Based on many results like this, I generated, using Python, two graphics witch demonstrate the stability of this filter:

Results Obtained

Conclusions

The project successfully implements a sensor processing system for orientation tracking using an MPU6050 and Kalman filtering on an STM32 platform, coupled with precise servo motor control. The use of TowerPro MG996R servo motors provides excellent torque and precision for camera stabilization, while the LM2596S DC-DC modules ensure stable power delivery. This provides a complete and functional gimbal stabilizer system suitable for lightweight cameras and mobile devices.

Source Code and Other Resources

All project resources are available on GitHub at: https://github.com/Pletea-Marinescu-Valentin/camera-gimbal-stabilizer

Bibliography/Resources

Hardware Resources

Software Resources