This commit is contained in:
2025-02-24 22:23:52 +03:00
parent 5e3cc5b31a
commit f83f95c9cc
12 changed files with 186 additions and 61 deletions

View File

@@ -0,0 +1,24 @@
Some examples of usage of libsidservo
=====================================
## Auxiliary files
*dump.c*, *dump.h* - base logging and dumping functions, also some useful functions like get current position and move to zero if current position isn't at zero.
*traectories.c*, *traectories.h* - modeling simple moving object traectories; also some functions like get current position in encoders' angles setting to zero at motors' zero.
*simpleconv.h*
## Examples
*dumpmoving.c* (`dump`) - dump moving relative starting point by simplest text commands "X" and "Y".
*dumpmoving_scmd.c* (`dump_s`) - moving relative starting point using "short" binary command.
*dumpswing.c* (`dumpswing`) - shake telescope around starting point by one of axis.
*goto.c* (`goto`) - get current coordinates or go to given (by simplest "X/Y" commands).
*scmd_traectory.c* (`traectory_s`) - try to move around given traectory using "short" binary commands.

View File

@@ -107,13 +107,13 @@ void waitmoving(int N){
}
/**
* @brief getMotPos - get current
* @brief getPos - get current position
* @param mot (o) - motor position (or NULL)
* @param Y (o) - encoder position (or NULL)
* @return FALSE if failed
*/
int getPos(coords_t *mot, coords_t *enc){
mountdata_t mdata;
mountdata_t mdata = {0};
int errcnt = 0;
do{
if(MCC_E_OK != Mount.getMountData(&mdata)) ++errcnt;
@@ -137,7 +137,8 @@ void chk0(int ncycles){
if(!getPos(&M, NULL)) signals(2);
if(M.X || M.Y){
WARNX("Mount position isn't @ zero; moving");
Mount.moveTo(0., 0.);
double zero = 0.;
Mount.moveTo(&zero, &zero);
waitmoving(ncycles);
green("Now mount @ zero\n");
}

View File

@@ -95,10 +95,11 @@ int main(int argc, char **argv){
signal(SIGINT, signals); // ctrl+C - quit
signal(SIGQUIT, signals); // ctrl+\ - quit
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
if(MCC_E_OK != Mount.moveTo(DEG2RAD(45.), DEG2RAD(45.)))
double tag = DEG2RAD(45.), zero = 0.;
if(MCC_E_OK != Mount.moveTo(&tag, &tag))
ERRX("Can't move to 45, 45");
dumpmoving(fcoords, 30., G.Ncycles);
Mount.moveTo(0., 0.);
Mount.moveTo(&zero, &zero);
dumpmoving(fcoords, 30., G.Ncycles);
signals(0);
return 0;

View File

@@ -72,6 +72,8 @@ static conf_t Config = {
.SepEncoder = 0
};
static coords_t M;
// dump thread
static void *dumping(void _U_ *u){
dumpmoving(fcoords, 3600., G.Ncycles);
@@ -108,20 +110,22 @@ static int Wait(double tag){
return TRUE;
}
// move X to 40 degr with given speed until given coord
// move X/Y to 40 degr with given speed until given coord
static void move(double target, double limit, double speed){
#define SCMD() do{if(MCC_E_OK != Mount.shortCmd(&cmd)) ERRX("Can't run command"); }while(0)
green("Move %s to %g until %g with %gdeg/s\n", G.axis, target, limit, speed);
short_command_t cmd = {0};
if(*G.axis == 'X'){
cmd.Xmot = DEG2RAD(target);
cmd.Xmot = DEG2RAD(target) + M.X;
cmd.Xspeed = DEG2RAD(speed);
limit = DEG2RAD(limit) + M.X;
}else{
cmd.Ymot = DEG2RAD(target);
cmd.Ymot = DEG2RAD(target) + M.Y;
cmd.Yspeed = DEG2RAD(speed);
limit = DEG2RAD(limit) + M.Y;
}
SCMD();
if(!Wait(DEG2RAD(limit))) signals(9);
if(!Wait(limit)) signals(9);
#undef SCMD
}
@@ -139,11 +143,11 @@ int main(int argc, char **argv){
ERRX("Can't open %s", G.coordsoutput);
}else fcoords = stdout;
Config.MountReqInterval = G.reqint;
mcc_errcodes_t e = Mount.init(&Config);
if(e != MCC_E_OK){
if(MCC_E_OK != Mount.init(&Config)){
WARNX("Can't init devices");
return 1;
}
if(!getPos(&M, NULL)) ERRX("Can't get current position");
signal(SIGTERM, signals); // kill (-15) - quit
signal(SIGHUP, SIG_IGN); // hup - ignore
signal(SIGINT, signals); // ctrl+C - quit
@@ -151,7 +155,6 @@ int main(int argc, char **argv){
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
// move to X=40 degr with different speeds
pthread_t dthr;
chk0(G.Ncycles);
logmnt(fcoords, NULL);
if(pthread_create(&dthr, NULL, dumping, NULL)) ERRX("Can't run dump thread");
// goto 1 degr with 1'/s
@@ -165,7 +168,7 @@ int main(int argc, char **argv){
// and go back with 5deg/s
move(0., 0., 5.);
// be sure to move @ 0,0
Mount.moveTo(0., 0.);
Mount.moveTo(&M.X, &M.Y);
// wait moving ends
pthread_join(dthr, NULL);
#undef SCMD

View File

@@ -147,23 +147,24 @@ int main(int argc, char **argv){
tagX = 0.; tagY = DEG2RAD(G.amplitude);
}
double t = sl_dtime(), t0 = t;
double divide = 2.;
double divide = 2., rtagX = -tagX, rtagY = -tagY;
for(int i = 0; i < G.Nswings; ++i){
Mount.moveTo(tagX, tagY);
Mount.moveTo(&tagX, &tagY);
DBG("CMD: %g", sl_dtime()-t0);
t += G.period / divide;
divide = 1.;
waithalf(t);
DBG("Moved to +, t=%g", t-t0);
DBG("CMD: %g", sl_dtime()-t0);
Mount.moveTo(-tagX, -tagY);
Mount.moveTo(&rtagX, &rtagY);
t += G.period;
waithalf(t);
DBG("Moved to -, t=%g", t-t0);
DBG("CMD: %g", sl_dtime()-t0);
}
double zero = 0.;
// be sure to move @ 0,0
Mount.moveTo(0., 0.);
Mount.moveTo(&zero, &zero);
// wait moving ends
pthread_join(dthr, NULL);
#undef SCMD

View File

@@ -31,6 +31,7 @@ typedef struct{
int help;
int Ncycles;
int wait;
int relative;
char *coordsoutput;
double X;
double Y;
@@ -49,6 +50,7 @@ static sl_option_t cmdlnopts[] = {
{"newy", NEED_ARG, NULL, 'Y', arg_double, APTR(&G.Y), "new Y coordinate"},
{"output", NEED_ARG, NULL, 'o', arg_string, APTR(&G.coordsoutput),"file to log coordinates"},
{"wait", NO_ARGS, NULL, 'w', arg_int, APTR(&G.wait), "wait until mowing stopped"},
{"relative", NO_ARGS, NULL, 'r', arg_int, APTR(&G.relative), "relative move"},
end_option
};
@@ -100,10 +102,22 @@ int main(int _U_ argc, char _U_ **argv){
}
printf("Mount position: X=%g, Y=%g\n", RAD2DEG(M.X), RAD2DEG(M.Y));
if(isnan(G.X) && isnan(G.Y)) goto out;
if(isnan(G.X)) G.X = RAD2DEG(M.X);
if(isnan(G.Y)) G.Y = RAD2DEG(M.Y);
printf("Moving to X=%g deg, Y=%g deg\n", G.X, G.Y);
Mount.moveTo(DEG2RAD(G.X), DEG2RAD(G.Y));
double *xtag = NULL, *ytag = NULL, xr, yr;
if(!isnan(G.X)){
xr = DEG2RAD(G.X);
if(G.relative) xr += M.X;
xtag = &xr;
}
if(!isnan(G.Y)){
yr = DEG2RAD(G.Y);
if(G.relative) yr += M.Y;
ytag = &yr;
}
printf("Moving to ");
if(xtag) printf("X=%gdeg ", G.X);
if(ytag) printf("Y=%gdeg", G.Y);
printf("\n");
Mount.moveTo(xtag, ytag);
if(G.wait){
sleep(1);
waitmoving(G.Ncycles);