#include "scope.h" void initEncoderValues( void ) { ARC10PERENCHO = ARC10_360 / CFG_ENC_HO; ARC10PERENCVE = ARC10_360 / CFG_ENC_VE; } void initScopeValues( void ) { double abs,v; v = (double)1296000 / (double)CFG_HSTS_HO; v = v - (double)CFG_HSTS_HO; modf( v, &abs ); HSTEPSHO359 = (long)abs; v = (double)324000 / (double)CFG_HSTS_HO; modf( v, &abs ); HSTEPSHO090 = (long)abs; v = (double)648000 / (double)CFG_HSTS_HO; modf( v, &abs ); HSTEPSHO180 = (long)abs; v = (double)972000 / (double)CFG_HSTS_HO; modf( v, &abs ); HSTEPSHO270 = (long)abs; } int hstepsSector( long val ) { if( ( val >= 0 ) && ( val < HSTEPSHO090 ) ){ return(0); } if( ( val >= HSTEPSHO090 ) && ( val < HSTEPSHO180 ) ){ return(1); } if( ( val >= HSTEPSHO180 ) && ( val < HSTEPSHO270 ) ){ return(2); } return(3); } void origin( void ) { double abs,v; KOOR_RA = OBJ_DEG_RA; KOOR_DEC = OBJ_DEG_DEC; cCurrentStarTime(); cAzAlt(); v = ( (double)KOOR_AZ * (double)3600 ) / (double)CFG_HSTS_HO; modf( v, &abs ); CUR_HSTEPS_HO = (long)abs; v = ( (double)KOOR_ALT * (double)3600 ) / (double)CFG_HSTS_VE; modf( v, &abs ); CUR_HSTEPS_VE = (long)abs; v = (double)CUR_HSTEPS_HO * (double)CFG_HSTS_HO * (double)10; modf( v , &abs); CUR_ARC10_HO = (long)abs; v = (double)CUR_HSTEPS_VE * (double)CFG_HSTS_VE * (double)10; modf( v , &abs); CUR_ARC10_VE = (long)abs; ENC_ARC10_HO = CUR_ARC10_HO; ENC_ARC10_VE = CUR_ARC10_VE; ENCHO_COR = OFF; ENCVE_COR = OFF; } //this must set directionflags for motors in every case //Then it must test if target is reached, - if so it returns 1, //otherwise returns 0. //KOOR_RA, and KOOR_DEC must contain current target-object. //KOOR_AZ, and KOOR_ALT will be set automatically. int calcTarget( void ) { double abs,v; int cursector,trgsector,flag; long curho,curve,trgho,trgve; cCurrentStarTime(); cAzAlt(); v = ( (double)KOOR_AZ * (double)3600 ) / (double)CFG_HSTS_HO; modf( v, &abs ); trgho = (long)abs; v = ( (double)KOOR_ALT * (double)3600 ) / (double)CFG_HSTS_VE; modf( v, &abs ); trgve = (long)abs; TRG_HSTEPS_HO = trgho; TRG_HSTEPS_VE = trgve; curho = CUR_HSTEPS_HO; curve = CUR_HSTEPS_VE; v = (double)curho * (double)CFG_HSTS_HO * (double)10; modf( v , &abs); CUR_ARC10_HO = (long)abs; v = (double)curve * (double)CFG_HSTS_VE * (double)10; modf( v , &abs); CUR_ARC10_VE = (long)abs; // for az we have to calculate the shortes way cursector = hstepsSector( curho ); trgsector = hstepsSector( trgho ); flag = 0; if( trgve == curve ) { flag++; MOTVE_RUN = OFF; } else { if( trgve < curve ){ MOTVE_DIR = DOWN; } else { MOTVE_DIR = UP; } MOTVE_RUN = ON; } if( trgho == curho ) { flag++; MOTHO_RUN = OFF; } else { switch( cursector ) { //north case 0: switch( trgsector ) { //north case 0: if( trgho < curho ){ MOTHO_DIR = LEFT; } else { MOTHO_DIR = RIGHT; } break; case 3: MOTHO_DIR = LEFT; break; //south case 1: MOTHO_DIR = RIGHT; break; case 2: MOTHO_DIR = RIGHT; break; } break; case 3: switch( trgsector ) { //north case 0: MOTHO_DIR = RIGHT; break; case 3: if( trgho < curho ){ MOTHO_DIR = LEFT; } else { MOTHO_DIR = RIGHT; } break; //south case 1: MOTHO_DIR = LEFT; break; case 2: MOTHO_DIR = LEFT; break; } break; //south case 1: switch( trgsector ) { //north case 0: MOTHO_DIR = LEFT; break; case 3: MOTHO_DIR = RIGHT; break; //south case 1: if( trgho < curho ){ MOTHO_DIR = LEFT; } else { MOTHO_DIR = RIGHT; } break; case 2: MOTHO_DIR = RIGHT; break; } break; case 2: switch( trgsector ) { //north case 0: MOTHO_DIR = LEFT; break; case 3: MOTHO_DIR = RIGHT; break; //south case 1: MOTHO_DIR = LEFT; break; case 2: if( trgho < curho ){ MOTHO_DIR = LEFT; } else { MOTHO_DIR = RIGHT; } break; } break; } MOTHO_RUN = ON; } if( MOTFR_USE == ON ) { ; //////////// in work } if( flag == 2 ) { return(1); } return(0); } int correction ( unsigned char KEY, char speedflag ) { int speed,speedct; unsigned char mflags,_key; double v,abs; if( ( KEY == KEY_LEFT ) || ( KEY == KEY_RIGHT ) ) { _key = KEY; speed = SPEED_HO; speedct = SPEED_HO_CT; mflags = MOT_FLAGS; MOT_FLAGS = 0; if( speedflag == '1' ){ SPEED_HO = CFG_SP1_HO; } else { SPEED_HO = CFG_SP2_HO; } MOT_CORRECTION = ON; SPEED_HO_CT = 0; if( KEY == KEY_LEFT ) { MOTHO_DIR = LEFT; } MOTHO_RUN = ON; while( testkey() == _key ) {;} MOTHO_RUN = OFF; SPEED_HO = speed; SPEED_HO_CT = speedct; MOT_FLAGS = mflags; v = (double)CUR_HSTEPS_HO * (double)CFG_HSTS_HO * (double)10; modf( v , &abs); CUR_ARC10_HO = (long)abs; return(1); } if( ( KEY == KEY_UP ) || ( KEY == KEY_DOWN ) ) { _key = KEY; speed = SPEED_VE; speedct = SPEED_VE_CT; mflags = MOT_FLAGS; MOT_FLAGS = 0; if( speedflag == '1' ){ SPEED_VE = CFG_SP1_VE; } else { SPEED_VE = CFG_SP2_VE; } MOT_CORRECTION = ON; SPEED_VE_CT = 0; if( KEY == KEY_DOWN ) { MOTVE_DIR = DOWN; } MOTVE_RUN = ON; while( testkey() == _key ) {;} MOTVE_RUN = OFF; SPEED_VE = speed; SPEED_VE_CT = speedct; MOT_FLAGS = mflags; v = (double)CUR_HSTEPS_VE * (double)CFG_HSTS_VE * (double)10; modf( v , &abs); CUR_ARC10_VE = (long)abs; return(1); } return(0); } #define statusflag_auto status2[1] #define statusflag_speed status2[4] #define statusflag_fr status2[7] #define statusflag_motor status2[10] #define statusflag_enc status2[13] void scope( void ) { unsigned char KEY; // char status1[20]; char status2[20]; int mode,upd; double ho,ve; long test; MOT_FLAGS = 0; lcd_clear(); initEncoderValues(); initScopeValues(); KEY = 0; mode = 0; upd = 1; strcpy( status2,"a1 s1 f0 m0 e0"); ENABLEMOTORS; if( ENCHO_USE ){ startEncoderIntsHo(); } if( ENCVE_USE ) { startEncoderIntsVe(); } while( KEY != KEY_EXIT ) { if(upd){ lcd_clear(); switch( mode ) { case 0: statusflag_motor = '0'; statusflag_fr = '0'; statusflag_enc = '0'; if( MOT_GOTO == ON ){ statusflag_motor = '1'; } if( MOTFR_USE == ON ){ statusflag_fr = '1'; } if( ( ENCHO_CORUSE == ON ) || ( ENCVE_CORUSE == ON )){ statusflag_enc = '1'; } lcd_puts(3,0,status2); break; case 1: printDegrees(2,OBJ_DEG_RA); printDegrees(3,OBJ_DEG_DEC); break; } upd = 0; } printArc10Degrees(0,CUR_ARC10_HO); printArc10Degrees(1,CUR_ARC10_VE); KEY = testkey(); if( ! KEY ) { // doing calcualtions for goto/guiding ...... if( MOT_GOTO == ON ) { if( calcTarget() ) { if( statusflag_auto == '0' ){ MOT_GOTO = OFF; MOTHO_RUN = OFF; MOTVE_RUN = OFF; upd = 1; } } test++; } continue; } if( correction( KEY, statusflag_speed ) ) { upd = 1; continue; } KEY = readkey(); if( ! KEY ) { continue; } // from here key is released, and no cursor key // first the keys used, where motors mut not be stopped if( KEY == KEY_FR ){ //switching field-rotator on/off if( MOTFR_USE == OFF ){ MOTFR_USE = ON; } else { MOTFR_USE = OFF; } upd = 1; continue; } if( KEY == KEY_AUTO ){ //switching continuous goto ( guiding after goto ) on/off if( statusflag_auto == '0' ){ statusflag_auto = '1'; } else { statusflag_auto = '0'; } upd = 1; continue; } if( KEY == KEY_ENC ){ //switching correction from encoders on/off //( if encoders are set to on ) if( ENCHO_USE == ON ) { if( ENCHO_CORUSE == ON ) { ENCHO_CORUSE = OFF; } else { ENCHO_CORUSE = ON; } } if( ENCVE_USE == ON ) { if( ENCVE_CORUSE == ON ) { ENCVE_CORUSE = OFF; } else { ENCVE_CORUSE = ON; } } upd = 1; continue; } if( KEY == KEY_SPD ){ //setting correctionspeed for motors to speed 1, or 2 if( statusflag_speed == '1' ){ statusflag_speed = '2'; } else { statusflag_speed = '1'; } upd = 1; continue; } if( KEY == KEY_KOOR ){ //mode 0 = showing statusline 2/3 ( current settings ... ) //mode 1 = showing objkoors 2/3 mode++; if(mode > 1){ mode = 0; } upd = 1; continue; } // and now, - all the others ///////////////////////////// MOT_GOTO = OFF; MOT_CORRECTION = OFF; MOTHO_RUN = OFF; MOTVE_RUN = OFF; ENCHO_COR = OFF; ENCVE_COR = OFF; upd = 1; if( KEY == KEY_GO ) { //start goto //this means, if current koors not objkoors, it runs to them, till reached //if auto is set ( default ) this will be done continuousely ( guiding ) SPEED_HO = CFG_SP3_HO; SPEED_VE = CFG_SP3_VE; SPEED_FR = CFG_SP_FR; SPEED_HO_CT = 0; SPEED_VE_CT = 0; SPEED_FR_CT = 0; KOOR_RA = OBJ_DEG_RA; KOOR_DEC = OBJ_DEG_DEC; if( statusflag_auto == '1' ) { test = 0; calcTarget(); MOT_GOTO = ON; } else { if( ! calcTarget() ) { test = 0; MOT_GOTO = ON; } } continue; } if( KEY == KEY_GUIDE ) { //start guiding, - means following of current set halfsteps SPEED_HO = CFG_SP3_HO; SPEED_VE = CFG_SP3_VE; SPEED_FR = CFG_SP_FR; SPEED_HO_CT = 0; SPEED_VE_CT = 0; SPEED_FR_CT = 0; //calculating current halfsteps to //KOOR_RA/KOOR_DEC KOOR_AZ = ( (double)CUR_HSTEPS_HO * (double)CFG_HSTS_HO ) / (double)3600; KOOR_ALT = ( (double)CUR_HSTEPS_VE * (double)CFG_HSTS_VE ) / (double)3600; cCurrentStarTime(); cRaDec(); statusflag_auto = '1'; test = 0; calcTarget(); MOT_GOTO = ON; continue; } if( KEY == KEY_OBJ ){ //getting object per manual input ho = KOOR_RA; ve = KOOR_DEC; KOOR_AZ = ( (double)CUR_HSTEPS_HO * (double)CFG_HSTS_HO ) / (double)3600; KOOR_ALT = ( (double)CUR_HSTEPS_VE * (double)CFG_HSTS_VE ) / (double)3600; cCurrentStarTime(); cRaDec(); usrGetKoor(0, KOOR_RA, KOOR_DEC ); KOOR_RA = ho; KOOR_DEC = ve; continue; } if( KEY == KEY_DB ){ //getting object from database //this must set OBJ_DEG_RA/OBJ_DEG_DEC in the same way as usrGetKoor /////////////////////////////////////////////////////////////////// getListObj(); continue; } if( KEY == KEY_ORG ){ //origin current with obj-koors origin(); continue; } } // end of scope MOT_FLAGS = 0; DISABLEMOTORS; stopEncoderInts(); sprintf(status2,"%10ld",test); lcd_puts(3,0,status2); while( readkey() == 0 ){;} } void encode( void ) { unsigned char KEY; char tmp1[20]; char tmp2[20]; int mode,upd; lcd_clear(); ENCHO_CORUSE = OFF; ENCVE_CORUSE = OFF; initEncoderValues(); if( ENCHO_USE ){ startEncoderIntsHo(); } if( ENCVE_USE ) { startEncoderIntsVe(); } KEY = 0; mode = 0; upd = 1; while( KEY != KEY_EXIT ) { switch( mode ) { case 0: printArc10Degrees(0,ENC_ARC10_HO); printArc10Degrees(1,ENC_ARC10_VE); break; case 1: KOOR_AZ = lArc10dDegrees( ENC_ARC10_HO ); KOOR_ALT = lArc10dDegrees( ENC_ARC10_VE ); cCurrentStarTime(); cRaDec(); printDegrees(0,KOOR_RA); printDegrees(1,KOOR_DEC); break; } if(upd){ switch( mode ) { case 0: strcpy(tmp1,"AZ K"); strcpy(tmp2,"ALT K"); lcd_puts(0,11,tmp1); lcd_puts(1,11,tmp2); printArc10Degrees(2,OBJ_ARC10_HO); printArc10Degrees(3,OBJ_ARC10_VE); strcpy(tmp1,"AZ O"); strcpy(tmp2,"ALT O"); lcd_puts(2,11,tmp1); lcd_puts(3,11,tmp2); break; case 1: strcpy(tmp1,"RA K"); strcpy(tmp2,"DEC K"); lcd_puts(0,11,tmp1); lcd_puts(1,11,tmp2); printDegrees(2,OBJ_DEG_RA); printDegrees(3,OBJ_DEG_DEC); strcpy(tmp1,"RA O"); strcpy(tmp2,"DEC O"); lcd_puts(2,11,tmp1); lcd_puts(3,11,tmp2); break; } upd = 0; } KEY = 0; KEY = readkey(); if( KEY ){ if( KEY == KEY_KOOR ){ if( mode == 0 ) { mode = 1; } else { mode = 0; } upd = 1; continue; } if( KEY == KEY_OBJ ){ //getting object per manual input mode = 1; usrGetKoor(0, 0, 0); upd = 1; continue; } if( KEY == KEY_DB ){ //getting object from database //this must set OBJ_DEG_RA/OBJ_DEG_DEC in the same way as usrGetKoor mode = 1; getListObj(); upd = 1; continue; } if( KEY == KEY_ORG ){ //origin current with obj-koors origin(); upd = 1; continue; } } } stopEncoderInts(); } void showEncoders( int mode ) { unsigned char KEY; char tmp1[20]; char tmp2[20]; lcd_clear(); ENCHO_CORUSE = OFF; ENCVE_CORUSE = OFF; initEncoderValues(); switch( mode ){ case 0: sprintf(tmp1,"ENC HORIZONTAL"); sprintf(tmp2,"ENC VERTICAL"); break; case 1: sprintf(tmp1,"ARC10 HORIZONTAL"); sprintf(tmp2,"ARC10 VERTICAL"); break; case 2: sprintf(tmp1,"AZ"); sprintf(tmp2,"ALT"); break; case 3: sprintf(tmp1,"RA"); sprintf(tmp2,"DEC"); break; } lcd_puts(0,0,tmp1); lcd_puts(2,0,tmp2); if( ENCHO_USE ){ startEncoderIntsHo(); } if( ENCVE_USE ) { startEncoderIntsVe(); } KEY = 0; while(! KEY ) { KEY = readkey(); switch( mode ) { case 0: sprintf(tmp1,"%010ld",ENC_ARC10_HO); sprintf(tmp2,"%010ld",ENC_ARC10_VE); lcd_puts(1,0,tmp1); lcd_puts(3,0,tmp2); break; case 1: printArc10Degrees(1,ENC_ARC10_HO); printArc10Degrees(3,ENC_ARC10_VE); break; case 2: KOOR_AZ = lArc10dDegrees( ENC_ARC10_HO ); KOOR_ALT = lArc10dDegrees( ENC_ARC10_VE ); cCurrentStarTime(); cRaDec(); printDegrees(1,KOOR_RA); printDegrees(3,KOOR_DEC); break; } } stopEncoderInts(); } void encAutoTestHo( void ) { char tmp[20]; int signr,ct; long l,enc; double d; lcd_clear(); sprintf(tmp,"TYPE NR ENCSIGS."); lcd_puts(0,0,tmp); while( readkey() == NOKEY ){;} signr = usrGetInt( 0 , 10 ); if( signr <= 0){ return; } lcd_clear(); sprintf(tmp,"PLEASE WAIT"); lcd_puts(0,0,tmp); initEncoderValues(); initScopeValues(); MOT_FLAGS = 0; stopEncoderInts(); ENABLEMOTORS; ENCHO_COR = OFF; ENCHO_CORUSE = OFF; startEncoderIntsHo(); SPEED_HO = CFG_SP3_HO; SPEED_HO_CT = 0; CUR_HSTEPS_HO = 0; MOTHO_DIR = RIGHT; MOT_CORRECTION = ON; ENC_ARC10_HO = (long)0; MOTHO_RUN = ON; while( ENC_ARC10_HO == (long)0 ) {;} MOTHO_RUN = OFF; ENC_ARC10_HO = (long)0; MOTHO_RUN = ON; while( ENC_ARC10_HO == (long)0 ) {;} MOTHO_RUN = OFF; CUR_HSTEPS_HO = 0; ENC_ARC10_HO = 0; enc = (long)signr * (long)ARC10PERENCHO; ct = 0; MOTHO_RUN = ON; while( ENC_ARC10_HO < enc ) {;} MOT_FLAGS = 0; DISABLEMOTORS; stopEncoderInts(); lcd_clear(); sprintf(tmp,"HALFSTEPS:"); lcd_puts(0,0,tmp); sprintf(tmp,"%10ld",CUR_HSTEPS_HO); lcd_puts(1,0,tmp); sprintf(tmp,"HALFSTEPSIZE:"); lcd_puts(2,0,tmp); l = (long)ENC_ARC10_HO; d = (double)l / (double) CUR_HSTEPS_HO; d = (double)d / (double)10; sprintf(tmp,"%016.6f",d); lcd_puts(3,0,tmp); while( readkey() == NOKEY ){;} CFG_HSTS_HO = d; } void encAutoTestVe( void ) { char tmp[20]; int signr,ct; long l,enc; double d; lcd_clear(); sprintf(tmp,"TYPE NR ENCSIGS."); lcd_puts(0,0,tmp); while( readkey() == NOKEY ){;} signr = usrGetInt( 0 , 10 ); if( signr <= 0){ return; } lcd_clear(); sprintf(tmp,"PLEASE WAIT"); lcd_puts(0,0,tmp); initEncoderValues(); initScopeValues(); MOT_FLAGS = 0; stopEncoderInts(); ENABLEMOTORS; ENCVE_COR = OFF; ENCVE_CORUSE = OFF; startEncoderIntsVe(); SPEED_VE = CFG_SP3_VE; SPEED_VE_CT = 0; CUR_HSTEPS_VE = 0; MOTVE_DIR = UP; MOT_CORRECTION = ON; ENC_ARC10_VE = (long)0; MOTVE_RUN = ON; while( ENC_ARC10_VE == (long)0 ) {;} MOTVE_RUN = OFF; ENC_ARC10_VE = (long)0; MOTVE_RUN = ON; while( ENC_ARC10_VE == (long)0 ) {;} MOTVE_RUN = OFF; CUR_HSTEPS_VE = 0; ENC_ARC10_VE = 0; enc = (long)signr * (long)ARC10PERENCVE; ct = 0; MOTVE_RUN = ON; while( ENC_ARC10_VE < enc ) {;} MOT_FLAGS = 0; DISABLEMOTORS; stopEncoderInts(); lcd_clear(); sprintf(tmp,"HALFSTEPS:"); lcd_puts(0,0,tmp); sprintf(tmp,"%10ld",CUR_HSTEPS_VE); lcd_puts(1,0,tmp); sprintf(tmp,"HALFSTEPSIZE:"); lcd_puts(2,0,tmp); l = (long)ENC_ARC10_VE; d = (double)l / (double) CUR_HSTEPS_VE; d = (double)d / (double)10; sprintf(tmp,"%016.6f",d); lcd_puts(3,0,tmp); while( readkey() == NOKEY ){;} CFG_HSTS_VE = d; }