/** * Callback to be run whenever a new motor info message is received */ void motorInfoCallback(const epos_manager::MotorInfo::ConstPtr& msg){ if(msg->node_id == panMotor.nodeId){ //Get Position of motor panMotor.currentPosition=msg->motor_position; //If motor has discovered boundary points, and is in between them, allow user control if(panMotor.maxValue!=0 && panMotor.minValue!=0 && !isMotorTooClose(panMotor)) panMotor.isReadyForControl=true; //If it is homing mode, home it if(panMotor.isHoming) homeMotor(&panMotor, msg); //If motor is no longer homing and is too close stop it else if(panMotor.isReadyForControl && isMotorTooClose(panMotor) ){ sendVelocityMessage(panMotor,0); } //Calculate and publish the camera angle panMotor.angle =((double)(panMotor.currentPosition - panMotor.homePos)) /PAN_MOTOR_GEAR_RATIO/512*90; publishCameraAngle(); } if(msg->node_id == tiltMotor.nodeId ){ tiltMotor.currentPosition = msg->motor_position; if(tiltMotor.maxValue!=0 && tiltMotor.minValue!=0 && !isMotorTooClose(tiltMotor)) tiltMotor.isReadyForControl=true; if (tiltMotor.isHoming) homeMotor(&tiltMotor, msg); else if(tiltMotor.isReadyForControl && isMotorTooClose(tiltMotor)){ sendVelocityMessage(tiltMotor,0); } //Calculate and publish the camera angle tiltMotor.angle =((double)(tiltMotor.currentPosition - tiltMotor.homePos)) /TILT_MOTOR_GEAR_RATIO/512*90; } if(msg->node_id == boomMotor.nodeId ){ boomMotor.currentPosition=msg->motor_position; if(boomMotor.maxValue!=0 && boomMotor.minValue!=0 && !isMotorTooClose(boomMotor)) boomMotor.isReadyForControl=true; if (boomMotor.isHoming){ homeMotor(&boomMotor, msg); } else if(boomMotor.isReadyForControl && isMotorTooClose(boomMotor)){ sendVelocityMessage(boomMotor,0); } } }
int main (int argc, char **argv) { float value, returnFloat, wavelength; int revolutions; /* Variables for generating a file name with date and time */ time_t rawtime; struct tm * timeinfo; char fileName[BUFSIZE], comments[BUFSIZE]; char dailyFileName[BUFSIZE]; char dataCollectionFileName[] = "/home/pi/.takingData"; FILE *fp,*dataCollectionFlagFile,*configFile; if (argc==2){ strcpy(comments,argv[1]); } else { printf("usage '~$ sudo ./faradayScan <comments in quotes>'\n"); return 1; } // Indicate that data is being collected. dataCollectionFlagFile=fopen(dataCollectionFileName,"w"); if (!dataCollectionFlagFile) { printf("unable to open file:\t%s\n",dataCollectionFileName); exit(1); } revolutions=1; // Set up interfacing devices initializeBoard(); initializeUSB1208(); // Get file name. Use format "FDayScan"+$DATE+$TIME+".dat" time(&rawtime); timeinfo=localtime(&rawtime); struct stat st = {0}; strftime(fileName,BUFSIZE,"/home/pi/RbData/%F",timeinfo); //INCLUDE if (stat(fileName, &st) == -1){ mkdir(fileName,S_IRWXU | S_IRWXG | S_IRWXO ); } strftime(fileName,BUFSIZE,"/home/pi/RbData/%F/FDayScan%F_%H%M%S.dat",timeinfo); //INCLUDE strftime(dailyFileName,BUFSIZE,"/home/pi/RbData/%F/FDayScan%F.dat",timeinfo); //INCLUDE printf("%s\n",fileName); printf("%s\n",comments); fp=fopen(fileName,"w"); if (!fp) { printf("Unable to open file: %s\n",fileName); fflush(stdout); exit(1); } configFile=fopen("/home/pi/RbControl/system.cfg","r"); if (!configFile) { printf("Unable to open config file\n"); fflush(stdout); exit(1); } fprintf(fp,"#Filename:\t%s\n#Comments:\t%s\n",fileName,comments); /** Record System Stats to File **/ /** Pressure Gauges **/ getIonGauge(&returnFloat); printf("IonGauge %2.2E Torr \n",returnFloat); fprintf(fp,"#IonGauge(Torr):\t%2.2E\n",returnFloat); getConvectron(GP_N2_CHAN,&returnFloat); printf("CVGauge(N2) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(N2)(Torr):\t%2.2E\n", returnFloat); getConvectron(GP_HE_CHAN,&returnFloat); printf("CVGauge(He) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(He)(Torr):\t%2.2E\n", returnFloat); /** Temperature Controllers **/ //getPVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res:\t%f\n",returnFloat); //getSVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res_set:\t%f\n",returnFloat); //getPVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg:\t%f\n",returnFloat); //getSVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg_set:\t%f\n",returnFloat); /** End System Stats Recording **/ char line[1024]; fgets(line,1024,configFile); while(line[0]=='#'){ fprintf(fp,"%s",line); fgets(line,1024,configFile); } fclose(configFile); /* int numDet=18,j; float scanDet[]={-33,-30,-19,-18,-9,-5,-4.5,-4,-3.5,6,6.5,7,7.5,11,20,21,30,33}; */ int numDet=10,j; float scanDet[]={-30,-27,-19,-18,-9,11,20,21,30,33}; fprintf(fp,"#Revolutions:\t%d\n",revolutions); fprintf(fp,"#DataPointsPerRev:\t%f\n",DATAPTSPERREV); fprintf(fp,"#NumVolts:\t%d\n",numDet); fprintf(fp,"#StepSize:\t%d\n",STEPSIZE); // Write the header for the data to the file. fprintf(fp,"STEP\tPUMP\tPUMPsd\tPRB\tPRBsd\tREF\tREFsd\n"); fclose(fp); printf("Homing motor...\n"); homeMotor(PROBE_MOTOR); // int numPd=3; // int pd[] = {PUMP_LASER,PROBE_LASER,REF_LASER}; int numPd=2; int pd[] = {BOTLOCKIN,TOPLOCKIN}; fp=fopen(fileName,"a"); setProbeDetuning(scanDet[0]); delay(10000); for(j=0;j<numDet;j++){ setProbeDetuning(scanDet[j]); getVortexPiezo(&value); delay(1000); getProbeFrequency(&wavelength); // wavelength=-1; fprintf(fp,"\n\n#VOLT:%f(%f)\n",value,wavelength); printf("VOLT:%f(%f)\t",value,wavelength); fflush(stdout); quickHomeMotor(PROBE_MOTOR); collectDiscreteFourierData(fp,pd,numPd /*numPhotoDet*/,PROBE_MOTOR,revolutions); }//end for Volt fclose(fp); //printf("Processing Data...\n"); //analyzeData(fileName, numDet, revolutions, dataPointsPerRevolution, FOI); char* extensionStart; extensionStart=strstr(fileName,".dat"); strcpy(extensionStart,"RotationAnalysis.dat"); //printf("Plotting Data...\n"); //plotData(fileName); //printf("Calculating number density...\n"); //calculateNumberDensity(fileName, 0, 0); //printf("Recording number density to file...\n"); //recordNumberDensity(fileName); closeUSB1208(); // Remove the file indicating that we are taking data. fclose(dataCollectionFlagFile); remove(dataCollectionFileName); return 0; }
int main (int argc, char **argv) { int i; int upOrDown; int revolutions,dataPointsPerRevolution; time_t rawtime; float returnFloat; //float probeOffset,mag1Voltage,mag2Voltage; struct tm * timeinfo; char fileName[BUFSIZE], comments[BUFSIZE]; char dailyFileName[BUFSIZE]; char dataCollectionFileName[] = "/home/pi/.takingData"; FILE *fp,*dataCollectionFlagFile,*configFile; float angle=-99; float desiredAngle,tempChange; if (argc==4){ upOrDown=atof(argv[1]); desiredAngle=atof(argv[2]); strcpy(comments,argv[3]); } else { printf("usage '~$ sudo ./stepTemperatureWaitForRotationAngle <up or down (0 down, 1 up)> <desired Angle> <comments in quotes>'\n"); printf(" Don't forget to edit the config file! \n"); return 1; } // Indicate that data is being collected. dataCollectionFlagFile=fopen(dataCollectionFileName,"w"); if (!dataCollectionFlagFile) { printf("unable to open file:\t%s\n",dataCollectionFileName); exit(1); } revolutions=1; dataPointsPerRevolution=(int)STEPSPERREV/STEPSIZE; // Set up interfacing devices initializeBoard(); initializeUSB1208(); if(upOrDown==0){ tempChange=-.1; }else{ tempChange=.1; } do{ getPVCN7500(CN_RESERVE,&returnFloat); setSVCN7500(CN_RESERVE,returnFloat+tempChange); delay(1800000); //delay(180); configFile=fopen("/home/pi/RbControl/system.cfg","r"); if (!configFile) { printf("Unable to open config file\n"); exit(1); } // Get file name. Use format "FDayScan"+$DATE+$TIME+".dat" time(&rawtime); timeinfo=localtime(&rawtime); struct stat st = {0}; strftime(fileName,BUFSIZE,"/home/pi/RbData/%F",timeinfo); //INCLUDE if (stat(fileName, &st) == -1){ mkdir(fileName,S_IRWXU | S_IRWXG | S_IRWXO ); } strftime(fileName,BUFSIZE,"/home/pi/RbData/%F/FDayRotation%F_%H%M%S.dat",timeinfo); //INCLUDE strftime(dailyFileName,BUFSIZE,"/home/pi/RbData/%F/FDayRotation%F.dat",timeinfo); //INCLUDE printf("%s\n",fileName); printf("%s\n",comments); fp=fopen(fileName,"w"); if (!fp) { printf("Unable to open file: %s\n",fileName); exit(1); } fprintf(fp,"#Filename:\t%s\n#Comments:\t%s\n",fileName,comments); getIonGauge(&returnFloat); //printf("IonGauge %2.2E Torr \n",returnFloat); fprintf(fp,"#IonGauge(Torr):\t%2.2E\n",returnFloat); getConvectron(GP_N2_CHAN,&returnFloat); //printf("CVGauge(N2) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(N2)(Torr):\t%2.2E\n", returnFloat); getConvectron(GP_HE_CHAN,&returnFloat); //printf("CVGauge(He) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(He)(Torr):\t%2.2E\n", returnFloat); getPVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res:\t%f\n",returnFloat); getSVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res_set:\t%f\n",returnFloat); getPVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg:\t%f\n",returnFloat); getSVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg_set:\t%f\n",returnFloat); char line[1024]; fgets(line,1024,configFile); while(line[0]=='#'){ fprintf(fp,"%s",line); fgets(line,1024,configFile); } fclose(configFile); fprintf(fp,"#Revolutions:\t%d\n",revolutions); fprintf(fp,"#DataPointsPerRev:\t%d\n",dataPointsPerRevolution); fprintf(fp,"#NumVoltages:\t%d\n",1); fprintf(fp,"#PumpFrequency:\t%f\n",getPumpFrequency(&returnFloat)); //fprintf(fp,"#ProbeWavelength:\t%f\n",getProbeFreq()); // UNCOMMENT THE FOLLOWING LINES WHEN COLLECTING STANDARD DATA int photoDetectors[] = {PUMP_LASER,PROBE_LASER,REF_LASER}; char* names[]={"PMP","PRB","REF"}; // UNCOMMENT THE FOLLOWING LINES WHEN USING THE FLOATING PD //int photoDetectors[] = {PROBE_LASER,PUMP_LASER,REF_LASER}; //char* names[]={"PRB","PMP","REF"}; int numPhotoDetectors = 3; int motor = PROBE_MOTOR; // Write the header for the data to the file. fprintf(fp,"STEP"); for(i=0;i<numPhotoDetectors;i++){ fprintf(fp,"\t%s\t%ssd",names[i],names[i]); } fprintf(fp,"\n"); fclose(fp); fp=fopen(fileName,"a"); homeMotor(motor); angle=collectDiscreteFourierData(fp, photoDetectors, numPhotoDetectors, motor, revolutions); printf("The measured angle was: %3.1f\n",angle); fclose(fp); printf("Processing Data...\n"); analyzeData(fileName, 1, revolutions, dataPointsPerRevolution,FOI); }while(angle > desiredAngle + .4 || angle < desiredAngle -.4); closeUSB1208(); // Remove the file indicating that we are taking data. fclose(dataCollectionFlagFile); remove(dataCollectionFileName); return 0; }
int getPolarizationData(char* fileName, int VHe, int dwell, float leakageCurrent){ char command[64]; char echoData[128]; // Variables for stepper motor control. int nsteps,steps,ninc,i; // Variables for data collections. long returnCounts; long sumCounts; float current1, current2,angle; float currentErr; float* measurement = calloc(dwell*2,sizeof(float)); // Write Aout for He traget here setUSB1208AnalogOut(HETARGET,(__u16)VHe); //i = setSorensen120Volts(VHe,SORENSEN120,GPIBBRIDGE1); //if(i!=0){ // printf("Error setting Sorensen. Code: %d\n",i); //} // NOTE THAT THIS SETS THE FINAL ELECTRON ENERGY. THIS ALSO DEPENDS ON BIAS AND TARGET OFFSET. AN EXCIATION FN WILL TELL THE // USER WHAT OUT TO USE, OR JUST MANUALLY SET THE TARGET OFFSET FOR THE DESIRED ENERGY // Begin File setup FILE* rawData=fopen(fileName,"a"); if (!rawData) { printf("Unable to open file: %s\n",fileName); exit(1); } // End File setup homeMotor(POL_MOTOR); nsteps=STEPSPERREV*REVOLUTIONS; ninc=STEPSPERREV/DATAPOINTSPERREV; // The number of steps to take between readings. fprintf(rawData,"STEP\tCOUNT\tCURRENT\tCURRENTsd\tANGLE\n");// This line withough a comment is vital for being able to quickly process data. DON'T REMOVE printf("Steps\tCounts\tCurrent\n"); for (steps=0;steps<nsteps;steps+=ninc){ stepMotor(POL_MOTOR,CCLK,ninc); current1=0.0; current2=0.0; sumCounts=0; for(i=0;i<dwell;i++){ //writeRS485to232Bridge("READ?",echoData,0xCA); //current += atof(echoData); do{ getUSB1208AnalogIn(0,¤t1); }while(current1 == 0); getUSB1208Counter(10,&returnCounts); sumCounts += returnCounts; do{ getUSB1208AnalogIn(0,¤t2); }while(current2 == 0); } currentErr=(current1-current2)/(current1+current2); angle = (float)steps/STEPSPERREV*2.0*PI; printf("%d\t%ld\t%1.2e\n",steps,sumCounts,current1+leakageCurrent); fprintf(rawData,"%d\t%ld\t%e\t%f\t%f\n",steps,sumCounts,current1+leakageCurrent,currentErr,angle); } fclose(rawData); // Reset Helium Target Offset back to zero i = setSorensen120Volts(VHe,SORENSEN120,GPIBBRIDGE1); if(i!=0){ printf("Error setting Sorensen. Code: %d\n",i); } //setUSB1208AnalogOut(HETARGET,0); return 0; }