The motor is connected to a quadrature encoder to get position and velocity feedback.
To decode the signal from the encoder I created an encoder driver class, encoderDriver.Encoder which reads the position of the encoder in rotations from startup as well as other common functions of an encoder. The controller task controller.Controller uses the encoder driver to get closed loop position and velocity feedback from the motor. To facilitate debugging the decoder, I added commands to the serial coms task, nucleoserial.NucleoSerial to allow the user to reset the encoder position to zero, as well as print out the position and position change of the encoder. The state machine diagram is shown below.
Due to the complexity of this state machine, I later simplified the state machine to just collect motor position data when the controller task, controller.Controller was collecting data and transmit it back to the PC via serial. This simplified state machine is shown in week 1.