1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 2K.1beta (1.48)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Developing the user_controller.c File</TITLE>
<META NAME="description" CONTENT="Developing the user_controller.c File">
<META NAME="keywords" CONTENT="rtic">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="LaTeX2HTML v2K.1beta">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="rtic.css">
<LINK REL="previous" HREF="node58.html">
<LINK REL="up" HREF="node56.html">
<LINK REL="next" HREF="node60.html">
</HEAD>
<BODY bgcolor="white">
<!--Navigation Panel-->
<A NAME="tex2html763"
HREF="node60.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
SRC="/usr/share/latex2html/icons/next.png"></A>
<A NAME="tex2html761"
HREF="node56.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
SRC="/usr/share/latex2html/icons/up.png"></A>
<A NAME="tex2html757"
HREF="node58.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
SRC="/usr/share/latex2html/icons/prev.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html764"
HREF="node60.html">Conclusion</A>
<B> Up:</B> <A NAME="tex2html762"
HREF="node56.html">RTiC-Lab Application Example: an</A>
<B> Previous:</B> <A NAME="tex2html758"
HREF="node58.html">Setting up the user_GUI.par</A>
<BR>
<BR>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION00630000000000000000">
Developing the <TT>user_controller.c</TT> File</A>
</H1>
<P>
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 <IMG
WIDTH="37" HEIGHT="37" ALIGN="MIDDLE" BORDER="0"
SRC="img71.png"
ALT="$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:
<P><PRE>
#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);
}
</PRE>
<P>
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: <TT>control_init()</TT>, <TT>control_run()</TT>, and <TT>control_stop()</TT>. 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 <TT>control_init()</TT> function blank. We also don't have
any shutdown restrictions, therefore the <TT>control_stop()</TT>
function is also left blank.
<P>
The story is different for the <TT>control_run()</TT> function. This
function has two main loops. The first loop reads in the sensor
readings via the <TT>GET_SENSOR</TT> 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 <TT>tmp</TT>, sets the voltage at the D/A outputs to
the value set in <TT>tmp</TT>, and appends these values to the last five
columns of the data output.
<HR>
<!--Navigation Panel-->
<A NAME="tex2html763"
HREF="node60.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
SRC="/usr/share/latex2html/icons/next.png"></A>
<A NAME="tex2html761"
HREF="node56.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
SRC="/usr/share/latex2html/icons/up.png"></A>
<A NAME="tex2html757"
HREF="node58.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
SRC="/usr/share/latex2html/icons/prev.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html764"
HREF="node60.html">Conclusion</A>
<B> Up:</B> <A NAME="tex2html762"
HREF="node56.html">RTiC-Lab Application Example: an</A>
<B> Previous:</B> <A NAME="tex2html758"
HREF="node58.html">Setting up the user_GUI.par</A>
<!--End of Navigation Panel-->
<ADDRESS>
Michael Barabanov
2001-06-19
</ADDRESS>
</BODY>
</HTML>
|