next up previous
Next: Conclusion Up: RTiC-Lab Application Example: an Previous: Setting up the user_GUI.par

Developing the user_controller.c File

Last, and must importantly, we need to write the piece of code that will do the ``heavy'' work. That is, this is the file that contains our controller algorithm - for example, this file would define a PID controller, or an $H_\infty$ controller, or a real time model, to name a few. For our meager task at hand, we do not crave such lofty algorithms. In fact, our algorithm is so simple that it can be shown in its entirety here:

#include "main.h"

int 
control_init(void)
{
  return(RTIC_SUCCESS); 
}

void 
control_run(void)
{
  int i;
  float tmp;
  for (i=0; i<NUM_CONTROL_INPUTS; i++)
    {
      RETURN_VAL(i,GET_SENSOR(i));
    }
  for (i=0; i<NUM_CONTROL_OUTPUTS; i++)
    {
     tmp = GET_SCALAR_PARAMETER(i);
     SET_VOLTAGE(i,tmp);
     RETURN_VAL(NUM_CONTROL_INPUTS+i,tmp); 
    }
}

int 
control_stop(void)
{
  return(RTIC_SUCCESS);
}

We begin by including ``main.h''. This must be included every single time. Then, we define our three functions as prescribed in a previous chapter: control_init(), control_run(), and control_stop(). In our case, we do not need to initialize any states as would be necessary in a PID or State Space type controller, so we leave our control_init() function blank. We also don't have any shutdown restrictions, therefore the control_stop() function is also left blank.

The story is different for the control_run() function. This function has two main loops. The first loop reads in the sensor readings via the GET_SENSOR macro, and returns these values in the first five columns of our data output. The second loop first reads in the value set by the user in the spin buttons, assign it to a temporary variable tmp, sets the voltage at the D/A outputs to the value set in tmp, and appends these values to the last five columns of the data output.


next up previous
Next: Conclusion Up: RTiC-Lab Application Example: an Previous: Setting up the user_GUI.par
Michael Barabanov 2001-06-19