mirror of
https://github.com/eddyem/astrovideoguide_v3.git
synced 2025-12-06 10:45:10 +03:00
fixed output center coordinate format, fixed disconnection of canserver @ each error
This commit is contained in:
parent
68449bef89
commit
31a5aeaa93
@ -275,8 +275,9 @@ void process_file(Image *I){
|
|||||||
int H = I->height;
|
int H = I->height;
|
||||||
// draw current star centroid
|
// draw current star centroid
|
||||||
Pattern_draw3(&i3, cross, Objects[0].xc, H-Objects[0].yc, C_G);
|
Pattern_draw3(&i3, cross, Objects[0].xc, H-Objects[0].yc, C_G);
|
||||||
xc = Objects[0].xc;
|
// add offset to show in target system
|
||||||
yc = Objects[0].yc;
|
xc = Objects[0].xc + theconf.xoff;
|
||||||
|
yc = Objects[0].yc + theconf.yoff;
|
||||||
// draw other centroids
|
// draw other centroids
|
||||||
for(int i = 1; i < objctr; ++i)
|
for(int i = 1; i < objctr; ++i)
|
||||||
Pattern_draw3(&i3, cross, Objects[i].xc, H-Objects[i].yc, C_R);
|
Pattern_draw3(&i3, cross, Objects[i].xc, H-Objects[i].yc, C_R);
|
||||||
|
|||||||
@ -120,6 +120,8 @@ typedef struct{
|
|||||||
} relaystate;
|
} relaystate;
|
||||||
static _Atomic relaystate relay;
|
static _Atomic relaystate relay;
|
||||||
|
|
||||||
|
static int errctr = 0; // sending messages error counter (if > MAX_ERR_CTR, set state to disconnected)
|
||||||
|
|
||||||
static pusistate state = PUSI_DISCONN; // server state
|
static pusistate state = PUSI_DISCONN; // server state
|
||||||
// the `ismoving` flag allows not to make corrections with bad images made when moving
|
// the `ismoving` flag allows not to make corrections with bad images made when moving
|
||||||
static volatile atomic_bool ismoving = FALSE; // == TRUE if any of steppers @hanging part is moving
|
static volatile atomic_bool ismoving = FALSE; // == TRUE if any of steppers @hanging part is moving
|
||||||
@ -147,8 +149,21 @@ static void pusi_disconnect(){
|
|||||||
sockfd = -1;
|
sockfd = -1;
|
||||||
Umoving = Vmoving = Fmoving = ismoving = FALSE;
|
Umoving = Vmoving = Fmoving = ismoving = FALSE;
|
||||||
state = PUSI_DISCONN;
|
state = PUSI_DISCONN;
|
||||||
|
LOGWARN("Canserver disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int too_much_errors(){
|
||||||
|
if(++errctr >= MAX_ERR_CTR){
|
||||||
|
LOGERR("Canserver: too much errors -> DISCONNECT");
|
||||||
|
errctr = 0;
|
||||||
|
pusi_disconnect();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define clr_errors() do{errctr = 0;}while(0)
|
||||||
|
|
||||||
static char *findval(const char *par, const char *statusmesg){
|
static char *findval(const char *par, const char *statusmesg){
|
||||||
if(!statusmesg || !par) return NULL;
|
if(!statusmesg || !par) return NULL;
|
||||||
char *pair = strcasestr(statusmesg, par);
|
char *pair = strcasestr(statusmesg, par);
|
||||||
@ -255,6 +270,7 @@ static int waitOK(char **retval){
|
|||||||
*retval = strdup(ok + sizeof(ANSOK)-1);
|
*retval = strdup(ok + sizeof(ANSOK)-1);
|
||||||
//DBG("RETVAL: '%s'", *retval);
|
//DBG("RETVAL: '%s'", *retval);
|
||||||
}
|
}
|
||||||
|
clr_errors();
|
||||||
}else{
|
}else{
|
||||||
LOGWARN("didn't get OK answer");
|
LOGWARN("didn't get OK answer");
|
||||||
}
|
}
|
||||||
@ -443,11 +459,14 @@ static int moving_finished(const char *mesgstatus, volatile atomic_int *position
|
|||||||
char *ans = NULL;
|
char *ans = NULL;
|
||||||
int ret = TRUE;
|
int ret = TRUE;
|
||||||
if(send_message(mesgstatus, &ans) && getparval(PARstatus, ans, &val)){
|
if(send_message(mesgstatus, &ans) && getparval(PARstatus, ans, &val)){
|
||||||
|
errctr = 0;
|
||||||
//DBG("send(%s) true: %s %g\n", mesgstatus, ans, val);
|
//DBG("send(%s) true: %s %g\n", mesgstatus, ans, val);
|
||||||
}else{
|
}else{
|
||||||
WARNX("send(%s) false: %s %g\n", mesgstatus, ans, val);
|
WARNX("send(%s) false: %s %g\n", mesgstatus, ans, val);
|
||||||
LOGDBG("send(%s) false: %s %g\n", mesgstatus, ans, val);
|
if(too_much_errors()){
|
||||||
pusi_disconnect();
|
LOGDBG("send(%s) false: %s %g", mesgstatus, ans, val);
|
||||||
|
}
|
||||||
|
if(ans) free(ans);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
int ival = (int)val;
|
int ival = (int)val;
|
||||||
@ -472,9 +491,8 @@ static int move_motor(const char *movecmd, int s){
|
|||||||
snprintf(buf, 255, "%s %d", movecmd, s);
|
snprintf(buf, 255, "%s %d", movecmd, s);
|
||||||
if(!send_message(buf, &ans)){
|
if(!send_message(buf, &ans)){
|
||||||
WARNX("can't send message");
|
WARNX("can't send message");
|
||||||
LOGDBG("can't send message");
|
if(too_much_errors()) LOGWARN("Canserver: can't move motor");
|
||||||
pusi_disconnect();
|
if(ans) free(ans);
|
||||||
FREE(ans);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
int ret = TRUE;
|
int ret = TRUE;
|
||||||
@ -500,6 +518,7 @@ static void process_movetomiddle_stage(){
|
|||||||
else{
|
else{
|
||||||
LOGWARN("GOTO middle: err in move command");
|
LOGWARN("GOTO middle: err in move command");
|
||||||
sstatus = SETUP_INIT;
|
sstatus = SETUP_INIT;
|
||||||
|
if(too_much_errors()) sstatus = SETUP_NONE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SETUP_WAITUVMID: // wait for the middle
|
case SETUP_WAITUVMID: // wait for the middle
|
||||||
@ -507,6 +526,7 @@ static void process_movetomiddle_stage(){
|
|||||||
if(!send_message(Fsetzero, NULL) || !send_message(Usetzero, NULL) || !send_message(Vsetzero, NULL)){
|
if(!send_message(Fsetzero, NULL) || !send_message(Usetzero, NULL) || !send_message(Vsetzero, NULL)){
|
||||||
LOGWARN("GOTO middle: err in set 0 command");
|
LOGWARN("GOTO middle: err in set 0 command");
|
||||||
sstatus = SETUP_INIT;
|
sstatus = SETUP_INIT;
|
||||||
|
if(too_much_errors()) sstatus = SETUP_NONE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Uposition = Vposition = Fposition = 0;
|
Uposition = Vposition = Fposition = 0;
|
||||||
@ -537,6 +557,7 @@ static void process_setup_stage(){
|
|||||||
else{
|
else{
|
||||||
LOGWARN("Can't move U/V -> 0");
|
LOGWARN("Can't move U/V -> 0");
|
||||||
sstatus = SETUP_INIT;
|
sstatus = SETUP_INIT;
|
||||||
|
if(too_much_errors()) sstatus = SETUP_NONE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SETUP_WAITUVMID: // wait for the middle
|
case SETUP_WAITUVMID: // wait for the middle
|
||||||
@ -545,6 +566,7 @@ static void process_setup_stage(){
|
|||||||
else{
|
else{
|
||||||
LOGWARN("Can't move U -> middle");
|
LOGWARN("Can't move U -> middle");
|
||||||
sstatus = SETUP_INIT;
|
sstatus = SETUP_INIT;
|
||||||
|
if(too_much_errors()) sstatus = SETUP_NONE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SETUP_WAITU0: // wait while U moves to zero
|
case SETUP_WAITU0: // wait while U moves to zero
|
||||||
@ -557,6 +579,7 @@ static void process_setup_stage(){
|
|||||||
else{
|
else{
|
||||||
LOGWARN("Can't move U -> max");
|
LOGWARN("Can't move U -> max");
|
||||||
sstatus = SETUP_INIT;
|
sstatus = SETUP_INIT;
|
||||||
|
if(too_much_errors()) sstatus = SETUP_NONE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SETUP_WAITUMAX: // wait while U moves to UVworkrange
|
case SETUP_WAITUMAX: // wait while U moves to UVworkrange
|
||||||
@ -568,6 +591,7 @@ static void process_setup_stage(){
|
|||||||
else{
|
else{
|
||||||
LOGWARN("Can't move U -> mid OR/AND V -> min");
|
LOGWARN("Can't move U -> mid OR/AND V -> min");
|
||||||
sstatus = SETUP_INIT;
|
sstatus = SETUP_INIT;
|
||||||
|
if(too_much_errors()) sstatus = SETUP_NONE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SETUP_WAITV0: // wait while V moves to 0
|
case SETUP_WAITV0: // wait while V moves to 0
|
||||||
@ -579,6 +603,7 @@ static void process_setup_stage(){
|
|||||||
else{
|
else{
|
||||||
LOGWARN("Can't move V -> max");
|
LOGWARN("Can't move V -> max");
|
||||||
sstatus = SETUP_INIT;
|
sstatus = SETUP_INIT;
|
||||||
|
if(too_much_errors()) sstatus = SETUP_NONE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SETUP_WAITVMAX: // wait while V moves to UVworkrange
|
case SETUP_WAITVMAX: // wait while V moves to UVworkrange
|
||||||
@ -674,7 +699,10 @@ static int try2correct(double dX, double dY){
|
|||||||
LOGDBG("try2correct(): move from (%d, %d) to (%d, %d) (abs: %d, %d), delta (%.1f, %.1f)",
|
LOGDBG("try2correct(): move from (%d, %d) to (%d, %d) (abs: %d, %d), delta (%.1f, %.1f)",
|
||||||
Uposition, Vposition, Unew, Vnew, Uposition + (int)(dU/KCORR),
|
Uposition, Vposition, Unew, Vnew, Uposition + (int)(dU/KCORR),
|
||||||
Vposition + (int)(dV/KCORR), dU, dV);
|
Vposition + (int)(dV/KCORR), dU, dV);
|
||||||
return (moveU((int)dU) && moveV((int)dV));
|
int ret = FALSE;
|
||||||
|
if(moveU((int)dU) && moveV((int)dV)) ret = TRUE;
|
||||||
|
if(!ret && too_much_errors()) LOGERR("Canserver: stop corrections");
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// global variable proc_corr
|
// global variable proc_corr
|
||||||
@ -924,7 +952,7 @@ static void *pusi_process_states(_U_ void *arg){
|
|||||||
case PUSI_FIX: // process corrections
|
case PUSI_FIX: // process corrections
|
||||||
if(coordsRdy){
|
if(coordsRdy){
|
||||||
coordsRdy = FALSE;
|
coordsRdy = FALSE;
|
||||||
red("GET AVERAGE -> correct\n");
|
DBG("GET AVERAGE -> correct\n");
|
||||||
double xtg = theconf.xtarget - theconf.xoff, ytg = theconf.ytarget - theconf.yoff;
|
double xtg = theconf.xtarget - theconf.xoff, ytg = theconf.ytarget - theconf.yoff;
|
||||||
double xdev = xtg - Xtarget, ydev = ytg - Ytarget;
|
double xdev = xtg - Xtarget, ydev = ytg - Ytarget;
|
||||||
double corr = sqrt(xdev*xdev + ydev*ydev);
|
double corr = sqrt(xdev*xdev + ydev*ydev);
|
||||||
@ -998,13 +1026,13 @@ static char *relaycmd(const char *val, char *buf, int buflen){
|
|||||||
int rval = r.relays;
|
int rval = r.relays;
|
||||||
if(v) rval |= 1<<tmpno;
|
if(v) rval |= 1<<tmpno;
|
||||||
else rval &= ~(1<<tmpno);
|
else rval &= ~(1<<tmpno);
|
||||||
green("Relay %d -> %d", r.relays, rval);
|
DBG("Relay %d -> %d", r.relays, rval);
|
||||||
snprintf(mbuf, 511, "%s %d %d", RelayCmd, R_RELAY + relaySetter, rval);
|
snprintf(mbuf, 511, "%s %d %d", RelayCmd, R_RELAY + relaySetter, rval);
|
||||||
if(send_message(mbuf, NULL)) ans = OK;
|
if(send_message(mbuf, NULL)) ans = OK;
|
||||||
}
|
}
|
||||||
}else if(1 == sscanf(par, "PWM%d", &tmpno)){ // PWM command
|
}else if(1 == sscanf(par, "PWM%d", &tmpno)){ // PWM command
|
||||||
if(tmpno >= 0 && tmpno < 4 && v > -1 && v < 256){
|
if(tmpno >= 0 && tmpno < 4 && v > -1 && v < 256){
|
||||||
green("PWM %d -> %d\n", tmpno, v);
|
DBG("PWM %d -> %d\n", tmpno, v);
|
||||||
r.PWM[tmpno] = v;
|
r.PWM[tmpno] = v;
|
||||||
snprintf(mbuf, 511, "%s %d %u %u %u", RelayCmd, R_PWM + relaySetter, r.PWM[0], r.PWM[1], r.PWM[2]);
|
snprintf(mbuf, 511, "%s %d %u %u %u", RelayCmd, R_PWM + relaySetter, r.PWM[0], r.PWM[1], r.PWM[2]);
|
||||||
if(send_message(mbuf, NULL)) ans = OK;
|
if(send_message(mbuf, NULL)) ans = OK;
|
||||||
|
|||||||
@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
#include "improc.h"
|
#include "improc.h"
|
||||||
|
|
||||||
|
// set state to `disconnect` after this amount of errors in `moving_finished`
|
||||||
|
#define MAX_ERR_CTR (15)
|
||||||
|
|
||||||
extern steppersproc pusyCANbus;
|
extern steppersproc pusyCANbus;
|
||||||
|
|
||||||
// try to connect to local pusirobo server
|
// try to connect to local pusirobo server
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user