GY-63_MS5611/libraries/PID_RT/README.md

149 lines
4.8 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/PID_RT/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-11-12 07:52:09 -05:00
[![Arduino-lint](https://github.com/RobTillaart/PID_RT/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PID_RT/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/PID_RT/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PID_RT/actions/workflows/jsoncheck.yml)
2023-11-14 11:40:51 -05:00
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/PID_RT.svg)](https://github.com/RobTillaart/PID_RT/issues)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PID_RT/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PID_RT.svg?maxAge=3600)](https://github.com/RobTillaart/PID_RT/releases)
2023-11-14 11:40:51 -05:00
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/PID_RT.svg)](https://registry.platformio.org/libraries/robtillaart/PID_RT)
2021-01-29 06:31:58 -05:00
2021-11-12 07:52:09 -05:00
2021-01-29 06:31:58 -05:00
# PID_RT
2021-11-12 07:52:09 -05:00
Arduino library for PID controller.
2021-01-29 06:31:58 -05:00
2021-05-28 07:41:04 -04:00
2021-01-29 06:31:58 -05:00
## Description
The PID_RT class allows the user to instantiate a PID controller.
2023-02-12 07:01:13 -05:00
This library allows one to
- adjust the K parameters runtime.
- stop / start computing runtime.
(to be elaborated)
#### Some PID background
- https://en.wikipedia.org/wiki/PID_controller
- https://www.ni.com/nl-nl/innovations/white-papers/06/pid-theory-explained.html
- https://www.youtube.com/watch?v=wkfEZmsQqiA
E-book
- https://www.elektor.nl/pid-based-practical-digital-control-with-raspberry-pi-and-arduino-uno-e-book
2024-01-08 06:43:38 -05:00
WOKWI
- https://forum.arduino.cc/t/pid-with-simulated-heater-or-motor/1093539
2021-05-28 07:41:04 -04:00
2021-01-29 06:31:58 -05:00
## Interface
2023-02-12 07:01:13 -05:00
```cpp
#include "PID_RT.h"
```
2021-01-29 06:31:58 -05:00
### Constructor
- **PID_RT()** minimal constructor.
- **PID_RT(float sp, float Kp, float Ki, float Kd)** constructor that sets minimal parameters to get started.
2021-05-28 07:41:04 -04:00
2021-01-29 06:31:58 -05:00
### Core
2023-02-12 07:01:13 -05:00
- **void reset()** resets internals to startup (Kp == Ki == Kd == 0).
- **void setPoint(float sp)** sets the setPoint, that needs to be reached.
- **float getSetPoint()** read back the setPoint.
- **bool compute(float input)** does one iteration of the PID controller.
Returns **true** after a calculation is done.
2021-11-12 07:52:09 -05:00
Returns **false** if not computed, either due to stop flag or not yet time to do the calculation.
2021-01-29 06:31:58 -05:00
- **float getOutput()** get the last calculated output value.
2023-02-12 07:01:13 -05:00
- **bool setK(float Kp, float Ki, float Kd)** Set the initial **P I D** parameters as a group.
2021-11-12 07:52:09 -05:00
Overwrites the values set in the constructor.
2021-01-29 06:31:58 -05:00
2021-05-28 07:41:04 -04:00
2021-01-29 06:31:58 -05:00
### Start Stop
2021-11-12 07:52:09 -05:00
- **void start()** enable the PID controller to **compute()** new output values.
- **void stop()** disable the PID controller, see **compute()**.
- **bool isRunning()** return the enable/disable flag.
2021-01-29 06:31:58 -05:00
2021-05-28 07:41:04 -04:00
2022-11-22 05:48:02 -05:00
### Behaviour parameters
2021-01-29 06:31:58 -05:00
2021-11-12 07:52:09 -05:00
- **bool setInterval(uint32_t interval)** set the interval between two **compute()** calls.
Returns **true** if changed, otherwise **false**.
- **uint32_t getInterval()** read back interval set.
- **void setOutputRange(float rangeMin, float rangeMax)** tune the output range, default 0..100
- **float getOutputMin()** read back setting rangeMin.
- **float getOutputMax()** read back setting rangeMax.
- **void setReverse(bool reverse)** reverse behaviour, seldom needed.
2021-01-29 06:31:58 -05:00
- **bool getReverse()** read back the setting.
2022-11-22 05:48:02 -05:00
### K-parameters
2021-01-29 06:31:58 -05:00
- **bool setKp(float Kp)** runtime updates are allowed - at your own risk.
- **bool setKi(float Ki)** runtime updates are allowed - at your own risk.
- **bool setKd(float Kd)** runtime updates are allowed - at your own risk.
- **float getKp()** read back setting.
- **float getKi()** read back setting.
- **float getKd()** read back setting.
2022-11-22 05:48:02 -05:00
### Proportional
2021-11-12 07:52:09 -05:00
- **void setPropOnInput()** this is default behaviour.
2021-01-29 06:31:58 -05:00
- **void setPropOnError()** alternative.
- **bool isPropOnInput()** read back setting.
- **bool isPropOnError()** read back setting.
2021-05-28 07:41:04 -04:00
2021-01-29 06:31:58 -05:00
### debugging calls
- **float getInput()** read last input.
- **float getLastError()** read the last error.
2021-11-12 07:52:09 -05:00
- **uint32_t getLastTime()** get the last time **compute()** was called.
Note this value is incremented with **Interval** every iteration so it
may have some offset of the actual time. This is chosen as this way it is
almost sure that no iterations are missed.
2021-01-29 06:31:58 -05:00
2021-05-28 07:41:04 -04:00
2021-01-29 06:31:58 -05:00
## Operations
2023-02-12 07:01:13 -05:00
See examples and
- https://wokwi.com/projects/356437164264235009 (thanks to drf5n)
2021-01-29 06:31:58 -05:00
2021-11-12 07:52:09 -05:00
## Future
2023-02-12 07:01:13 -05:00
#### Must
2022-11-22 05:48:02 -05:00
- update / improve documentation
- more testing
2023-02-12 07:01:13 -05:00
#### Should
- investigate if it works as PI or P controller too.
- PI as derived or base class?
2021-11-12 07:52:09 -05:00
- add examples to test more
- improve unit test
2022-11-22 05:48:02 -05:00
2023-02-12 07:01:13 -05:00
#### Could
2022-11-22 05:48:02 -05:00
- add reference to PID book / website?
2023-02-12 07:01:13 -05:00
- move all code to .cpp
#### Wont
2023-11-14 11:40:51 -05:00
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,