hayschan/pid-pwm-control-relay

uploaded 7 months ago
PID PWM Relay component for ESP-IDF

readme

## Test Example
1. Write test examples in examples/default_example.
2. Conduct tests on examples/default_example as a separate project.

## Instructions for Using the Component
1. (Note that GPIO pins must be passed using the format GPIO_NUM_5, as opposed to simply '5')
2. The style can be found in examples/default_example/main.cpp.
3. First, initialize a PWM object with the chip pin and frequency as its two arguments.
4. Next, create a PID object and pass in the coefficients KP, KI, and KD, as well as the PID name during construction.
5. Use the member functions of the PID object to set the target temperature and current temperature to calculate the corresponding duty value.

```c++
void    PID_set_temperature(double set_temperature);
void    PID_now_temperature(double now_temperature);
```

6. Pass the PID object's duty value into the PWM object for control, thereby completing one cycle of PID control.

```c++
PID pid_1(16.00,0.06,64,"pid_1"); // Create instance of PID object with kp: 16, ki: 0.06, kd: 64, and PID name:"pid_1".

PWM pwm_1(GPIO_NUM_6,0.2);        // Create instance of PWM object with GPIO output pin GPIO_NUM_6 and frequency 0.2.

pid_1.PID_set_temperature(50);   // Set target temperature.

pid_1.PID_now_temperature(25);   // Set current temperature.

pid_1.PID_calculation();         // Calculate latest duty based on target and set temperature.

pwm_1.PWM_set_dutypercent(pid_1.PID_duty_value_get());   // Output control via PWM using duty calculated by the PID object.

pwm_1.PWM_get_fireState();   // Peek the level of PWM.
```
7. If you wish to modify the values of KP, KI, and KD during the PID control process, use the PID object's function interfaces to make changes.

Links

  • Repository Repository

Supports all targets

Maintainer

  • Hays Chan <blog@haysc.tech>

License: Custom

To add this component to your project, run:

idf.py add-dependency "hayschan/pid-pwm-control-relay^1.1.0"

or download archive

Stats

  • Archive size
    Archive size: 7.21 KB
  • Downloaded in total
    Downloaded in total 160 times
  • Downloaded this version
    This version: 103 times

Badge

hayschan/pid-pwm-control-relay version: 1.1.0
|