rtdemo1 RTDB

The rtdemo1 RTDB is used by a number of tests and models to simulate a PID controller. According to Wikipedia:

“A proportional-integral-derivative controller (PID controller) is a generic control loop feedback mechanism (controller) widely used in industrial control systems - a PID is the most commonly used feedback controller. A PID controller calculates an ‘error’ value as the difference between a measured process variable and a desired setpoint. The controller attempts to minimize the error by adjusting the process control inputs.”

There are four variables in this RTDB:

reference

An input point containing the desired setpoint.

reference_out

An output point containing a copy of the value of reference.

control_signal

The process control signal that is varied by the PID to get the plant to reach the desired reference setpoint.

plant_response

The response of the plant to the control signal. The controller is attempting to adjust the plant_response to match the reference input.

There are several different tests that illustrate the use of scripts and multiple models in addition to a couple of displays that illustrate features of the HMI.

rtdemo1 Test and rtdemo1.swbd Display

Begin by running the rdemo1 test and opening the rtdemo1.swbd display. The reference variable is connected to a Numeric Value, Bar Graph, Knob, and Slider widget. Use these widgets to make adjustments to the reference value and watch the control_signal and plant_response values change in the graphs.

rtdemo1.png 

As an exercise, we’re going to make two changes. First, we’re going to change the color of the plant_response so it can be distinguished from the reference value in the upper left graph. Select that graph then click on the Plot Properties +/- Elements button. Click on the plot color in the second row and select a non-white color.

Second, we’re going to re-purpose the bar graph to tweak one of the model parameters. Select the bar graph. Notice the Value widget variable is pre-selected. Select the Model Variables tab and the rtdemo1 model in the Model combo box. Then find Parameters/sm_computation/Gain Kp/Gain and click the check box next to it. The bar graph can now be used to adjust the weight given to the present error.

Play with different values for the Gain and see how it effects the plant_response when the reference variable is adjusted.

rtdemo1-ex1.png 

rtdemo_ref Testrtdemo_ref.png

This test uses the same rtdemo1 model, but it also runs a simple user model, rtdemo_u, that drives the reference value by assigning it a random value every five seconds.

while (1) {

   ccurSched_waitNextFrame();

   if (count % sec_5 == sec_5-1) {

       if (!(p->data.rtFlags

             & RTDBFL_OPERATOR)) {

            ref = 20+80.0*rand()

                 /RAND_MAX;

           ccurLog_printf(

              defaultLogger,

              LOG_INFO,

          "Setting set point to %g ",

              ref);

              cvtTable.reference=ref;

       }

   }

   count++;

}

Note that a dependency is used between the two models to insure that rtdemo_u runs before rtdemo1.

rtdemo_swm Test

It is even easier to use an SWm script to drive the reference input, like the rtdemo_swm test does.

First the script establishes shortcut references to the reference and plant_response variables, initializes the reference variable to 10, and configures itself to ignore errors:

rtdb_ref  "reference",ref;

rtdb_ref "plant_response",pr;

r.ref  = 10;

ei;  # Ignore errors so we keep running when the waitcond fails

waitseconds 5

There’s some uninteresting logging stuff going on that is elided here. The first loop increments the reference variable by 10, then waits up to one half second for the plant response to get within 0.1 of that value.

section "Increment ref by 10 until 100";

msg "Go to 100";

while ref < 100

   r.ref = ref;

   section "wait for %g",ref;

       waitcond abs (r.pr - r.ref) < 0.1,.5;

       waitseconds 0.5;

   endsec

   ref = ref+10;

end

endsec

We can now look at the messages to see how successful it was at tracking the reference input:

rtdemo_swm-messages.png 

Now in the rtdemo1 display we edited, try adjusting the Gain parameter we linked to the Bar Graph widget and rerun the test to see if a different value yields a better response.

rtdemo1_sigg_c and rtdemo1_sigg_py Tests

Scripts can also be written in C or Python. The rtdemo1_sigg_c and rtdemo1_sigg_py tests use scripts to connect the reference variable to signal generators.