Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

amplifier.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Defines

#define __attribute__(x)

Functions

char __attribute__ ((unused)) amplifier_h[]="$Id
int amplifierInit (AMPLIFIER_STRUCT *amp)
int amplifierSetGain (AMPLIFIER_STRUCT *amp, double gain)
double amplifierGetGain (AMPLIFIER_STRUCT *amp)
int amplifierSetMaxOutputCurrent (AMPLIFIER_STRUCT *amp, double maxOutputCurrent)
double amplifierGetMaxOutputCurrent (AMPLIFIER_STRUCT *amp)
int amplifierSetLoadResistance (AMPLIFIER_STRUCT *amp, double loadResistance)
double amplifierGetLoadResistance (AMPLIFIER_STRUCT *amp)
int amplifierEnable (AMPLIFIER_STRUCT *amp)
int amplifierDisable (AMPLIFIER_STRUCT *amp)
int amplifierIsEnabled (AMPLIFIER_STRUCT *amp)
int amplifierReset (AMPLIFIER_STRUCT *amp)
int amplifierIsTripped (AMPLIFIER_STRUCT *amp)
double amplifierRunCycle (AMPLIFIER_STRUCT *amp, double input)
int amplifierIniLoad (AMPLIFIER_STRUCT *amp, const char *filename, const char *section)

Variables

 AMPLIFIER_STRUCT


Define Documentation

#define __attribute__  
 

Definition at line 32 of file amplifier.h.


Function Documentation

char __attribute__ (unused)    [static]
 

Definition at line 36 of file amplifier.h.

00036                                                         : amplifier.h,v 1.2 2000/10/27 20:34:42 terrylr Exp $";
00037 
00038 typedef struct
00039 {
00040   /* parameters */
00041   double gain;                  /* multiplying gain for runCycle */
00042   double maxOutputCurrent;      /* output/loadResistance exceeds will trip */
00043   double loadResistance;        /* resistance of attached motor */
00044 
00045   /* internal vars */
00046   int configured;               /* non-zero means some params not set */
00047   int enabled;                  /* zero means 0.0 output always */
00048   int tripped;                  /* zero means 0.0 output always */
00049 
00050 } AMPLIFIER_STRUCT;

int amplifierDisable AMPLIFIER_STRUCT   amp
 

Definition at line 156 of file amplifier.c.

00157 {
00158   if (0 == amp)
00159   {
00160     return -1;
00161   }
00162 
00163   amp->enabled = 0;
00164 
00165   return 0;
00166 }

int amplifierEnable AMPLIFIER_STRUCT   amp
 

Definition at line 139 of file amplifier.c.

Referenced by simAmpEnable().

00140 {
00141   if (0 == amp)
00142   {
00143     return -1;
00144   }
00145 
00146   if (! amp->tripped &&
00147       amp->configured == ALL_SET)
00148   {
00149     amp->enabled = 1;
00150   }
00151 
00152   return 0;
00153 }

double amplifierGetGain AMPLIFIER_STRUCT   amp
 

Definition at line 76 of file amplifier.c.

00077 {
00078   if (0 == amp ||
00079       ! (amp->configured & GAIN_SET))
00080   {
00081     return 0.0;
00082   }
00083 
00084   return amp->gain;
00085 }

double amplifierGetLoadResistance AMPLIFIER_STRUCT   amp
 

Definition at line 127 of file amplifier.c.

00128 {
00129   if (0 == amp ||
00130       ! (amp->configured & LOAD_RESISTANCE_SET))
00131   {
00132     return 0.0;
00133   }
00134 
00135   return amp->loadResistance;
00136 }

double amplifierGetMaxOutputCurrent AMPLIFIER_STRUCT   amp
 

Definition at line 102 of file amplifier.c.

00103 {
00104   if (0 == amp ||
00105       ! (amp->configured & MAX_OUTPUT_CURRENT_SET))
00106   {
00107     return 0.0;
00108   }
00109 
00110   return amp->maxOutputCurrent;
00111 }

int amplifierIniLoad AMPLIFIER_STRUCT   amp,
const char *    filename,
const char *    section
 

Definition at line 241 of file amplifier.c.

Referenced by __attribute__(), and main().

