...
Although the inputs may be angles or rates, the output of a PID should be a motor % that can be understood by each actuator.
Implementation
A new PID will be will be designed to solve the issues with the previous iteration and saved in the PID.cpp file. The goal is to have multiple PID controllers at the same time each with a PID controller class that can be used by multiple managers (although will be used by attitude manager at first), each object of the class will calculate their own integral & derivative terms being calculated independently, also the PID’s should will update at the same fixed frequency, so that derivative and integral calculations work properly. There are 2 motors per prop on the drone, a yaw servo motor and a roll BLDC (brushless DC) motor. Thus, a wrapper class will be designed for the PIDs so that all the yaw PIDs can be accessed/updated together and same for the roll PIDsBy having one PID instance per axis rather than one per motor the output will be cleaner and more consistent. When the PID does its computations to output, it will calculate it’s own derivative and integral values. The PID will be implemented in the PID.hpp and PID.cpp files in the Attitude Manager Folder, updating/replacing the previous PID controller.
Laslty, the PID will also need to utilize the input-map to be able to convert angles/rates into motor % when outputting. Meaning the PID input and target point will be angles/rates, however it will convert the angle/rate to a motor % before outputting so that the motor can adjust to reach the desired set point.
Fixed Time Frequency Updating:
The goal, is have all the PID controllers controller for an axis update at the same a fixed frequency, all axis do not necessarily have to update at the same frequency but the PID controllers of the same axis should. This will be implemented using freeRTOS, where , the wrapper class will have an update method in which it uses the vTaskDelayUntil function from freeRTOS PID update method will use a task and vTaskDelayUntil from freeRTOS, to ensure that the roll or yaw PIDs update at the same frequencycontroller for an axis is updating at a fixed frequency. When an object of the class is instantiated one of the parameters will be the frequency at which the PID should update.