Stick Balancer
Project discontinued due to practical difficulties with potentiometer coupling and drive motors being not powerful enough and the gear not robust enough to provide good acceleration of the cart with the weight of the RCX.
A Lego Mindstorms project aimed at a machine which can balance a stick (say 0.5 metres long) which can hinge in only one direction (i.e. within a plane). The project combines:
- building a competent mechanical balancing "cart"
- programming the balancer in pbForth
- design of a process control algorithm to (in order of priority):
- balance the stick (stop it from falling over)
- bring average cart velocity to zero
- bring the cart back to its starting position (assuming it wandered off while balancing)
- constructing the necessary Button "Operating System" to control the program execution
Other Issues:
- Need to have some "stops" on the stick to prevent it from getting so far away from vertical that it tips the cart over or lands on the ground.
- May need to shut-down control if stick goes past an unrecoverable angle from vertical. This will stop the cart from shooting off in one direction if the stick has come to rest on one of the movement "stops".
- May be useful to add touch sensors at each end of cart to abort balancing if the cart hits something.
Stage 1 - Build cart with simple control
The first task is to build a cart which can mechanically balance the stick. The cart at this stage looks like this:
The program (balance1.f) reads the potentiometer voltage through the normal RCX port. This needs to be converted to angle by using the voltage divider equations because the angle is not proportional to the voltage. For the 25k Ohm potentiometer used here, the equation is angle = 128*x /(1023-x) where x is the raw integer reading from the port.
The control algorithm is executed and the drive signal applied to both motors (for more traction/acceleration).
For this first stage, a very simple control algorithm was devised. The power setting for the motors was set proportional to the angle deviation from vertical (120 deg for ours) such that 30 degrees of deviation resulted in the full power setting for the motor (integer 7). The equation was power = (angle-120)*(-7)/30 .
Unfortunately, there was significant backlash (~5 deg) in the linkage between the stick pivot and the potentiometer. This would cause significant delay to the reactions of the cart. However, even with this simple control calculation (plus backlash), it was clear that the cart was making a good effort to balance the stick. On most trials it would keep the stick up for around 3 reversals of cart movement.
Proportional control of a double-integrator (approximately) process cannot eliminate the cycling of the control loop, even if there was no backlash. In fact, if you count the motor power accelerating the cart mass (including 2 motors + RCX), the process is actually rather more like a triple-integrator. Quite a task, and not surprising that the proportional control doesn't work.
Stage 2 - smarter control
Two additional pieces of information might help the control algorithm:
- The speed of movement of the stick (angular velocity) relative to the cart, and
- the speed of the cart.
Now, its a bit hard to measure the speed of the cart, so we might be able to predict the cart speed by simulating the movement of the cart given the set of motor speed commands that we have recently sent to the motors. But we need more information:
- max speed of cart = 3.8m / 4.49s = 0.85 m/s (at power=7)
acceleration (at power=7) --> from stationary, 1.0m in 1.4s (avg speed = 0.71m/s), this gets a bit technical:
- We can probably assume a first order increase in speed till full speed is reached.
But how do we calculate what the time-constant of the increase is from the data above? --> using iteration of quad integration function (integrating the exponential function of a time-constant) in SciPy.
- Time-constant = 0.23 seconds
- We should be able to use a simple filter applied to the sequence of motor speed commands, to estimate the speed of the cart.
To be continued.
Hypothesis of required control scheme
The final control scheme could be potentially complex and a hypothetical scheme is illustrated (extremely poorly, but good enough for my purposes) below:
ToDo
- try a longer stick, with a small weight on the end, to extend the effective length of the stick to its centre of gravity. This will mean the stick will take longer to respond (and accelerate downwards) thereby allowing the rather heavy cart to move quickly enough to maintain balance. Present stick has a distance to CG of about 0.5m. The new stick should be more like 2.0m.