https://github.com/eagletrt/libpid-sw
Simple implementation of a PID controller suited for all embedded devices
https://github.com/eagletrt/libpid-sw
embedded library pid-controller platformio platformio-library sw
Last synced: about 1 month ago
JSON representation
Simple implementation of a PID controller suited for all embedded devices
- Host: GitHub
- URL: https://github.com/eagletrt/libpid-sw
- Owner: eagletrt
- License: other
- Created: 2025-03-21T14:17:07.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2026-03-28T23:12:05.000Z (2 months ago)
- Last Synced: 2026-03-29T01:43:12.834Z (2 months ago)
- Topics: embedded, library, pid-controller, platformio, platformio-library, sw
- Language: C
- Homepage:
- Size: 187 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LIBPID-CONTROLLER
This library implements a simple PID (Proportional-Integral-Derivative) controller in C.
## PID Controller
A PID controller is a widely used control loop mechanism that calculates an error value as the difference between a desired setpoint and a measured process variable. It applies a correction based on proportional, integral, and derivative terms.
This type of controller is useful for maintaining stable and accurate control in various systems, such as robotics, automation, and embedded applications.
The main advantage of a PID controller is its ability to dynamically adjust its output to minimize the error over time, while its main drawback is the need for careful tuning of the `kp`, `ki`, and `kd` parameters.
> [!TIP]
> PID controllers are commonly used in embedded systems for precise control of motors, temperature regulation, and signal stabilization.
## Dependencies
This library uses [ArenaAllocator](https://github.com/eagletrt/libarena-allocator-sw/) for memory management. Make sure to initialize the arena handler structure before using any of the PID functions.
## Usage
To use this library, include the `pid-controller-api.h` header file in your program, declare a PID controller handler, and initialize it with the appropriate function before processing inputs.
```c
int main(void) {
struct ArenaAllocatorHandler arena;
arena_allocator_api_init(&arena);
struct PidController pid;
if(pid_controller_api_init(&pid, 1.0, 0.1, 0.01, 0.1, 10.0, &arena, 3) != PID_OK){
// Error handling
}
while (1) {
float status = read_sensor_value();
pid_controller_api_update(&pid, status);
float output = pid_controller_api_compute(&pid);
apply_output(output);
}
arena_allocator_api_free(&arena);
return 0;
}
```
> [!IMPORTANT]
> Remember to free the arena memory at the end of the program, even if it never ends.
For more information, check the [examples](examples) folder.