PD Control of Micromouse Motor Control without Gyroscope - What , Why , Wall Following, PD Controller Code, Tuning PD Gains
PD Control of Micromouse Motor Control without Gyroscope - What , Why , Wall Following, PD Controller Code, Tuning PD Gains
In a Micromouse robot, motor control is one of the most important factors that determines speed, stability, and maze-solving accuracy. A poorly controlled motor system causes oscillation, drifting, overshoot, and unstable turns. To solve these problems, many Micromouse robots use a PD (Proportional-Derivative) controller.
PD control is widely used because it is relatively simple, computationally efficient, and highly effective for high-speed robotic motion. It is especially suitable for embedded systems based on microcontrollers such as STM32F411CEU6 or other ARM Cortex-M devices commonly used in Micromouse designs.
What is PD Control?
A PD controller combines two control terms:
- Proportional (P) Control
- Derivative (D) Control
The output of the controller is:
Where:
- = controller output
- = proportional gain
- = derivative gain
The controller continuously calculates the error between the target value and the measured value, then adjusts the motor output accordingly. Source :
Why PD Control is Important in Micromouse
Micromouse robots move at very high speeds inside narrow maze walls. Even small steering errors can cause wall collisions or unstable movement.
PD control helps the robot:
- Maintain straight motion
- Reduce oscillation
- Improve cornering accuracy
- Stabilize wall following
- Improve acceleration and braking
- Reduce overshoot during turns
Without proper control, the robot may continuously wobble while driving through corridors.
Proportional Control (P)
The proportional term reacts directly to the current error.
For example:
- If the robot drifts slightly to the left,
- The controller increases power to the left motor or decreases power to the right motor,
- The robot returns toward the center.
The proportional term is:
Characteristics of P Control
Advantages
- Simple implementation
- Fast response
- Easy to tune
Disadvantages
- Large may cause oscillation
- Small may produce slow correction
- Cannot fully eliminate vibration alone
Derivative Control (D)
The derivative term predicts future error by observing how fast the error changes.
The derivative equation is:
This term acts like damping in a suspension system.
If the robot begins oscillating:
- The derivative term detects rapid error changes,
- It suppresses excessive correction,
- Motion becomes smoother and more stable.
Why Micromouse Often Uses PD Instead of PID
Many industrial systems use PID control, but Micromouse robots commonly use PD control because:
- Integral control may accumulate error during rapid movement
- Integral windup can destabilize high-speed robots
- PD provides faster response
- Embedded implementation is simpler
- High-speed wall following works well without integral action
For many Micromouse systems, PD control is sufficient.
PD Control for Wall Following
Wall sensors measure the distance between the robot and maze walls.
Common sensors include infrared emitters such as:
- SFH 4550
- TEFT4300
The error is calculated as:
Where:
- = left wall sensor value
- = right wall sensor value
If the robot is centered:
- Left and right values are balanced,
- Error becomes nearly zero.
The PD controller then adjusts motor speeds.
Motor Speed Correction
The control output modifies the left and right motor PWM signals.
Example:
This creates steering correction while maintaining forward speed.
Encoder Feedback in PD Control
Accurate motor control requires wheel encoder feedback.
Magnetic encoders such as:
AS5304A
are commonly used in Micromouse robots.
Encoders provide:
- Wheel speed measurement
- Distance tracking
- Rotation feedback
- Velocity estimation
The controller uses encoder data to maintain stable velocity.
Typical PD Control Loop
A Micromouse control loop usually runs every:
- 1 ms
- 2 ms : 500Hz
- or 5 ms
Typical process:
- Read wall sensors
- Read wheel encoders
- Calculate error
- Compute derivative
- Generate control output
- Update PWM signals
Fast update rates improve stability and responsiveness.
Applied Example PD Controller Code
//*** MOTION CONTROL CONSTANTS **********************************************//
// forward motion controller constants
const float FWD_KP = 2.0;
const float FWD_KD = 1.1;
// rotation motion controller constants
const float ROT_KP = 2.1;
const float ROT_KD = 1.2;
// controller constants for the steering controller
const float STEERING_KP = 0.25;
const float STEERING_KD = 0.00;
const float STEERING_ADJUST_LIMIT = 10.0; // deg/s
float CDriveSensors::calculate_steering_adjustment(float error) {
// always calculate the adjustment for testing. It may not get used.
float pTerm = STEERING_KP * error;
float dTerm = STEERING_KD * (error - last_steering_error);
float adjustment = (pTerm + dTerm) * LOOP_INTERVAL;
// TODO: are these limits appropriate, or even needed?
adjustment = Constrainf(adjustment, -STEERING_ADJUST_LIMIT, STEERING_ADJUST_LIMIT);
last_steering_error = error;
return adjustment;
}
float CBody::position_controller() {
objMindForward.update();
// write code here what you need
fwd_error += objMindForward.increment() - objArms.robot_fwd_increment();
float diff = fwd_error - old_fwd_error;
old_fwd_error = fwd_error;
float output = FWD_KP * fwd_error + FWD_KD * diff;
return output;
}
float CBody::angle_controller() {
objMindRotation.update();
// write code here what you need
rot_error += objMindRotation.increment() - objArms.robot_rot_increment();
if (objEyes.steering_enabled) {
rot_error += steering_adjustment;
}
float diff = rot_error - old_rot_error;
old_rot_error = rot_error;
float output =ROT_KP * rot_error + ROT_KD * diff;
return output;
}
void CBody::update_motor_controllers() {
// write code here what you need
float pos_output = position_controller();
float rot_output = angle_controller();
float left_output = 0;
float right_output = 0;
left_output += pos_output;
right_output += pos_output;
left_output -= rot_output;
right_output += rot_output;
float v_fwd = objMindForward.speed();
float v_rot = objMindRotation.speed();
float v_left = v_fwd - (PI / 180.0) * MOUSE_RADIUS * v_rot;
float v_right = v_fwd + (PI / 180.0) * MOUSE_RADIUS * v_rot;
left_output += SPEED_FF * v_left;
right_output += SPEED_FF * v_right;
if (controllers_output_enabled) {
objLegs.update_motors(left_output, right_output);
}
}
This code was modified the source from GitHub's ukMars .
Tuning PD Gains
Increasing Kp
Effects:
- Faster correction
- More aggressive steering
- Higher responsiveness
Too high:
- Oscillation
- Instability
- Wall bouncing
Increasing Kd
Effects:
- Smoother motion
- Reduced overshoot
- Better damping
Too high:
- Slow response
- Weak correction
- Delayed steering
Practical Tuning Method
A common tuning procedure is:
- Set (K_d = 0)
- Slowly increase (K_p)
- Observe oscillation
- Add (K_d) gradually
- Fine-tune both gains
The goal is stable movement without vibration.
PD Control During Turning
PD control is also used during:
- Slalom turns
- 90-degree turns
- 180-degree turns
- Diagonal movement
Gyroscope sensors and encoders help maintain accurate rotational motion during high-speed cornering.
Limitations of PD Control
Although effective, PD control also has limitations:
- Sensitive to sensor noise
- Requires tuning
- Performance changes with battery voltage
- Difficult at extremely high speeds
- Derivative term amplifies noisy signals
To improve performance, advanced robots may add:
- Velocity feedforward
- Motion profiling
- State estimation
- Kalman filtering
- Cascaded control loops
Conclusion
PD control is one of the most essential technologies in Micromouse motor control systems. By combining proportional and derivative actions, the robot can achieve stable wall following, precise steering, and high-speed maze navigation.
A well-tuned PD controller allows a Micromouse robot to move smoothly through complex mazes while minimizing oscillation and maintaining accurate trajectory control. Because of its simplicity and effectiveness, PD control remains one of the most widely used control methods in competitive Micromouse robotics.

Comments
Post a Comment