PID code in C++ language

Status
Not open for further replies.

simon_12

New Member
Hi every1

Can someone please send me the code in C++ for PID control? The code should be like that when it is run , the window should ask for Kp, Ki , Kd and sample time? and then generates the pwm output. I will use a USB daq card for to control the motor speed.

Any help will be greatly appreciated.

Regards
Simon
 
I am not asking anyone to write code for me but if anyone has previouly done this task then it can be a source of guidance for me?
 
Code:
float pid(float setpoint, float x, float oldx, float kp, float ki, float kd, float &integrator)
{
    float err = x - setpoint;
    integrator += err;
    
    return kp*err + ki*integrator + kd*(x-oldx);
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…