github.com/RhysU/helm
A header-only PID controller.
|
Sample controlling a 3rd order system across a unit step in the setpoint. More...
Functions | |
static void | advance (const double h, const double a[restrict static 3], const double b[restrict static 1], const double u[restrict static 1], double y[restrict static 3]) |
Advance the temporal state of a model given by transfer function \( \frac{y(s)}{u(s)} = \frac{b_0}{s^3 + a_2 s^2 + a_1 s + a_0} \). More... | |
static void | print_usage (const char *arg0, FILE *out) |
Print usage on the given stream. More... | |
int | main (int argc, char *argv[]) |
Control the process with transfer function \( \frac{y(s)}{u(s)} = \frac{b_0}{s^3 + a_2 s^2 + a_1 s + a_0} \) across a unit step change in setpoint value. More... | |
Variables | |
static const double | default_a [3] = {1, 3, 3} |
Default process parameters. | |
static const double | default_b [1] = {1} |
Default process parameters. | |
static const double | default_f = 0.01 |
Default filter time scale. | |
static const double | default_kd = 1 |
Default derivative gain. | |
static const double | default_ki = 1 |
Default integration gain. | |
static const double | default_kp = 1 |
Default proportional gain. | |
static const double | default_r = 1 |
Default reference value. | |
static const double | default_t = 1 |
Default time step size. | |
static const double | default_T = 25 |
Default final time. | |
Sample controlling a 3rd order system across a unit step in the setpoint.
This sample can be used to test controller behavior against known good results. For example, those presented in Figure 10.2 within Chapter 10 of Astrom and Murray.
|
static |
Advance the temporal state of a model given by transfer function \( \frac{y(s)}{u(s)} = \frac{b_0}{s^3 + a_2 s^2 + a_1 s + a_0} \).
Given the process transfer function
\begin{align} \frac{y(s)}{u(s)} = \frac{b_0}{s^3 + a_2 s^2 + a_1 s + a_0} \end{align}
a matching state space model consisting of 1st order differential equations can be derived with the form
\begin{align} \frac{\mathrm{d}}{\mathrm{d}t} \begin{bmatrix} y_0(t) \\ y_1(t) \\ y_2(t) \end{bmatrix} &= \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ -a_0 & -a_1 & -a_2 \end{bmatrix} \begin{bmatrix} y_0(t) \\ y_1(t) \\ y_2(t) \end{bmatrix} + \begin{bmatrix} 0 \\ 0 \\ b_0 \end{bmatrix} u(t) \end{align}
for constants \(a_0\), \(a_1\), \(a_2\), and \(b_0\) and time-varying input data \(u(t)\). Using a semi-implicit Euler integration scheme,
\begin{align} \vec{y}\left(t_{i+1}\right) &= \vec{y}\left(t_i\right) + h \vec{f}\left(\vec{y}\left(t_{i+1}\right), u\left(t_i\right)\right) , \end{align}
yields a constant-coefficient linear problem for advancing by time \(h\):
\begin{align} \begin{bmatrix} 1 & -h & 0 \\ 0 & 1 & -h \\ ha_0 & ha_1 & 1+ha_2 \end{bmatrix} \begin{bmatrix} y_0(t_{i+1})\\y_1(t_{i+1})\\y_2(t_{i+1}) \end{bmatrix} &= \begin{bmatrix} y_0(t_i) \\ y_1(t_i) \\ y_2(t_i) \end{bmatrix} + \begin{bmatrix} 0 \\ 0 \\ b_0 \end{bmatrix} u(t_i) \end{align}
Left multiplying by the matrix cofactor and dividing by the determinant gives a form amenable to computation,
\begin{align} \begin{bmatrix} y_0(t_{i+1})\\y_1(t_{i+1})\\y_2(t_{i+1}) \end{bmatrix} &= \frac{ \begin{bmatrix} h (a_2+a_1 h)+1 & h (a_2 h+1) & h^2 \\ -a_0 h^2 & a_2 h+1 & h \\ -a_0 h & -h (a_1+a_0 h) & 1 \end{bmatrix} \left( \begin{bmatrix} y_0(t_i) \\ y_1(t_i) \\ y_2(t_i) \end{bmatrix} + \begin{bmatrix} 0 \\ 0 \\ b_0 \end{bmatrix} u(t_i) \right) }{h (h (a_0 h+a_1)+a_2)+1} . \end{align}
This routine advances \(\vec{y}(t)\) to \(\vec{y}(t + h)\) using the above result.
[in] | h | Time step \(h\) to be taken. |
[in] | a | Coefficients \(a_0\), \(a_1\), and \(a_2\). |
[in] | b | Coefficient \(b_0\). |
[in] | u | Input \(u(t)\). |
[in,out] | y | On input, state \(y_0(t)\), \(y_1(t)\), and \(y_2(t)\). On output, state \(y_0(t+h)\), \(y_1(t+h)\), and \(y_2(t+h)\). |
|
static |
Print usage on the given stream.
int main | ( | int | argc, |
char * | argv[] | ||
) |
Control the process with transfer function \( \frac{y(s)}{u(s)} = \frac{b_0}{s^3 + a_2 s^2 + a_1 s + a_0} \) across a unit step change in setpoint value.
That is, just prior to time zero process state \(y(t)\), reference value \(r(t)\), actuator signal \(u(t)\), and all of their derivatives are zero. At time zero, step change \(r(t) = 1\) is introduced. The transfer function, in conjunction with the controller dynamics, determines the controlled system response.