diff --git a/motorApp/NewportSrc/XPSGathering.c b/motorApp/NewportSrc/XPSGathering.c new file mode 100644 index 00000000..a19cabe7 --- /dev/null +++ b/motorApp/NewportSrc/XPSGathering.c @@ -0,0 +1,276 @@ +/* Prog to test the XPS position gathering and trigger during a trajectory scan */ +/**/ +#include +#include +#include "XPS_C8_drivers.h" +#include "Socket.h" +#include "xps_ftp.h" + +#define XPS_ADDRESS "164.54.160.34" +#define NUM_ELEMENTS 10 +#define NUM_AXES 2 +#define PULSE_TIME 1.0 +#define POLL_TIMEOUT 1.0 +#define DRIVE_TIMEOUT 100.0 +#define USERNAME "Administrator" +#define PASSWORD "Administrator" +#define TRAJECTORY_DIRECTORY "/Admin/public/Trajectories" +#define TRAJECTORY_FILE "test_trajectory" +#define GATHERING_DIRECTORY "/Admin/public/" +#define GATHERING_FILE "Gathering.dat" + +void xps_gathering() +{ + int status,poll_socket,drive_socket,end=0; + int ftpSocket; + char *gatheringData = "GROUP2.POSITIONER1.CurrentPosition;GROUP2.POSITIONER2.CurrentPosition"; + + + char *positioner[NUM_AXES] = {"GROUP2.POSITIONER1", "GROUP2.POSITIONER2"}; + char group[] = "GROUP2"; + char outputfilename[500]; + double maxp,minp,maxv,maxa; + char buffer[100]; + double motorReadbacks[NUM_AXES][NUM_ELEMENTS+1]; + double motorError[NUM_AXES][NUM_ELEMENTS+1]; + double trajTime = 0,trajStep = 0; + int i,j; + int groupStatus; + double posTheory[NUM_AXES]; + FILE *gatheringFile, *trajFile; + int eventID; + time_t start_time, end_time; + + poll_socket = TCP_ConnectToServer(XPS_ADDRESS, 5001, POLL_TIMEOUT); + drive_socket = TCP_ConnectToServer(XPS_ADDRESS, 5001, DRIVE_TIMEOUT); + + status = GroupStatusGet(poll_socket, group, &groupStatus); + printf("Initial group status=%d\n", groupStatus); + /* If group not initialized, then initialize it */ + if (groupStatus >= 0 && groupStatus <= 9) { + printf("Calling GroupInitialize ...\n"); + status = GroupInitialize(drive_socket, group); + if (status) { + printf("Error calling GroupInitialize error=%d\n", status); + return; + } + printf("Calling GroupHomeSearch ...\n"); + status = GroupHomeSearch(drive_socket, group); + if (status) { + printf("Error calling GroupHomeSearch error=%d\n", status); + return; + } + } + + printf("FTPing trajectory file to XPS ...\n"); + /* FTP the trajectory file from the local directory to the XPS */ + status = ftpConnect(XPS_ADDRESS, USERNAME, PASSWORD, &ftpSocket); + if (status != 0) { + printf("Error calling ftpConnect, status=%d\n", status); + return; + } + status = ftpChangeDir(ftpSocket, TRAJECTORY_DIRECTORY); + if (status != 0) { + printf("Error calling ftpChangeDir, status=%d\n", status); + return; + } + status = ftpStoreFile(ftpSocket, TRAJECTORY_FILE); + if (status != 0) { + printf("Error calling ftpStoreFile, status=%d\n", status); + return; + } + + /* Define trajectory output pulses */ + printf("Defining output pulses ...\n"); + status = MultipleAxesPVTPulseOutputSet(poll_socket, group, 1, NUM_ELEMENTS-1, PULSE_TIME); + + /*************************** Verify trajectory **********************/ + printf("Verifying trajectory ...\n"); + status = MultipleAxesPVTVerification(drive_socket, group, TRAJECTORY_FILE); + if (status != 0) { + printf(" Error performing MultipleAxesPVTVerification, status=%d\n",status); + end = 1; + } + + printf("Reading verify results ...\n"); + printf(" MultipleAxesPVTVerificationResultGet\n"); + for (i=0; i 0 && j < (NUM_AXES-1)) { + if (fscanf(trajFile," %lf,%*f,", &trajStep) != 1) printf("trajerror\n"); + } + + if (i == 0) { + posTheory[j] = motorReadbacks[j][i]; + printf("posTheory = %f ",posTheory[j]); + } + else { + posTheory[j]+= trajStep; + } + + motorError[j][i] = posTheory[j] - motorReadbacks[j][i]; + printf("i=%d J=%d ReadBack=%f motorError=%f trajStep%f\n", + i,j,motorReadbacks[j][i],motorError[j][i],trajStep); + } + } + + fclose (trajFile); + fclose (gatheringFile); + + return; +} + diff --git a/motorApp/NewportSrc/XPSGatheringMain.c b/motorApp/NewportSrc/XPSGatheringMain.c new file mode 100644 index 00000000..3458ea55 --- /dev/null +++ b/motorApp/NewportSrc/XPSGatheringMain.c @@ -0,0 +1,7 @@ +void xps_gathering(); + +int main(int arvgc, char **argv) { + xps_gathering(); + return(0); +} + diff --git a/motorApp/NewportSrc/XPSGatheringRegister.c b/motorApp/NewportSrc/XPSGatheringRegister.c new file mode 100644 index 00000000..e5c204e4 --- /dev/null +++ b/motorApp/NewportSrc/XPSGatheringRegister.c @@ -0,0 +1,20 @@ +#include +#include + +void xps_gathering(); + +static const iocshArg XPSGatheringArg0 = {"Interelement period", iocshArgInt}; +static const iocshArg * const XPSGatheringArgs[1] = {&XPSGatheringArg0}; +static const iocshFuncDef XPSGathering = {"XPSGathering", 1, XPSGatheringArgs}; +static void XPSGatheringCallFunc(const iocshArgBuf *args) +{ + xps_gathering(args[0].ival); +} +static void XPSGatheringRegister(void) +{ + iocshRegister(&XPSGathering, XPSGatheringCallFunc); +} + +epicsExportRegistrar(XPSGatheringRegister); + +