Lesson 31 - Enhancements to PID
Enhancements to PID
PID, while incredibly strong when tuned correctly, still has some weaknesses. For example, when the movement first starts, PID quite literally changes your motor power from 0 to 100 which can cause a whole bunch of problems with movement consistency. Furthermore, PID forward and backward movements will become very inconsistent if they are bumped by something and the robot’s heading strays off course. There are obviously many other weaknesses and potential improvements to PID but for the sake of this lesson we will be proposing solutions to these two issues. To summarize:
PID Issues:
“Jerks” the motors into high power right away (this is due to the formula to calculate PID power).
Cannot correct for heading error.
Enhancements to PID - Slew
To solve problem 1, we can implement “slew”. Slew essentially is limiting the rate of change of the speed of the robot per code loop.
For example let’s say we set our slew rate to 5. That is to say, our speed can only increase by 5 per loop. At the start of the PID movement, rather than go from 0 to 100 power, the slew would then kick in and only make the robot go at 5 power. Then in the next iteration it would go to 10 power. Then 15 and so on and so on until the slew rate catches up to the PID. This would cause the robot to progressively accelerate rather than immediately jump at the start. A video of this can be seen here.
Using our previous PID example, slew could be implemented by doing this:
Enhancements to PID - Heading Correction
To solve problem 2, very simple IMU code can be added to the PID movement functions. The new code essentially modifies each chassis sides’ power proportional to how many degrees the heading is off course. It looks like:
VERY IMPORTANT NOTE: Some of the addition and subtraction signs may need to be flipped to work for your robot, experiment with the signs when you write code for your robot.