Why use a case statement in a PD loop?
The gain I used on our robot is 5 or 6… however, the output of the PD loop is then sent to our drive code, which incorporates an exponential drive algorithm.
The best thing to do is to use a printf statement right before the drive motors (or, even better, AFTER) are set–this will enable you to read EXACTLY what the drive motors are getting.
Since this may not be possible with the robots having been already shipped, I’ll give you a quick fix:
By now, since you’ve probably figured out a minimum value that DOES make the motors move the robot, set a MINIMUM speed limit. Something like…
//150 and 105 are just arbitrary numbers; replace them with the minimum speeds that turns your robot
//copy this code for each motor
if (motor_speed > 129 && motor_speed < 150)
{
motor_speed = 150;
}
else if (motor_speed < 126 && motor_speed > 105)
{
motor_speed = 105;
}
Do that for both motors, and it should limit their minimum speed. If they’re getting a value a little off center it’ll increase their speed to the value you define as a minimum. That stops them from “humming” and actually makes the robot move, even at very low speeds as defined by the PD control.
