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

testprobe.cc

Go to the documentation of this file.
00001 
00002 extern "C" {
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include "pmac.h"
00007 }
00008 
00009 #define LINELEN 80
00010 
00011 struct NML_CARTESIAN
00012 {
00013   NML_CARTESIAN() {}
00014   NML_CARTESIAN(double _x, double _y, double _z) {x = _x; y = _y; z = _z;}
00015   double x;
00016   double y;
00017   double z;
00018 };
00019 
00020 void nml_log_error(int error, const char *fmt = NULL, ...)
00021 {
00022   printf("error %d\n", error);
00023 }
00024 
00025 static int nml_servo_set_scale_called[3] = {1, 1, 1};
00026 
00027 struct SCALE
00028 {
00029   double a;
00030 };
00031 
00032 struct SERVO_WM
00033 {
00034   SCALE scale[3];
00035   double home_offset[3];
00036 };
00037 
00038 static SERVO_WM servo_wm;
00039 
00040 /* Probing */
00041 
00042 /* returns the most recent probe value */
00043 NML_CARTESIAN servo_wm_probe()
00044 {
00045   NML_CARTESIAN probe;
00046 
00047   /* make sure scale is set */
00048   if (!nml_servo_set_scale_called[0] ||
00049       !nml_servo_set_scale_called[1] ||
00050       !nml_servo_set_scale_called[2])
00051   {
00052     nml_log_error(1124);
00053     return probe;
00054   }
00055 
00056   if (pmac_probe_tripped(1) &&
00057       pmac_probe_tripped(2) &&
00058       pmac_probe_tripped(3))
00059   {
00060     probe.x = pmac_probe_value(1) / servo_wm.scale[0].a -
00061       servo_wm.home_offset[0];
00062     pmac_probe_clear(1);
00063     probe.y = pmac_probe_value(2) / servo_wm.scale[1].a -
00064       servo_wm.home_offset[1];
00065     pmac_probe_clear(2);
00066     probe.z = pmac_probe_value(3) / servo_wm.scale[2].a -
00067       servo_wm.home_offset[2];
00068     pmac_probe_clear(3);
00069   }
00070   else
00071   {
00072     /* no probe data-- fill with zero */
00073     probe.x = probe.y = probe.z = 0.0;
00074   }
00075 
00076   return probe;
00077 }
00078 
00079 int main()
00080 {
00081   static char buffer[LINELEN];
00082   static char cmd[LINELEN];
00083   int axis;
00084   NML_CARTESIAN pos;
00085 
00086   servo_wm.scale[0].a = servo_wm.scale[1].a = servo_wm.scale[2].a =
00087     1578.4;
00088   servo_wm.home_offset[0] = servo_wm.home_offset[1] =
00089     servo_wm.home_offset[2] = -5.0;
00090 
00091   while (!feof(stdin))
00092   {
00093     fputs("probe> ", stdout);
00094     fflush(stdout);
00095 
00096     fgets(buffer, LINELEN, stdin);
00097 
00098     if (!strncmp(buffer, "on", 2))
00099     {
00100       printf("%d\n", pmac_probe_on());
00101       continue;
00102     }
00103 
00104     if (!strncmp(buffer, "off", 2))
00105     {
00106       printf("%d\n", pmac_probe_off());
00107       continue;
00108     }
00109 
00110     if (!strncmp(buffer, "trip", 1))
00111     {
00112       if (2 == sscanf(buffer, "%s%d", cmd, &axis))
00113       {
00114         printf("%d\n", pmac_probe_tripped(axis));
00115         continue;
00116       }
00117     }
00118 
00119     if (!strncmp(buffer, "value", 1))
00120     {
00121       if (2 == sscanf(buffer, "%s%d", cmd, &axis))
00122       {
00123         printf("%d\n", pmac_probe_value(axis));
00124         continue;
00125       }
00126     }
00127 
00128     if (!strncmp(buffer, "probe", 1))
00129     {
00130       pos = servo_wm_probe();
00131       printf("%f\t%f\t%f\n", pos.x, pos.y, pos.z);
00132       continue;
00133     }
00134 
00135     if (!strncmp(buffer, "quit", 1))
00136     {
00137       exit(0);
00138     }
00139 
00140     printf("?\n");
00141   }
00142 }

Generated on Sun Dec 2 15:56:53 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001