Have you ever programmed your robot to drive forward, only to watch it curve off to one side? You’re not alone! Making a robot drive perfectly straight is one of the most common challenges in VEX IQ programming.
In this guide, we’ll teach you a technique called proportional control that automatically corrects your robot when it starts to drift.
Why Does My Robot Drift?
Even with identical motors and wheels, robots rarely drive perfectly straight. Here’s why:
- Motor differences - No two motors are exactly the same
- Wheel friction - One wheel might grip the floor better than the other
- Weight distribution - If your robot is heavier on one side, it will pull that direction
- Floor surface - Bumps, seams, or slippery spots affect each wheel differently
The solution? Instead of hoping the robot drives straight, we detect when it drifts and correct it automatically.
The Secret: Brain Inertial Sensor
The VEX IQ 2nd Generation Brain has a built-in inertial sensor that tracks the robot’s rotation. We can use this to detect drift:
- Robot facing forward = 0 degrees
- Robot drifts right = positive degrees (like 5°)
- Robot drifts left = negative degrees (like -5°)
By continuously checking this sensor, we know exactly when the robot is going off course.
The Basic Idea: Proportional Control
Proportional control follows a simple formula:
correction = error × kp
Where:
- error = where we want to be - where we actually are
- kp = how aggressively to correct
When the error is big (robot drifted a lot), we correct a lot. When the error is small (almost on target), we correct a little. This creates smooth, natural corrections.
The Drive Straight Function
Here’s a custom block that makes your robot drive straight using proportional control:
What Each Parameter Does
| Parameter | What It Controls |
|---|---|
rotation | Target heading (usually 0 for straight ahead) |
distance | How far to drive (in motor degrees) |
velocity | Speed (positive = forward, negative = backward) |
kp | Correction strength |
How the Correction Works
Let’s say the robot drifts 5 degrees to the right while driving forward:
- error = 0 - 5 = -5 (we’re 5 degrees off target)
- output = -5 × 1 = -5
Now we adjust the motors:
- Left motor = velocity + (-5) = slower
- Right motor = velocity - (-5) = faster
The right wheel speeds up, turning the robot back to the left and correcting the drift!
Putting It All Together
Here’s a complete program that drives straight forward and backward:
This program:
- Calibrates the inertial sensor (keep robot still!)
- Drives forward 720 motor degrees while staying at 0° heading
- Drives backward 720 motor degrees while staying at 0° heading
Tuning Your kp Value
The kp value determines how aggressively your robot corrects. Every robot is different, so you’ll need to experiment!
| kp Value | Behavior |
|---|---|
| Too low | Robot drifts, weak corrections |
| Just right | Smooth, straight driving |
| Too high | Robot wobbles back and forth |
How to tune:
- Robot still drifting? → Increase kp
- Robot wobbling? → Decrease kp
Common Problems and Fixes
Robot curves instead of going straight
- Check that Brain Inertial is calibrated (robot must be still at startup)
- Increase your kp value
Robot wobbles while driving
- Decrease your kp value
- Try slowing down the velocity
Robot drives backward when it should go forward
- Check your motor directions in the device configuration
- Make sure LeftMotor and RightMotor are on the correct ports
What’s Next?
Once you’ve mastered driving straight, you can:
- Add a turn function to rotate to specific angles
- Combine moves into complex autonomous routines
- Learn about PID control for even smoother motion
The same proportional control concept applies to turning, arm positioning, and many other robot behaviors. Master this foundation, and you’ll have a powerful tool for any programming challenge!
This technique is used by competitive VEX teams at every level. Start simple, tune your values, and watch your robot transform from a wanderer into a precision machine.