The Arduino needs to be programmed in order to be able to control the robot. It uses the various sensor inputs to decide what to send to the three servo motors. There are three major parts of code: the arm x-axis, the arm y-axis and the gripper. The complete code can be found here.
The x- and y- axis are operated by similar code but driven by an other potentiometer, joystick direction and servo motor. The user input is given by the reading of the joystick, the potentiometer is used as a feedback for the position of the servo motor. This is needed because the servo is hacked, thus it had the inner feedback loop removed.
The code starts with initializing the different pins and variables. Afterwards, the pins are declared as input or output in the
setup() loop of the program. In the
loop(), the values of the joystick and potentiometers are read and it follows the following flowchart.
Flowchart of the Arduino code that operates one axis of the arm
When a potentiometer is no longer between 4 and 6 turns, the arm will risk to tangle itself and precautions are made. Practically, the code will prohibit further movement of the arm in the direction that will make the reading even more out of the safe range. The movement in the opposite direction will steer the arm back towards its neutral position (5 turns) and is therefore not blocked.
A test was done to have the speed of the servo motor vary linear with the potentiometer reading. This was implemented and shown in the code for one of the axes. However, as the movement of the arm is rather slow, the code was later on switched to always set the servo motors to their maximum velocity (shown in the code for the other axis).
The code for the EMG sensor is fairly simple. The sensor gives as output a value between 0 and 1023, where a low value means that the muscle is relaxed and a high value corresponds to a tensioned muscle. The code checks in the
loop() if the reading is under or above a threshold value. This threshold can vary from person to person and need to be determined experimentally. When the value is below the threshold, the gripper wil open, otherwise, it closes.