hayschan/pid-pwm-control-relay

uploaded 3 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.
```
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.

readme of default_example example

                                        
                                        # _Sample project_

(See the README.md file in the upper level 'examples' directory for more information about examples.)

This is the simplest buildable example. The example is used by command `idf.py create-project`
that copies the project to user specified path and set it's name. For more information follow the [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project)



## How to use example
We encourage the users to use the example as a template for the new projects.
A recommended way is to follow the instructions on a [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project).

## Example folder contents

The project **sample_project** contains one source file in C language [main.c](main/main.c). The file is located in folder [main](main).

ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt`
files that provide set of directives and instructions describing the project's source files and targets
(executable, library, or both). 

Below is short explanation of remaining files in the project folder.

```
├── CMakeLists.txt
├── main
│   ├── CMakeLists.txt
│   └── main.c
└── README.md                  This is the file you are currently reading
```
Additionally, the sample project contains Makefile and component.mk files, used for the legacy Make based build system. 
They are not used or needed when building with CMake and idf.py.

                                    

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.0.0"

or download archive

Dependencies

  • ESP-IDF >=4.4.0
  • Examples:

    default_example

    more details

    To create a project from this example, run:

    idf.py create-project-from-example "hayschan/pid-pwm-control-relay^1.0.0:default_example"

    or download archive

    Stats

    • Downloaded in total
      Downloaded in total 101 times
    • Downloaded this version
      This version: 57 times

    Badge

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