This library provides an automated PID (Proportional-Integral-Derivative) controller for Arduino. It includes two classes:
PID: A standard PID controller for single-input single-output (SISO) control.ConcurrentPID: A concurrent PID controller that enables multiple PID instances to run simultaneously.
In order to use all the following features you need to include the concurrentPID.h header file
#include <concurrentPID.h>
Sets the proportional (Kp), integral (Ki), and derivative (Kd) gains of the PID controller.
Sets the acceptable error margin within which the goal is considered reached.
Defines the duration (in milliseconds) that the error must remain within tolerance for the PID controller to complete.
Sets the target value for the PID controller.
A function that returns the input value. Can be overridden in a subclass.
A function that outputs the calculated PID response. Can be overridden in a subclass.
Computes the PID output based on the current input, goal, and PID parameters.
Starts a loop that continuously runs the calculate() function until the goal is reached.
Checks if the current error is within the specified tolerance.
Checks if the error has remained within tolerance for the required duration.
Initializes a concurrent PID controller with an array of PID objects.
Destructor to free allocated resources.
Sets PID values (Kp, Ki, Kd) for all PID controllers.
Sets the tolerance for all PID controllers.
Sets the required time for all PID controllers.
Sets the goal for all PID controllers.
Sets PID values (Kp, Ki, Kd) for a specific PID controller.
Sets the tolerance for a specific PID controller.
Sets the required time for a specific PID controller.
Sets the goal for a specific PID controller.
Starts a loop that enables all PID controllers to run concurrently.
Create a new controller class for each unique controller inheriting from the PID class and override input and output
class Controller : public PID {
public:
float inputFunction() override {
return *input; // Read the current speed from a sensor
}
void outputFunction(float outputVal) override {
*output = outputVal; // Send the computed output to the motor
}
};create objects for each PID controller you need to use
Controller myController1;
Controller myController2;
Controller myController3;create object of the concurrentPID class and give it an array of pointers to each of your controllers
PID* array[] = {&myController1, &myController2, &myController3};
concurrentPID multiController(array, 3);set variables to each of your controllers or the concurrentPID object
multiController.setPIDvalues(10, 0.1, 1);
myController1.setPIDvalues(1.0, 0.01, 0.1);
myController1.setGoal(0);
myController1.setTolerance(1.0);
// Set the time required
multiController.setTimeRequired(1);
// Set the goal of firct controller to 100
multiController.setGoal(1 ,100);- The calculate function enables the controller to automatically perform the necesary calculations
- The start() function calls the claculate() function untill the goal is reached for a certain amount of time within a set tolerance
Both of these functions are available for both classes
This library is open-source and can be freely used and modified under the MIT License.
This library was created at the University of Cyprus Robotics CLab by me as a tool in order to be used in a maze solving robot. I thought it would be interesting if i submited it to the library manager of Arduino IDE.
Creator: Christodoulos Negkoglou, Undergraduate student at University of Cyprus
