Following from my previous post on PID control, I have integrated my old test PID code into a more usable form in the GUI. I will quickly describe what the old test balancer did, and then the recent updates:
I started with the notes from this useful article as a baseline, but then built a very simple C++ class around it. I have also included some fairly standard modifications to the “vanilla” (ideal form) PID controller:
- Calculating the derivative of the process variable, rather than of the error, to avoid large and sudden outputs in response to a large increase in error.
- Prevention of integral windup by constraining the integral term and controller output between a minimum and maximum value.
I then started adding additional features built around the controller, which are:
- Derived class which works on the standard form of the PID controller
- Qt “widget” class, which displays a number of spin boxes and sliders for controlling the three gains and the output limits of the PID (as well as the min/max limits of the user controls)
- A graph to trace the set point (SP) and process variable (PV) against time
- A procedure which starts/stops the PID loop for balancing, in a separate thread (more on this below)
The aim is to control the forward/backward balance of the robot on a slanting surface. The balancing works by adjusting the ankle motors to match the pitch of the IMU link (see older posts here and here). For example, if the robot is on a board which lowered downwards by 5 degrees, the ankles will also point downwards by 5 degrees. The motor’s position is directly controlled by the IMU pitch, and the PID is actually controlling the moving speed with which the motors will reach that position. Unfortunately it’s not possible to do torque or direct speed control with the AX-12 motors.
With only some limited manual tuning, the initial results are fairly good for small and slow movements of a slopes surface, but it will need some tuning to stop the robot from oscillating at higher speeds and falling over. I will continue improving this method, possibly by using more PIDs to control the knee and hip motors at the same time. For now, here is an image of what it looks like running in the GUI: