[From Bruce Abbott (2018.01.11.2330 EST)]
I’ve been playing around with my Lego Mindstorms EV3 set and came up with a demo I thought worth sharing. It implements a simple proportional control system to keep a simulated forearm level against changes in the load placed in its “hand.”
The “forearm” is the bottom arm that is holding the two Lego tires in its “hand.” The “elbow joint” is a shaft attached to an angle sensor; when the forearm is level the angle sensor reads zero degrees. The angle becomes negative if the arm falls below the horizontal and positive if the arm raises above the horizontal.
The large Lego motor at top, together with the rubber band, acts as the forearm’s flexor muscle. When the short arm attached to the motor output wheel rotates upward, this simulates the muscle contracting. The rubber band simulates the muscle’s elastic property (although in quite exaggerated form relative to real muscle!).
The angular position of the forearm is regulated by a proportional controller, which compares the reference angle (currently zero degrees or horizontal, set as a parameter) to the “joint angle” reported by the angle sensor. The difference between them (the error signal) is multiplied by the output gain factor Ko and this result sets the rotational velocity of the motor. The direction of rotation is determined by the sign of the input to the motor block and its rotational speed by the magnitude.
If the forearm angle is negative, this causes the motor to rotate so as to raise the short arm attached to its output wheel. This action pulls on the rubber band, and when the tension is high enough, lifts the arm, thus reducing the error (negative feedback). If the load is decreased (e.g., by removing the Lego tires), the stretched rubber band shortens, pulling the forearm upward and thus creating a positive forearm angle. The system responds by lowering the arm attached to the motor, thus lowering the forearm back toward the horizontal.
With a relatively heavy load, the arm tended to be driven into oscillation because of the springiness of the rubber bands. To overcome this tendency I created a dashpot made from a discarded pill bottle and a few Lego parts. As the forearm moves it raises or lowers a small wheel (serving as a paddle) inside the water-filled container, thus generating some resistance to movement that is proportional to the rate of movement of the paddle. The dashpot acts as a damper, much like a car’s shock absorbers.
Lego does not offer a stand-alone angle sensor, so I ordered one from HiTehnic. It turns out to be rather noisy electrically, and consequently, spurious angle readings are generated that occasionally cause the forearm to twitch, hence the name “Twitchie.” I tried out a smoothing algorithm but this introduced a fair amount of lag in the system’s response to changes of load without entirely eliminating the twitches, so I’ve gone back to using the unfiltered signal.
The output function of the proportional controller simply multiplies the angle error by the output gain Ko – there is no leaky integrator and, consequently, no “slowing factor.” The output gain Ko is set to around 0.5 rather than to the values we typically use in our “leaky integrator output” simulations, which typically have values from the tens to the hundreds. So here’s a nice test of your understanding – can you explain why the hardware implementation can get away without a leaky integrator in the output of the control system, and why the proper output gain is so much lower.
I’ve posted a brief (30-s) video showing Twitchie in action to my YouTube site at https://youtu.be/Y_f9FV1ymIU .
Comments?
Bruce
p.s. Adam Matic, I haven’t forgotten about your implementation, which is better than mine in that it had “muscles” acting on the limb in both directions! The challenge for me was simply to learn how to do something similar using the Lego EV3 setup. I could duplicate your setup by adding a second motor pulling on the same limb from the opposite direction – although I’d have to extensively redesign the framework to accommodate the extra muscle.
Bruce

