Motion Control

Except for the fabrication, the mechanical aspects of this project are pretty simple. The grinder and water heater need to be positioned over the French press beaker, and the coffee needs to be stirred.

I liked the laboratory-apparatus vibe of the prototype, so really all I needed to do was rotate the vertical rod back and forth. I considered various worm-gear arrangements and gearboxes but eventually decided that this was well-worn ground, and I bought a high-torque hobby servo. By using two tie rods and a custom-made horn, I was able to reduce backlash and side load on the servo's bearing considerably.

Mechanically, this proved to be a good choice as the servo was small, easy to mount, cheap, and plenty powerful to move the grinder and water heater.

Unfortunately, the analog servo I purchased provided no way to control its acceleration, and with the relatively high mass it was moving, abrupt motions were unwelcome. Worse, it also turned out to be very susceptible to electrical noise generated by the grinder motor. Finally, on startup the servo would jump to its commanded position from wherever it happened to be, which in many cases caused huge sudden movements when the system was turned on.

The solution was to implement my own motor controller in the Arduino, directly reading the servo's potentiometer and driving its motor directly -- something I was interested in doing anyway after getting a brief taste of PID controllers while helping a friend build a quadcopter controlled by the AeroQuad software. After a quick dissection and the purchase of a small H-bridge chip, the hardware side was complete.

First-pass: P-only with fixed accel/decel

Since I wanted to move forward with the project while learning about PID controllers and how to implement them in Arduino, I wrote a quick and dirty P-only controller. The motion to be controlled in this case is very simple -- the movement is always the same, speeds and forces are low, there are unlikely to be any external disturbances, and while I'd love the motion to be exactly the same no matter what, in practice I don't care as long as there aren't any wild movements and the final position is correct. This makes a high-performance controller less important. So I wrote a controller with a fixed P-value as well as fixed accel and decel values. I added a few hard-coded tweaks to account for some quirks in the motor itself, and now have a surprisingly workable, consistent motion.

Writing a PID

In progress...