PID ( double Kp, double Ki, double Kd, double dt, double max, double min );
double calculate ( double setpoint, double current );
cd ~/catkin_ws/src
git clone -b ros1 https://github.com/NTU-Mecatron/pid_package
For .hpp
/.h
file:
#include <pid_package/pid.h>
class YourClass {
public:
YourClass();
private:
PID your_pid_ = PID(0,0,0,0,0,0);
};
For .cpp
file:
#include "your_package/your_class.hpp"
YourClass::YourClass() {
your_pid_ = PID(1, 0.1, 0.01, 0.01, 100, -100);
}
void YourClass::yourCallback() {
double setpoint = 10;
double current = 5;
double output = your_pid_.calculate(setpoint, current);
}
You can use float
type for the PID controller as well.
Modify your CMakeLists.txt
file to include the following:
find_package(pid_package REQUIRED)
Modify your package.xml
file to include the following:
<build_depend>pid_package</build_depend>
<exec_depend>pid_package</exec_depend>