introduce a lot of errors when trying to apply model

This commit is contained in:
2025-07-30 16:45:42 +03:00
parent 502014bee4
commit 04ee999159
11 changed files with 627 additions and 113 deletions

View File

@@ -19,8 +19,9 @@
#include <ctype.h>
#include <inttypes.h>
#include <string.h>
#include <unistd.h>
#include "dbg.h"
#include "main.h"
#include "serial.h"
#include "ssii.h"
@@ -65,13 +66,6 @@ static void ChkStopped(const SSstat *s, mountdata_t *m){
*/
void SSconvstat(const SSstat *s, mountdata_t *m, double t){
if(!s || !m) return;
/*
#ifdef EBUG
static double t0 = -1.;
if(t0 < 0.) t0 = dtime();
#endif
DBG("Convert, t=%g", dtime()-t0);
*/
m->motXposition.val = X_MOT2RAD(s->Xmot);
m->motYposition.val = Y_MOT2RAD(s->Ymot);
ChkStopped(s, m);
@@ -82,9 +76,6 @@ void SSconvstat(const SSstat *s, mountdata_t *m, double t){
m->encYposition.val = Y_ENC2RAD(s->Yenc);
m->encXposition.t = m->encYposition.t = t;
}
//m->lastmotposition.X = X_MOT2RAD(s->XLast);
//m->lastmotposition.Y = Y_MOT2RAD(s->YLast);
//m->lastmotposition.msrtime = *tdat;
m->keypad = s->keypad;
m->extradata.ExtraBits = s->ExtraBits;
m->extradata.ain0 = s->ain0;
@@ -170,7 +161,9 @@ int SSstop(int emerg){
const char *cmdx = (emerg) ? CMD_EMSTOPX : CMD_STOPX;
const char *cmdy = (emerg) ? CMD_EMSTOPY : CMD_STOPY;
for(; i < 10; ++i){
DBG("t1: %g", nanotime());
if(!SStextcmd(cmdx, NULL)) continue;
DBG("t2: %g", nanotime());
if(SStextcmd(cmdy, NULL)) break;
}
if(i == 10) return FALSE;
@@ -180,12 +173,19 @@ int SSstop(int emerg){
// update motors' positions due to encoders'
mcc_errcodes_t updateMotorPos(){
mountdata_t md = {0};
double t0 = dtime(), t = 0.;
double t0 = nanotime(), t = 0.;
DBG("start @ %g", t0);
do{
t = dtime();
t = nanotime();
if(MCC_E_OK == getMD(&md)){
DBG("got");
if(md.encXposition.t == 0 || md.encYposition.t == 0){
DBG("Just started, t-t0 = %g!", t - t0);
sleep(1);
DBG("t-t0 = %g", nanotime() - t0);
//usleep(10000);
continue;
}
DBG("got; t pos x/y: %g/%g; tnow: %g", md.encXposition.t, md.encYposition.t, t);
if(fabs(md.encXposition.t - t) < 0.1 && fabs(md.encYposition.t - t) < 0.1){
DBG("FIX motors position to encoders");
int32_t Xpos = X_RAD2MOT(md.encXposition.val), Ypos = Y_RAD2MOT(md.encYposition.val);