Ax Ay Az 10000 Ax MULTIPLY X is from -1 to 1 Add 1 to make it 0-2. Multiple by 90 to get 0-180 angle 90 1 ADD 1 1 0 Ay MULTIPLY Y is from -1 to 1 Add 1 to make it 0-2. Multiple by 90 to get 0-180 angle 90 1 ADD 1 1 1 Az MULTIPLY Z is from -1 to 1. Add 1 to make it 0-2. Multiply by 90 to get 0-180 angle 90 1 ADD 1 1 2 1 Ax 2 Ay 3 Az myplot Az Objective


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.


Robotic Arm

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.



Rotation to Angle conversion


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.


  1. The X axis rotation is scaled, and copied to the pincer servo.
  2. The Y axis rotation controls the extender servo of the robotic arm.
  3. The Z axis rotation controls the rotation of the robotic arm. The SG-90 Servo


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.


Plotting


We also plot the rotation around the X axis as a function of time just for visualization purposes.


]]>