Main Page   Data Structures   File List   Data Fields   Globals  

StageMotion.c

Go to the documentation of this file.
00001 #include <tcl.h>
00002 #include <tk.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 
00006 #include "motion.h"
00007 
00008 
00009 
00010 #define         rnd(x)          (short)((x) > 0.0  ?  (x)+0.5 : (x)-0.5)
00011 
00012 
00013 ptraject xy = 0;
00014 
00015 
00016 int StageMotion_Open_Cmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00017 {  
00018         int err = 0;
00019 
00020         if (xy == 0) {
00021           xy = newxystage();
00022           err = openstage(xy, "/dev/bpp0");
00023         } else {
00024           return TCL_OK; /* Assume the stage is already open */
00025         }
00026         if (err) {
00027                 return TCL_ERROR;
00028         } else {
00029                 return TCL_OK;
00030         }
00031 }  
00032 
00033 
00034 
00035 int StageMotion_Close_Cmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00036 {  
00037 
00038         int err = 0;
00039 
00040       if (closestage(xy)) {
00041          return TCL_ERROR;
00042       } else {
00043          disposestage(xy);
00044                  return TCL_OK;
00045       }
00046 
00047 }  
00048 
00049 
00050 
00051 int StageMotion_Move_Cmd(ClientData client_data, Tcl_Interp* interp, int argc,char *argv[])
00052 {  
00053         int xp, yp, xcoord, ycoord;
00054         int err = 0;
00055         struct Motion nextpoint[2];
00056 
00057 
00058         if( argc <= 2 ) {
00059                 return TCL_ERROR;
00060         }
00061 
00062 
00063         if( Tcl_GetInt (interp, argv[1], &xcoord) != TCL_OK ) {
00064                 return TCL_ERROR;
00065         }
00066         if( Tcl_GetInt (interp, argv[2], &ycoord) != TCL_OK ) {
00067                 return TCL_ERROR;
00068         }
00069 
00070 
00071         xp = xcoord;
00072         yp = ycoord;
00073         nextpoint[0].relative = 0;
00074         nextpoint[0].vel = 0;
00075         nextpoint[0].pos = xp;
00076         nextpoint[1].relative = 0;
00077         nextpoint[1].vel = 0;
00078         nextpoint[1].pos = yp;
00079         err = movestage(xy, nextpoint);
00080 
00081         if (err) {
00082                 return TCL_ERROR;
00083         } else {
00084                 return TCL_OK;
00085         }
00086 }  
00087 
00088 
00089 int StageMotion_GetState_Cmd(ClientData client_data, Tcl_Interp* interp, int argc,char *argv[])
00090 {  
00091         int ax  = xy->naxes;
00092         ptranslation trans = xy->axis;
00093         char state[15];
00094     char   msg[200];
00095 
00096         sprintf(state,"stopped");
00097 
00098         while (ax-- && (trans != NULL)) {
00099                 if (trans->pos != trans->goalpos) {
00100                         sprintf(state,"moving");
00101                 }
00102             
00103             trans++;
00104         }
00105 
00106         sprintf(msg, "%s", state);
00107         Tcl_SetResult(interp, msg, TCL_VOLATILE);
00108 
00109         return TCL_OK;
00110 }  
00111 
00112 
00113 
00114 #ifdef __cplusplus
00115 extern "C" {
00116 #endif 
00117 
00118 
00119 /*************************************************************************
00120  *
00121  * This procedure initializes the the stagemotion procedures when
00122  * this package is loaded.
00123  *
00124  *************************************************************************/
00125 int StageMotion_Init(Tcl_Interp *interp) {
00126   Tcl_CreateCommand(interp, "StageMotion_Open", StageMotion_Open_Cmd,
00127         (ClientData) NULL, NULL);
00128   Tcl_CreateCommand(interp, "StageMotion_Close", StageMotion_Close_Cmd,
00129         (ClientData) NULL, NULL);
00130   Tcl_CreateCommand(interp, "StageMotion_Move", StageMotion_Move_Cmd,
00131         (ClientData) NULL, NULL);
00132   Tcl_CreateCommand(interp, "StageMotion_GetState", StageMotion_GetState_Cmd,
00133         (ClientData) NULL, NULL);
00134 
00135   return TCL_OK;
00136 }
00137 
00138 
00139 #ifdef __cplusplus
00140 }
00141 #endif 

Generated on Wed Apr 9 08:56:14 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002