I am a student using the 3pi Standard for a competition. My partner and I were doing some basic tests, and this happens when we try and drive straight. As you can see, it significantly curves to the left. We’re pretty stumped, as all the hardware seems intact and there’s nothing wrong with our code.
Motors are not identical and do not all run at the same speeds even under otherwise identical conditions.
The simplest way to make the robot run straight is to use the encoders. Count encoder pulses for a suitable interval, and if they are not the same for each motor, adjust the power to correct for the difference in counts.
One approach uses a simple PID controller and goes something like this:
count_diff = left_counts - right_counts;
set_right_speed(base_speed + Kp*count_diff); //if left has more counts, speed up the right motor
set_left_speed (base_speed - Kp*count_diff); // and slow down the left motor
Adjust base_speed and Kp (the P term in a PID controller) to suit.
Another approach with the 3Pi is to use the magnetometer as a compass to determine direction of travel, and likewise adjust motor speeds to move in the commanded direction.
3 Likes