i'm trying create simple pid simulator in c. simple cruise control system , have chosen model system low pas filter.
i'm having difficulty writing mathematical model in c.
i found similar question , useful answer in:
convert first order transfer function c code did not understand answer completely.
i create function accepts input (later output of pid i'd test step) , sampling time , provides me output 0 steady state.
for simplicity sake id program following transfer function g(s) = 1/(s+10) sampling rate of 0.01.
after applying tustin transformation end with: (0.004762z + 0.004762)/(z-0.9048)
how go here writing in c?
from above link answer provided was:
double firstorderlag(double input, double coeff, double dt, double *state){ // function implement discretization of continuous time first // order lag sys = coeff/(s+coeff) using tustin (bilinear) transformation. double num = (1/(1+2/coeff/dt)); // numerator double den = (1-2/coeff/dt)*num; // denominator double temp; double output; temp = input - den*(*state); output = num*(temp + (*state)); *state = temp; return output; } so in particular case num 0.004762 , den = -0.9048 i'm curious how acheived z domain transfer function.
i'm not clear pointer variable state , struggle understand rest of code.
any clarifying appreciated feel if have clear understanding of function able implement in loop simulate open loop response, feedback response , integrate pid conotroller.
Comments
Post a Comment