#include "eltel.h" //this makes only sense for interfaces, which uses calculated, instead real koordinates //during goto, and correction. //for for all other interfces, this returns true, and do nothing. int test_CalculatedKoors( void ) { int opnocon, oprefract; struct timeb tb1,tb2; double t1,t2,t; time_t offset; double az,alt; double _az,_alt; double azarc,altarc; if(prog.iftype != IF_SERIAL){ ScrClear; fprintf(stdout,"\nThis test makes only sense for interfaces, which must calculate"); fprintf(stdout,"\nkoordinates during correction-, and gotomode.\n"); fprintf(stdout,"\nCurrently this is only the interface -SERIAL-."); fprintf(stdout,"\nAll other get the real koordinates by time.\n\n"); return(1); } ScrClear; fprintf(stdout,"\nNow, we try to find out usefully configvalues,"); fprintf(stdout,"\nfor calculation of koordinates, for your interface SERIAL\n\n"); opnocon = 0; oprefract = 0; if(scope.calcrefraction){ scope.calcrefraction = 0; oprefract = 1; } if(! prog.connection ){ opnocon = 1; if(if_StartConnection( ) == 0){ if_alert("Cannot start connection for test"); return(0); } } if(if_StopMotors( ) == 0){ return(0); } tb2.time = 0; fprintf(stdout,"\nFirst moving 30 seconds to right direction,"); fprintf(stdout,"\nusing your speedsettings for AZ - GOTO\n"); if_GetCurrentAzKoor( ); _az = if_azhs; if(if_GoRight_Fast( ) == 0){ return(0); } ftime(&tb1); offset = tb1.time + 30; while(tb2.time < offset){ ftime(&tb2); } if(if_StopMotors( ) == 0){ return(0); } t1 = (double)(tb1.time * 1000) + tb1.millitm; t2 = (double)(tb2.time * 1000) + tb2.millitm; t = t2 - t1; t = t / 1000; if_GetCurrentAzKoor( ); az = if_azhs - _az; azarc = az * scope.az_halfstepsize; fprintf(stdout,"\n%f halfsteps done within %f seconds",az,t); fprintf(stdout,"\n= %f arcseconds, using your AZHALFSTEPSIZE %f",azarc,scope.az_halfstepsize); fprintf(stdout,"\nresult for SERIALAZGOTOHSPERSEC: %f\n", ( azarc / t ) / scope.az_halfstepsize); tb2.time = 0; fprintf(stdout,"\nNo, we do the same with your speedsettings for AZ - CORRECTION\n"); _az = if_azhs; if(if_GoRight_Slow( ) == 0){ return(0); } ftime(&tb1); offset = tb1.time + 30; while(tb2.time < offset){ ftime(&tb2); } if(if_StopMotors( ) == 0){ return(0); } t1 = (double)(tb1.time * 1000) + tb1.millitm; t2 = (double)(tb2.time * 1000) + tb2.millitm; t = t2 - t1; t = t / 1000; if_GetCurrentAzKoor( ); az = if_azhs - _az; azarc = az * scope.az_halfstepsize; fprintf(stdout,"\n%f halfsteps done within %f seconds",az,t); fprintf(stdout,"\n= %f arcseconds, using your AZHALFSTEPSIZE %f",azarc,scope.az_halfstepsize); fprintf(stdout,"\nresult for SERIALAZCORRECTIONHSPERSEC: %f\n", ( azarc / t ) / scope.az_halfstepsize); tb2.time = 0; fprintf(stdout,"\nNow, moving 30 seconds upwards, using your speedsettings for ALT - GOTO\n"); if_GetCurrentAltKoor( ); _alt = if_alths; if(if_GoUp_Fast( ) == 0){ return(0); } ftime(&tb1); offset = tb1.time + 30; while(tb2.time < offset){ ftime(&tb2); } if(if_StopMotors( ) == 0){ return(0); } t1 = (double)(tb1.time * 1000) + tb1.millitm; t2 = (double)(tb2.time * 1000) + tb2.millitm; t = t2 - t1; t = t / 1000; if_GetCurrentAltKoor( ); alt = if_alths - _alt; altarc = alt * scope.alt_halfstepsize; fprintf(stdout,"\n%f halfsteps done within %f seconds",alt,t); fprintf(stdout,"\n= %f arcseconds, using your ALTHALFSTEPSIZE %f",altarc,scope.alt_halfstepsize); fprintf(stdout,"\nresult for SERIALALTGOTOHSPERSEC: %f\n", ( altarc / t ) / scope.alt_halfstepsize); tb2.time = 0; fprintf(stdout,"\nThe same with your speedsettings for ALT - CORRECTION\n"); _alt = if_alths; if(if_GoUp_Slow( ) == 0){ return(0); } ftime(&tb1); offset = tb1.time + 30; while(tb2.time < offset){ ftime(&tb2); } if(if_StopMotors( ) == 0){ return(0); } t1 = (double)(tb1.time * 1000) + tb1.millitm; t2 = (double)(tb2.time * 1000) + tb2.millitm; t = t2 - t1; t = t / 1000; if_GetCurrentAltKoor( ); alt = if_alths - _alt; altarc = alt * scope.alt_halfstepsize; fprintf(stdout,"\n%f halfsteps done within %f seconds",alt,t); fprintf(stdout,"\n= %f arcseconds, using your ALTHALFSTEPSIZE %f",altarc,scope.alt_halfstepsize); fprintf(stdout,"\nresult for SERIALALTCORRECTIONHSPERSEC: %f\n\n", ( altarc / t ) / scope.alt_halfstepsize); fprintf(stdout,"Be sure, you have set the correct values for"); fprintf(stdout,"\nAZHALFSTEPSIZE, ALTHALFSTEPSIZE, and the speedsettings"); fprintf(stdout,"\nTIMERINTCTGOTO/CORRECTION, AZ/ALTGOTOSPEED, AZ/ALTCORRECTIONSPEED."); fprintf(stdout,"\nIf you change these settings, you must do this test again\n"); if(oprefract){ scope.calcrefraction = 1; } if(opnocon){ if(if_StopConnection( ) == 0){ if_alert("Error when ending connection for test"); return(0); } } return(1); } void DebugCalculation(void) { int ct; double average, result, count, diff, min, max; if(! prog.debug ){ return; } if(encoder.type != NOENCODER){ if(encoder.debugazcount > 2 ){ fprintf(stdout,"\n%d measured values for numbers of az-halfsteps between signalchanges\n",encoder.debugazcount - 2); ct = 2; count = 0.0; average = 0.0; min = 999999999; max = 0; while( ct < encoder.debugazcount ){ diff = encoder.debug_azhs[ct] - encoder.debug_azhs[ct - 1]; if(diff < 0.0){ diff = diff * -1; } fprintf(stdout,"Nr: %d = %ld halfsteps per pulse\n",ct -1, diff); if( diff < min ){ min = diff; } if(diff > max){ max = diff; } average = average + diff; count = count + 1.0; ct++; } result = average / count; fprintf(stdout,"\nAverage: %ld\n", result ); fprintf(stdout,"If your settings for AZHALFSTEPSIZE is correct,\n"); fprintf(stdout,"then for ENCODERAZSIGNALS360 you can use: %ld\n",scope.hs_az360 / result); fprintf(stdout,"minimum hs %ld - maximum hs %ld\n",min,max); if(min == max){ fprintf(stdout,"Wow, no different min-max values\n"); fprintf(stdout,"Try 0.0 for ENCODERAZTOLERANCE\n"); } else { diff = max - min; if(diff < 0.0){ diff = diff * -1.0; } fprintf(stdout,"Difference of %ld between min-max, try this for ENCODERAZTOLERANCE\n"); } } if(encoder.debugaltcount > 2 ){ fprintf(stdout,"\n%d measured values for numbers of alt-halfsteps between signalchanges\n",encoder.debugaltcount - 2); ct = 2; count = 0.0; average = 0.0; min = 999999999; max = 0; while( ct < encoder.debugaltcount ){ diff = encoder.debug_alths[ct] - encoder.debug_alths[ct - 1]; if(diff < 0.0){ diff = diff * -1; } fprintf(stdout,"Nr: %d = %ld halfsteps per pulse\n",ct - 1, diff); if( diff < min ){ min = diff; } if(diff > max){ max = diff; } average = average + diff; count = count + 1.0; ct++; } result = average / count; fprintf(stdout,"\nAverage: %ld\n", result ); fprintf(stdout,"If your settings for ALTHALFSTEPSIZE is correct,\n"); fprintf(stdout,"then for ENCODERALTSIGNALS90 you can use: %ld\n",scope.hs_alt90 / result); fprintf(stdout,"minimum hs %ld - maximum hs %ld\n",min,max); if(min == max){ fprintf(stdout,"Wow, no different min-max values\n"); fprintf(stdout,"Try 0.0 for ENCODERALTTOLERANCE\n"); } else { diff = max - min; if(diff < 0.0){ diff = diff * -1.0; } fprintf(stdout,"Difference of %ld between min-max, try this for ENCODERALTTOLERANCE\n"); } } fprintf(stdout,"\nCurrent state of signalcount az: %ld, alt: %ld\n",encoder.azpulse, encoder.altpulse); fprintf(stdout,"Current state of halfsteps az: %ld, alt: %ld\n",encoder.cazhs, encoder.calths); } }