/* * This file is part of the libsidservo project. * Copyright 2025 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ // dump telescope moving using short binary commands #include #include #include #include #include #include #include "dump.h" #include "sidservo.h" #include "simpleconv.h" #include "ssii.h" typedef struct{ int help; int Ncycles; char *coordsoutput; } parameters; static parameters G = { .Ncycles = 40, }; static FILE *fcoords = NULL; static sl_option_t cmdlnopts[] = { {"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"}, {"ncycles", NEED_ARG, NULL, 'n', arg_int, APTR(&G.Ncycles), "N cycles in stopped state (default: 40)"}, {"coordsfile", NEED_ARG, NULL, 'o', arg_string, APTR(&G.coordsoutput),"output file with coordinates log"}, end_option }; void signals(int sig){ if(sig){ signal(sig, SIG_IGN); DBG("Get signal %d, quit.\n", sig); } Mount.quit(); exit(sig); } static conf_t Config = { .MountDevPath = "/dev/ttyUSB0", .MountDevSpeed = 19200, //.EncoderDevPath = "/dev/ttyUSB1", //.EncoderDevSpeed = 153000, .MountReqInterval = 0.1, .SepEncoder = 0 }; // dump thread static void *dumping(void _U_ *u){ dumpmoving(fcoords, 90., G.Ncycles); return NULL; } // return TRUE if motor position is reached +-2 counts #define X2count (X_RAD2MOT(2)) #define Y2count (Y_RAD2MOT(2)) static int Xreached(double xtag){ mountdata_t mdata; if(MCC_E_OK != Mount.getMountData(&mdata)) return FALSE; if(fabs(mdata.motposition.X - xtag) <= X2count) return TRUE; return FALSE; } /* static int Yreached(double ytag){ mountdata_t mdata; if(MCC_E_OK != Mount.getMountData(&mdata)) return FALSE; if(fabs(mdata.motposition.Y - ytag) <= Y2count) return TRUE; return FALSE; } */ int main(int argc, char **argv){ sl_init(); sl_parseargs(&argc, &argv, cmdlnopts); if(G.help) sl_showhelp(-1, cmdlnopts); if(G.coordsoutput){ if(!(fcoords = fopen(G.coordsoutput, "w"))) ERRX("Can't open %s", G.coordsoutput); }else fcoords = stdout; logmnt(fcoords, NULL); mcc_errcodes_t e = Mount.init(&Config); if(e != MCC_E_OK){ WARNX("Can't init devices"); return 1; } signal(SIGTERM, signals); // kill (-15) - quit signal(SIGHUP, SIG_IGN); // hup - ignore signal(SIGINT, signals); // ctrl+C - quit signal(SIGQUIT, signals); // ctrl+\ - quit signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z // move to X=30 degr with different speeds // start with 1degr/s, increase to 15, decrease to 1 short_command_t cmd = {0}; pthread_t dthr; if(pthread_create(&dthr, NULL, dumping, NULL)) ERRX("Can't run dump thread"); #define SCMD() do{if(MCC_E_OK != Mount.shortCmd(&cmd)) ERRX("Can't run command"); }while(0) // goto 5 degr with 1deg/s cmd.Xmot = DEG2RAD(30.); cmd.Xspeed = DEG2RAD(1.); SCMD(); while(!Xreached(DEG2RAD(5.))); // goto 15 degr with 5deg/s cmd.Xmot = DEG2RAD(30.); cmd.Xspeed = DEG2RAD(5.); SCMD(); while(!Xreached(DEG2RAD(10.))); // goto 25 degr with 15deg/s cmd.Xmot = DEG2RAD(30.); cmd.Xspeed = DEG2RAD(15.); SCMD(); while(!Xreached(DEG2RAD(25.))); // goto 29.9 degr with 1deg/s cmd.Xmot = DEG2RAD(30.); cmd.Xspeed = DEG2RAD(1.); SCMD(); while(!Xreached(DEG2RAD(29.9))); // and go back with 15deg/s cmd.Xmot = DEG2RAD(0.); cmd.Xspeed = DEG2RAD(15.); SCMD(); while(!Xreached(DEG2RAD(0.1))); Mount.moveTo(0., 0.); // wait moving ends pthread_join(dthr, NULL); #undef SCMD signals(0); return 0; }