This code was written for a PIC32MX795F512L microprocessor on an Explorer 16/32 Board on the MPLAB X IDE. Because the code only works on the specified hardware, the focus of this repository is to show the method in which the DC motor was controlled, rather than the actual code itself.
There were 3 different types of motor controllers that were implemented
- Angle-Gap Controller
- Proportional controller
- Proportional-Integral controller
This controller is the simplest method of controlling the motor. Essentially, the motor is set to turn right if its current angle exceeds the desired angle and turn left if it is below the desired angle.
Lines 188 to 208 in 74b51d9
The second controller is the proportional controller. The block diagram of the controller is shown below.
This controller works by taking the difference between the current_angle and desired_angle, multiplying the difference by a constant named kp, then setting that value to be the velocity of the motor.
Lines 209 to 215 in 74b51d9
The last controller is the most complicated controller out of the three (relatively).
This controller is an extension of the proportional controller. The added feature is that the velocity of the motor is not only defined by the difference in current_angle and desired_angle. but also the integral of the difference.
Lines 216 to 223 in 74b51d9
What makes this controller superior to the proportional controller is that the proportional controller cannot maintain a steady motor angle under constant force. Consider the following scenario: a constant force is applied to the wheel of the motor that shifts current_angle away from desired_angle. In this case, the proportional controller will start moving the motor only when the difference in the angles is non-zero. This means the motor will go back and forth between desired_angle and slightly less/more than desired_angle, causing and oscillatory motion. On the other hand, the proportional-integral controller will be able to maintain a steady angle even under constant force.