Once you designed a good controller, you can save it from the
menu File
Save Controller. The controller is always saved in
RaPID format in a file with a .con extension.
You can also save the pseudo-code of the controller, as described in Section 6.6.3.
You can load previously designed controllers into RaPID as
current controllers or as benchmark controllers (see Section
6.7.2). The file has to be a RaPID controller file with
a .con extension. Note that if the sample times of current
project and controller to be loaded are not compatible, the sample
time of the project has priority.
You can also save a controller in a ``pseudo-code'' format with
the menu entry File
Save Pseudo Code. This is a format close to
C, which implements the currently designed controller. Use the
resulting .pc file for implementation of the controller on
platforms not supported by RaPID. The following contains a
pseudo-code example.
/******************************************************************************/
/*
Pseudo Code Generated by RaPID 1.0
03-Dec-1997 21:49:06
This code implements the RaPID extended PID controller
The controller runs on the project Example
Sampling time of the controller is 0.1 sec
The process input is measured in Volt
The process output is measured in Volt
The process input u[k] is actuated with the function DA_out(u[k])
The process output y[k] is measured with the function y[k] = AD_in()
The reference signal is contained in the array r[k]
*/
/******************************************************************************/
/******************************************************************************/
/* Initialization of parameters */
/******************************************************************************/
#define fb_proportional 1.0501636 /* Feedback Proportional */
#define fb_derivative 0.44972011 /* Feedback Derivative */
#define fb_double_derivative 0 /* Feedback Double Derivative */
#define ff_proportional 0.97380139 /* Feedforward Proportional */
#define ff_derivative 0 /* Feedforward Derivative */
#define ff_double_derivative 0 /* Feedforward Double Deriv */
#define pd 0 /* Pole Derivative */
#define pdd 0 /* Pole Double Deriv */
#define integral_gain 0.10079237 /* Integral Gain */
#define input_bias 0 /* Input Bias */
#define input_min -5 /* Minimal Input */
#define input_max 5 /* Maximal Input */
/******************************************************************************/
/* The controller output is computed as:
u[k] = ubias + integral_gain * sum(i=0->k) (r[i] - y[i])
- fb_proportional * y[k]
- fb_derivative * (yd[k] - yd[k-1])
- fb_double_derivative * (ydd[k] - 2*ydd[k-1] + ydd[k-2])
+ ff_proportional * r[k]
+ ff_derivative * (rd[k] - rd[k-1])
+ ff_double_derivative * (rdd[k] - 2*rdd[k-1] + rdd[k-2])
where:
yd[k] = pd*yd[k-1] + y[k]
rd[k] = pd*rd[k-1] + r[k]
ydd[k] = 2*pdd*ydd[k-1] - pdd^2*ydd[k-2] + y[k]
rdd[k] = 2*pdd*rdd[k-1] - pdd^2*rdd[k-2] + r[k]
*/
/******************************************************************************/
/******************************************************************************/
/* Control Loop
[k] indicates the sampled time index
*/
/******************************************************************************/
initial = 1; /* Need to do an initialization of the variables */
while (~stop_flag) {
/* Measure the current process output */
y_now = AD_in();
/* Compute the current error */
r_now = r[k];
e_now = r_now - y_now;
/******************************************************************************/
/* Initialization of variables */
/******************************************************************************/
if (initial == 1) {
initial = 0; /* initialize only once */
/* The initial process output sits in y_now */
/* The initial reference sits in r_now */
y_initial = y_now;
r_initial = r_now;
/* Initialize for simple bumpless transfer */
/* Assume all variables are in steady state */
yd_prev = y_initial/(1-pd);
rd_prev = r_initial/(1-pd);
tmp = (1-pdd)^2; /* Temporary variable */
ydd_prev = y_initial/tmp;
rdd_prev = r_initial/tmp;
ydd_prev_prev = y_initial/tmp;
rdd_prev_prev = r_initial/tmp;
/**************************************************************************/
/* Implementation of integral error */
/**************************************************************************/
/* The initial process input equals u_initial */
u_initial = input_bias; /* Change this to the desired initial input */
/* The initial process input also equals: */
/* input_bias
+ integral_gain*(integral_error+e_now)
- fb_proportional*y_initial
+ ff_proportional*r_initial */
/* And thus the initial integral error becomes */
if (integral_gain != 0)
integral_error = (
u_initial
- input_bias
+ fb_proportional*y_initial
- ff_proportional*r_initial
)/integral_gain - e_now;
else
integral_error = 0;
} /* End of initialization */
/* Integrate the error */
integral_error = integral_error + e_now;
/* Derivative auxiliary output & reference */
yd_now = pd*yd_prev + y_now;
rd_now = pd*rd_prev + r_now;
/* Double Der auxiliary output & reference */
ydd_now = 2*pdd*ydd_prev - pdd^2*ydd_prev_prev + y_now;
rdd_now = 2*pdd*rdd_prev - pdd^2*rdd_prev_prev + r_now;
/* Compute the feedback contribution */
fb_cont = fb_proportional * y_now
+ fb_derivative * (yd_now - yd_prev)
+ fb_double_derivative * (ydd_now - 2*ydd_prev + ydd_prev_prev);
/* Compute the feedforward contribution */
ff_cont = ff_proportional * r_now
+ ff_derivative * (rd_now - rd_prev)
+ ff_double_derivative * (rdd_now - 2*rdd_prev + rdd_prev_prev);
/* Compute the new system input */
u_now = input_bias
+ integral_gain * integral_error
- fb_cont
+ ff_cont;
/* Anti-windup */
if (u_now > input_max) {
u_now = input_max;
integral_error = integral_error - e_now;
}
if (u_now < input_min) {
u_now = input_min;
integral_error = integral_error - e_now;
}
/* Send the input to the process */
DA_out(u_now);
/* And shift the registers */
ydd_prev_prev = ydd_prev;
ydd_prev = ydd_now;
rdd_prev_prev = rdd_prev;
rdd_prev = rdd_now;
yd_prev = yd_now;
rd_prev = rd_now;
} /* until stop_flag != 0 */
/******************************************************************************/
/* End Control Loop */
/******************************************************************************/
The design model is the linear model used in the computation of the optimal controller. Each time you identify a new model, and open the ``Control Design'' window, the identified model is designated as design model.
You can also load the design model into RaPID. In that way you
can use models obtained with different identification packages for the
design of the controller. Use the menu entry File
Load Design
Model to load a model from a RaPID or Matlab file (Section
5.4.2).