00242 {
00243 #ifndef NO_STDIO_SUPPORT
00244 
00245   AMPLIFIER_STRUCT amp;
00246   int retval = 0;
00247   const char *inistring;
00248 
00249 #ifndef UNDER_CE
00250   FILE *fp;
00251 
00252   if (NULL == (fp = fopen(filename, "r")))
00253   {
00254     rcs_print_error( "can't open ini file %s\n", filename);
00255     return -1;
00256   }
00257 #else
00258   INET_FILE *fp;
00259 
00260   if (NULL == (fp = inet_file_open(filename, "r")))
00261   {
00262     rcs_print_error( "can't open ini file %s\n", filename);
00263     return -1;
00264   }
00265 #endif
00266 
00267   memset(&amp,0,sizeof(amp));
00268   if (NULL != (inistring = iniFind(fp, "AMPLIFIER_GAIN", section)))
00269   {
00270 #ifndef UNDER_CE
00271     if (1 != sscanf((char *) inistring, "%lf", &amp.gain))
00272     {
00273       /* found, but invalid */
00274       rcs_print_error( "invalid GAIN: %s\n", inistring);
00275       retval = -1;
00276     }
00277     else
00278     {
00279       amplifierSetGain(amplifier, amp.gain);
00280     }
00281 #else
00282     amp.gain = RCS_CE_ATOF(inistring);
00283     amplifierSetGain(amplifier, amp.gain);
00284 #endif
00285   }
00286 
00287   if (NULL != (inistring = iniFind(fp, "MAX_OUTPUT_CURRENT", section)))
00288   {
00289 #ifndef UNDER_CE
00290     if (1 != sscanf((char *) inistring, "%lf", &amp.maxOutputCurrent))
00291     {
00292       /* found, but invalid */
00293       rcs_print_error( "invalid MAX_OUTPUT_CURRENT: %s\n", inistring);
00294       retval = -1;
00295     }
00296     else
00297     {
00298       amplifierSetMaxOutputCurrent(amplifier, amp.maxOutputCurrent);
00299     }
00300 #else
00301     amp.maxOutputCurrent =  RCS_CE_ATOF(inistring);
00302     amplifierSetMaxOutputCurrent(amplifier, amp.maxOutputCurrent);
00303 #endif
00304   }
00305 
00306   if (NULL != (inistring = iniFind(fp, "LOAD_RESISTANCE", section)))
00307   {
00308 #ifndef UNDER_CE
00309     if (1 != sscanf((char *) inistring, "%lf", &amp.loadResistance))
00310     {
00311       /* found, but invalid */
00312       rcs_print_error( "invalid LOAD_RESISTANCE: %s\n", inistring);
00313       retval = -1;
00314     }
00315     else
00316     {
00317       amplifierSetLoadResistance(amplifier, amp.loadResistance);
00318     }
00319 #else
00320     amp.loadResistance =  RCS_CE_ATOF(inistring);
00321     amplifierSetLoadResistance(amplifier, amp.loadResistance);
00322 #endif
00323   }
00324 
00325   /* close inifile */
00326 #ifndef UNDER_CE
00327   fclose(fp);
00328 #else
00329   inet_file_close(fp);
00330 #endif
00331 
00332 
00333   return retval;
00334 
00335 #else
00336 
00337   return -1;
00338 
00339 #endif
00340 }

int amplifierInit AMPLIFIER_STRUCT   amp
 

int amplifierIsEnabled AMPLIFIER_STRUCT   amp
 

Definition at line 169 of file amplifier.c.

00170 {
00171   if (0 == amp)
00172   {
00173     return -1;
00174   }
00175 
00176   return amp->enabled;
00177 }

int amplifierIsTripped AMPLIFIER_STRUCT   amp
 

Definition at line 197 of file amplifier.c.

Referenced by simAmpFault().

00198 {
00199   if (0 == amp)
00200   {
00201     return -1;
00202   }
00203 
00204   return amp->tripped;
00205 }

int amplifierReset AMPLIFIER_STRUCT   amp
 

Definition at line 180 of file amplifier.c.

00181 {
00182   if (0 == amp)
00183   {
00184     return -1;
00185   }
00186 
00187   if (amp->configured == ALL_SET)
00188   {
00189     amp->enabled = 0;
00190     amp->tripped = 0;
00191   }
00192 
00193   return 0;
00194 }

double amplifierRunCycle AMPLIFIER_STRUCT   amp,
double    input
 

Definition at line 207 of file amplifier.c.

Referenced by simDacWrite().

00208 {
00209   double output;
00210   double outputCurrent;
00211 
00212   /* check for configured */
00213   if (0 == amp ||
00214       amp->configured != ALL_SET)
00215   {
00216     return 0.0;
00217   }
00218 
00219   /* check state for allowing output */
00220   if (! amp->enabled ||
00221       amp->tripped)
00222   {
00223     return 0.0;                 /* disabled-- hold output at 0.0 */
00224   }
00225 
00226   /* finally-- do the simple math */
00227   output = amp->gain * input;
00228   outputCurrent = fabs(output / amp->loadResistance);
00229 
00230   /* check output */
00231   if (outputCurrent > amp->maxOutputCurrent)
00232   {
00233     amp->tripped = 1;
00234     amp->enabled = 0;
00235     output = 0.0;
00236   }
00237 
00238   return output;
00239 }

int amplifierSetGain AMPLIFIER_STRUCT   amp,
double    gain
 

Definition at line 62 of file amplifier.c.

Referenced by amplifierIniLoad().

00063 {
00064   if (0 == amp ||
00065       gain <= 0.0)
00066   {
00067     return -1;
00068   }
00069 
00070   amp->gain = gain;
00071   amp->configured |= GAIN_SET;
00072 
00073   return 0;
00074 }

int amplifierSetLoadResistance AMPLIFIER_STRUCT   amp,
double    loadResistance
 

Definition at line 113 of file amplifier.c.

Referenced by amplifierIniLoad().

00114 {
00115   if (0 == amp ||
00116       loadResistance <= 0.0)
00117   {
00118     return -1;
00119   }
00120 
00121   amp->loadResistance = loadResistance;
00122   amp->configured |= LOAD_RESISTANCE_SET;
00123 
00124   return 0;
00125 }

int amplifierSetMaxOutputCurrent AMPLIFIER_STRUCT   amp,
double    maxOutputCurrent
 

Definition at line 87 of file amplifier.c.

Referenced by amplifierIniLoad().

00089 {
00090   if (0 == amp ||
00091       maxOutputCurrent <= 0.0)
00092   {
00093     return -1;
00094   }
00095 
00096   amp->maxOutputCurrent = maxOutputCurrent;
00097   amp->configured |= MAX_OUTPUT_CURRENT_SET;
00098 
00099   return 0;
00100 }


Variable Documentation

AMPLIFIER_STRUCT
 

Definition at line 50 of file amplifier.h.


Generated on Sun Dec 2 15:27:46 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001