The Code
The Beertender works by separating tasks into four separate but interdependent state machines, activated by two large buttons at the front of the machine. A seven-segment display shows the current number of beers in the queue. The big green button adds to the queue, while the red one subtracts. The state of the queue triggers the machine into action.
Sensor feedback to help determine states comes from ten sensors. A limit switch at both the near and far end of the tower’s rotational space keep the tower from colliding with the cup dispenser. Another limit switch at the shuttle’s upper apex halts the shuttle and protects against motor wear. There are four ping sensors, two in the shuttle used to measure the height of the beers being poured, and two at the front base of the tower to detect the presence of cups. A digital IR switch at the far end of the turntable (secured to one of the cup dispenser’s support poles) detects the presence of a cup, indicating the turntable is at full capacity. Twelve magnets are situated one under each of the brass cup holders, which are used by two separate hall sensors for accurate positioning; one stationary hall sensor triggers the cup dispenser, and another installed at the front base of the tower helps determine accurate rotational placement of the tower in relation to cups on the turntable.
The four state machines are as separated below.
Cup Drop State Machine
If the hall sensor has detected alignment with a magnet, the servo moves into position to drop a cup. If no magnet is detected, the servo moves into the ready position, placing one cup in the arm’s trigger area to be dropped.
Table Rotation State Machine
If the tower does not detect two cups present (determined by two ping sensors and the hall sensor at the base), then the table rotation is activated. The table only rotates in one direction. The table’s rotation is halted (and the go-state is overridden) if either the digital IR sensor detects a full table, or if the tower’s far limit switch is activated. The table is also halted if the tower is aligned with two empty cups.
Tower Rotation State Machine
If the tower’s far limit is not active and the tower does not detect two cups present, tower rotation is activated. The tower rotates in the opposite direction of the table. Its motion is determined by the internal gear attached to the turntable; if the table is rotating and the tower’s motor is halted, the tower is rotating with it. Thus, the tower’s rotation is relative to the turntable’s movement. The purpose of rotating the tower is to ratchet the tower backwards to the next available pair of cups. Once two empty cups are located, the tower's rotation in relation to the table is halted, locking the tower's position to those two cups. This state flags the Tap State Machine that it is ok to deploy the shuttle and pour beer. After one or two beers have been poured, the tower ratchets backwards one or two places, or until it finds another pair of empty cups. The ping sensors are used to make sure the shuttle is not deployed into cupholders with no cups.
Tap State Machine
On startup, the shuttle is raised to the highest position. While the queue is empty, it remains here. If the queue is changed to anything over zero, and if the tower’s state confirms alignment with two empty cups, the shuttle deploys and lowers the dispensing straws into the cups. The taps are opened according to the number in the queue. For only one beer ordered, only the right tap (as seen from the center axis) opens. For anything greater than one, both taps open. Taps are held open until the shuttle’s ping sensors detect an appropriate height, and then taps are closed. Once taps are closed, the shuttle retracts to the ready position, and the tower is triggered to begin its search for two new empty cups. The tower is not allowed to rotate while the shuttle is deployed. The table, however, is free to rotate.