To study control loops where some parameters are measured, and some outputs are set based on the measured inputs. In this demo, we measure the rotation angle of the phone around the X Y and Z axes, and control the motors of a robotic arm using these values. The rotation value can be obtained by the rotation block in the phone menu below the KuttyPy and Sensor Menus. This measures the values from the accelerometer and magnetometer inside the phone to obtain rotation values.
We need a simple robotic arm with 4 servo motors for this activity. We also need a PCA9685 servo motor controller with an I2C interface.
The rotation measurements are obtained between -1 and 1 . Since angle is between 0 and 180 degrees for each motor, we add 1 to the rotation value in order to make it 0-2 range, and then multiply by 90 to make it 0-180. Therefore, a rotation of 0 will imply a 90 Degree angle set on the corresponding servo motor.
This is the SG-90 servo motor. It has 3 connections. Vcc(5V), GND, and a PWM input. For this activity, we are using the PCA9685 PWM generator, but we can also use SQ1 or SQ2 to generate the necessary signals to drive this servo. It can consume a lot of current, so please connect a separate power supply of 5V to drive this motor.
We also plot the rotation around the X axis as a function of time just for visualization purposes.