CALPOLY MECHATRONICS
Documentation for all Mechatronics Labs
MOTION PROFILE TRACKING AND CONTROLLER TASK

To control the motor position and velocity using closed loop feedback I created a PID controller, pid.ClosedLoop which calculates the required motor duty cycle based on the error between a reference position and velocity and the motor's actual position and velocity.

The PID controller also calculates its performance over time, denoted as J, using the sum of the squares of the position and velocity error. J provides a metric to compare different controllers. The controller task controller.Controller uses the PID controller to move the motor along a reference motion profile.
The end goal of this project was to have the motor follow a reference profile and velocity, provided as comma separated values. To achieve this goal, I created a controller task controller.Controller which uses an encoderDriver.Encoder object, pid.ClosedLoop object, and a motorDriver.Motor object to control the motor and track the reference profile. The controller task is set up as a state machine to allow for rapid execution on the single threaded Nucleo without interrupting other tasks. In normal opperation the controller switches between waiting and moving the motor along the reference profile, as shown in Figure 1 below.

The Nucleo is very limited on memory, so having too many reference points in the reference file could cause memory problems. To avoid this, I created a script to down sample the reference csv into more managable 0.1 second increments before loading it onto the Nucleo.
While controlling the motor, the controller task also sends motor position data to the serial communication task, nucleoSerial.nucleoSerial via shares which is a script used to share data between tasks. The results of this controller design are shown on the overview page of this project.