Giter Site home page Giter Site logo

pid's People

Contributors

pms67 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pid's Issues

Question about function

Hello, I would like to ask how the finally function 'TestSystem_Update' in the file 'PID_Test.c' comes from and what is the specific significance. Thank you~

Issue with D component

Code now (bi-linear transform):

pid->differentiator = -(2.0f * pid->Kd * (measurement - pid->prevMeasurement)
                        + (2.0f * pid->tau - pid->T) * pid->differentiator)
                        / (2.0f * pid->tau + pid->T);

if you assume tau = 0, e[n] - e[n-1] = 0, then you'll get: D[n] = D[n-1], so it keeps always the previous value (and doesn't go to 0).
if you assume tau >>T, e[n] - e[n-1] = 0, then you'll get: D[n] = -1*D[n-1], so it keeps oscillating (and doesn't go to zero).

After reviewing other sources, I suggest using Backward-Euler transform s→(z-1)/z, then you'll get:

D[n] = K[d]/(tau + T)*(e[n] - e[n-1]) + tau/(tau + T)*D[n-1] // classical form
D[n] = K[d]/(tau + T)*(measurement[n-1] - measurement[n]) + tau/(tau + T)*D[n-1] // derivative on measurement

in this case it works as expected, for both "test cases" from above, if e[n] - e[n-1] = 0 then D[n] = 0

Pid

#include <stdio.h>

#define KP 2.0
#define KI 0.5
#define KD 0.1

float setpoint = 25.0;
float error, last_error, integral, derivative;
float temperature[3], pwm_output[3];

void read_temperature()
{
// read temperature from sensors and store in temperature array
}

void update_pid()
{
// calculate error value
error = setpoint - temperature[0];

// calculate integral term
integral += error;

// calculate derivative term
derivative = error - last_error;

// calculate PID output
pwm_output[0] = KP * error + KI * integral + KD * derivative;

// limit PWM output to a safe range
if (pwm_output[0] > 255) pwm_output[0] = 255;
if (pwm_output[0] < 0) pwm_output[0] = 0;

// update last_error
last_error = error;

// set PWM output to thermoelectric cooler
}

int main()
{
// initialize integral and last_error
integral = 0.0;
last_error = 0.0;

while (1)
{
read_temperature();
update_pid();
}

return 0;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.