shortcmd checked

This commit is contained in:
2025-02-16 21:59:08 +03:00
parent 53b18299dc
commit 5250aa185d
13 changed files with 281 additions and 94 deletions

View File

@@ -28,7 +28,6 @@
#include "dump.h"
#include "sidservo.h"
#include "simpleconv.h"
#include "ssii.h"
typedef struct{
int help;
@@ -72,14 +71,32 @@ static void *dumping(void _U_ *u){
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){
// return TRUE if motor position is reached +- 0.1 degrees
#define X2count (DEG2RAD(0.1))
#define Y2count (DEG2RAD(0.1))
static int WaitX(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;
red("Wait for %g degrees\n", RAD2DEG(xtag));
int errcnt = 0;
double sign = 0.;
uint32_t millis = 0;
do{
if(MCC_E_OK != Mount.getMountData(&mdata)) ++errcnt;
else{
errcnt = 0;
if(mdata.millis == millis) continue;
millis = mdata.millis;
if(sign == 0.) sign = (mdata.motposition.X > xtag) ? 1. : -1.;
printf("X=%g deg, need %g deg; delta=%g arcmin\n", RAD2DEG(mdata.motposition.X),
RAD2DEG(xtag), RAD2DEG(sign*(mdata.motposition.X - xtag))*60.);
}
}while(sign*(mdata.motposition.X - xtag) > X2count && errcnt < 10);
if(errcnt >= 10){
WARNX("Too much errors");
return FALSE;
}
green("X reached position %g degrees\n", RAD2DEG(xtag));
return TRUE;
}
/*
static int Yreached(double ytag){
@@ -90,6 +107,18 @@ static int Yreached(double ytag){
}
*/
// check current position and go to 0 if non-zero
static void chk0(){
coords_t M;
if(!getPos(&M, NULL)) signals(2);
if(M.X || M.Y){
WARNX("Mount position isn't @ zero; moving");
Mount.moveTo(0., 0.);
waitmoving(G.Ncycles);
green("Now mount @ zero\n");
}
}
int main(int argc, char **argv){
sl_init();
sl_parseargs(&argc, &argv, cmdlnopts);
@@ -98,7 +127,6 @@ int main(int argc, char **argv){
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");
@@ -113,34 +141,37 @@ int main(int argc, char **argv){
// 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
chk0();
logmnt(fcoords, NULL);
if(pthread_create(&dthr, NULL, dumping, NULL)) ERRX("Can't run dump thread");
// goto 10 degr with 1deg/s
cmd.Xmot = DEG2RAD(30.);
cmd.Xspeed = DEG2RAD(1.);
SCMD();
while(!Xreached(DEG2RAD(5.)));
// goto 15 degr with 5deg/s
if(!WaitX(DEG2RAD(10.))) signals(9);
// goto 20 degr with 5deg/s
cmd.Xmot = DEG2RAD(30.);
cmd.Xspeed = DEG2RAD(2.);
SCMD();
if(!WaitX(DEG2RAD(20.))) signals(9);
// goto 30 degr with 15deg/s
cmd.Xmot = DEG2RAD(40.);
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.);
if(!WaitX(DEG2RAD(30.))) signals(9);
// goto 40 degr with 1deg/s
cmd.Xmot = DEG2RAD(40.);
cmd.Xspeed = DEG2RAD(1.);
SCMD();
while(!Xreached(DEG2RAD(29.9)));
if(!WaitX(DEG2RAD(40.))) signals(9);
// and go back with 15deg/s
cmd.Xmot = DEG2RAD(0.);
cmd.Xspeed = DEG2RAD(15.);
SCMD();
while(!Xreached(DEG2RAD(0.1)));
if(!WaitX(DEG2RAD(0.))) signals(9);
Mount.moveTo(0., 0.);
waitmoving(10);
// wait moving ends
pthread_join(dthr, NULL);
#undef SCMD