shortcmd checked
This commit is contained in:
@@ -5,5 +5,6 @@ include_directories(../)
|
||||
link_libraries(sidservo usefull_macros)
|
||||
|
||||
# exe list
|
||||
add_executable(goto goto.c dump.c)
|
||||
add_executable(dump dumpmoving.c dump.c)
|
||||
add_executable(dump_s dumpmoving_scmd.c dump.c)
|
||||
|
||||
@@ -29,10 +29,9 @@
|
||||
* @param m - mount data
|
||||
*/
|
||||
void logmnt(FILE *fcoords, mountdata_t *m){
|
||||
if(!fcoords || !m) return;
|
||||
DBG("LOG");
|
||||
static double t0 = -1.;
|
||||
if(!fcoords) return;
|
||||
//DBG("LOG %s", m ? "data" : "header");
|
||||
static double t0 = -1.;
|
||||
if(!m){ // write header
|
||||
fprintf(fcoords, "# time Xmot(deg) Ymot(deg) Xenc(deg) Yenc(deg) millis T V\n");
|
||||
return;
|
||||
@@ -73,7 +72,7 @@ void dumpmoving(FILE *fcoords, double t, int N){
|
||||
usleep(10000);
|
||||
if(MCC_E_OK != Mount.getMountData(&mdata)){ WARNX("Can't get data"); continue;}
|
||||
if(mdata.millis == millis) continue;
|
||||
DBG("Got new data, posX=%g, posY=%g", mdata.motposition.X, mdata.motposition.Y);
|
||||
//DBG("Got new data, posX=%g, posY=%g", mdata.motposition.X, mdata.motposition.Y);
|
||||
millis = mdata.millis;
|
||||
if(fcoords) logmnt(fcoords, &mdata);
|
||||
if(mdata.motposition.X != xlast || mdata.motposition.Y != ylast){
|
||||
@@ -104,3 +103,28 @@ void waitmoving(int N){
|
||||
}else ++ctr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief getMotPos - get current
|
||||
* @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;
|
||||
int errcnt = 0;
|
||||
do{
|
||||
if(MCC_E_OK != Mount.getMountData(&mdata)) ++errcnt;
|
||||
else{
|
||||
errcnt = 0;
|
||||
if(mdata.millis) break;
|
||||
}
|
||||
}while(errcnt < 10);
|
||||
if(errcnt >= 10){
|
||||
WARNX("Can't read mount status");
|
||||
return FALSE;
|
||||
}
|
||||
if(mot) *mot = mdata.motposition;
|
||||
if(enc) *enc = mdata.encposition;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -25,3 +25,4 @@
|
||||
void logmnt(FILE *fcoords, mountdata_t *m);
|
||||
void dumpmoving(FILE *fcoords, double t, int N);
|
||||
void waitmoving(int N);
|
||||
int getPos(coords_t *mot, coords_t *enc);
|
||||
|
||||
@@ -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
|
||||
|
||||
91
LibSidServo/examples/goto.c
Normal file
91
LibSidServo/examples/goto.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This file is part of the libsidservo project.
|
||||
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// move telescope to given MOTOR position in degrees
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <usefull_macros.h>
|
||||
|
||||
#include "dump.h"
|
||||
#include "sidservo.h"
|
||||
#include "simpleconv.h"
|
||||
|
||||
typedef struct{
|
||||
int help;
|
||||
int Ncycles;
|
||||
double X;
|
||||
double Y;
|
||||
} parameters;
|
||||
|
||||
static parameters G = {
|
||||
.Ncycles = 40,
|
||||
.X = NAN,
|
||||
.Y = NAN,
|
||||
};
|
||||
|
||||
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 of waiting in stopped state (default: 40)"},
|
||||
{"newx", NEED_ARG, NULL, 'X', arg_double, APTR(&G.X), "New X coordinate"},
|
||||
{"newy", NEED_ARG, NULL, 'Y', arg_double, APTR(&G.Y), "New Y coordinate"},
|
||||
end_option
|
||||
};
|
||||
|
||||
static conf_t Config = {
|
||||
.MountDevPath = "/dev/ttyUSB0",
|
||||
.MountDevSpeed = 19200,
|
||||
//.EncoderDevPath = "/dev/ttyUSB1",
|
||||
//.EncoderDevSpeed = 153000,
|
||||
.MountReqInterval = 0.1,
|
||||
.SepEncoder = 0
|
||||
};
|
||||
|
||||
void signals(int sig){
|
||||
if(sig){
|
||||
signal(sig, SIG_IGN);
|
||||
DBG("Get signal %d, quit.\n", sig);
|
||||
}
|
||||
Mount.quit();
|
||||
exit(sig);
|
||||
}
|
||||
|
||||
int main(int _U_ argc, char _U_ **argv){
|
||||
sl_init();
|
||||
sl_parseargs(&argc, &argv, cmdlnopts);
|
||||
if(G.help) sl_showhelp(-1, cmdlnopts);
|
||||
if(MCC_E_OK != Mount.init(&Config)) ERRX("Can't init mount");
|
||||
coords_t M;
|
||||
if(!getPos(&M, NULL)) ERRX("Can't get current position");
|
||||
printf("Mount position: X=%g, Y=%g\n", RAD2DEG(M.X), RAD2DEG(M.Y));
|
||||
if(isnan(G.X) && isnan(G.Y)){
|
||||
Mount.quit();
|
||||
return 0;
|
||||
}
|
||||
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));
|
||||
sleep(1);
|
||||
waitmoving(G.Ncycles);
|
||||
if(!getPos(&M, NULL)) WARNX("Can't get current position");
|
||||
else printf("New mount position: X=%g, Y=%g\n", RAD2DEG(M.X), RAD2DEG(M.Y));
|
||||
Mount.quit();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user