PD Control of Micromouse Motor Control Using MPU6050 - Role, Why, Straight Motion , Correction Formula

 

PD Control of Micromouse Motor Control Using MPU6050 - Role, Why, Straight Motion , Correction Formula

A Micromouse robot requires fast and stable motion control to navigate maze cells accurately at high speed. One of the most commonly used control methods is the PD (Proportional-Derivative) controller combined with the MPU6050 inertial sensor. This approach helps the robot maintain straight movement, improve turning precision, and reduce oscillation during acceleration and braking.


Role of MPU6050 in Micromouse

The MPU6050 contains:

  • 3-axis gyroscope
  • 3-axis accelerometer
  • Digital Motion Processor (DMP)

For Micromouse robots, the gyroscope is especially important because it measures angular velocity. The robot can detect unwanted rotation while moving and immediately correct motor speeds.

Typical uses include:

  • Heading correction
  • Accurate 90° turns
  • Angular velocity measurement
  • Drift compensation
  • Motion stabilization


Why Use MPU6050 with PD Control?

Encoder-only control sometimes cannot detect:

  • Wheel slip
  • Uneven motor torque
  • Surface friction differences
  • Sudden rotational drift

Using the MPU6050 allows the controller to measure actual rotational movement instead of relying only on wheel encoders.

Benefits include:

  • Better straight driving
  • Smoother turns
  • Faster recovery from disturbances
  • Reduced oscillation
  • Improved maze accuracy


Straight Motion PD Control

When the Micromouse moves forward, the desired angular velocity should ideally remain zero.

The error becomes:

e=\omega_{target}-\omega_{gyro}

Where:

  • (\omega_{target}) = desired angular velocity
  • (\omega_{gyro}) = measured gyro angular velocity

If the robot drifts left or right, the gyroscope detects rotation and the PD controller changes motor PWM values.

Example:

  • Robot drifts left
  • Gyroscope detects positive rotation
  • Controller reduces left motor speed
  • Controller increases right motor speed
  • Robot returns to center


PD Motor Correction Formula

Motor correction is commonly calculated as:

correction=K_p(error)+K_d(error-previous_error)

Motor PWM values become:

PWM_{left}=base-correction

PWM_{right}=base+correction

This creates automatic balancing between both motors.


MPU6050 Data Reading

The MPU6050 usually communicates with microcontrollers through I2C.

Typical data flow:

  1. Initialize MPU6050
  2. Read gyroscope registers
  3. Convert raw gyro data
  4. Calculate angular velocity
  5. Apply PD algorithm
  6. Update PWM output

The gyroscope Z-axis is most commonly used for Micromouse heading control.


STM32 Example Architecture

Many Micromouse robots use the STM32F411CEU6 because it provides:

  • Fast timer peripherals
  • Hardware PWM generation
  • I2C communication
  • Interrupt support
  • Floating-point performance

Typical peripheral configuration:

PeripheralPurpose
TIM1/TIM2Encoder interface
TIM3/TIM4PWM motor control
I2C1MPU6050 communication
UARTDebugging
EXTI/Timer InterruptControl loop timing

Basic PD Control Loop

A Micromouse control loop usually runs at:

  • 500 Hz
  • 1 kHz
  • 2 kHz

Fast loops improve stability and response time.


Importance of Derivative Control

Without derivative control:

  • Robot oscillates
  • Motion becomes unstable
  • Turning overshoots occur

The derivative term predicts future error movement and dampens oscillation.

Advantages:

  • Faster stabilization
  • Reduced overshoot
  • Smoother movement
  • Better cornering


Gyroscope Calibration

Before motion starts, gyro offset calibration is essential.

Common method:

  1. Keep robot stationary
  2. Read gyro data multiple times
  3. Average readings
  4. Store bias value

Corrected gyro value:

gyro_{corrected}=gyro_{raw}-bias

Without calibration, the robot may slowly rotate even when standing still.


Combining Encoders and MPU6050

Advanced Micromouse robots combine:

  • Wheel encoders
  • Gyroscope
  • Wall sensors

Encoder advantages:

  • Distance accuracy

Gyroscope advantages:

  • Heading accuracy

Together they provide:

  • Reliable positioning
  • Stable movement
  • Accurate turning

This technique is often called sensor fusion.


Turn Control Using MPU6050

The gyroscope is extremely useful for precise turning.

For a 90-degree turn:

  1. Start rotation
  2. Integrate gyro angular velocity
  3. Calculate angle
  4. Stop motors at target angle

Angle estimation:

\theta=\int \omega dt

This allows smooth and highly repeatable turns.


Conclusion

Using a PD controller with the MPU6050 is one of the most effective methods for Micromouse motor control. The gyroscope provides real-time rotational feedback while the PD controller continuously corrects motor output for stable and accurate movement.

When combined with wheel encoders and a fast microcontroller such as the STM32F411CEU6, the system can achieve smooth straight-line motion, precise turns, and reliable maze navigation required for competitive Micromouse robots.

Comments

Popular posts from this blog

How to Build a Micromouse Robot - Mechanical, Hardware, Software

Micromouse Competitions - Types, Overview, Comparison, Advantages, Worldwide

Complete Guide to Micromouse Maze - Dimensions, Structure and Components, Building