Code Development
We started with an online library that read feedback directly from the accelerometer and converted it into degrees.
Next the program takes the calculated angle (xaxisangle) and calculates the PID errors.
Finally the controller uses the errors to output a PWM and direction signal to the motor controllers
For the reaction wheel, when the feedback method was changed to a potentiometer, the feedback was measured in steps by the Arduino depending on the variable voltage. These steps were between 0-1023. This number was converted to an angle number which could be compared to a known zero point to let the controller what it needs to do.
Finally, for the reaction wheel, it was determined that the setpoint needed to be constantly updated to avoid the reaction wheel endlessly traveling in one direction. This change was made on a KL25Z controller.
This code dynamically adjusts the target angle when the measure angle overshoots. In this way it can allow the pendulum to oscillate between to points and the wheel doesn't endlessly ramp.