less squares 4 speed + fixed some bugs (but found more)

This commit is contained in:
2025-07-31 17:03:15 +03:00
parent ca9dcdfa68
commit 9fbd858086
15 changed files with 428 additions and 234 deletions

View File

@@ -36,9 +36,8 @@ static void chkminmax(double *min, double *max){
movemodel_t *model_init(limits_t *l){
if(!l) return FALSE;
movemodel_t *model = calloc(1, sizeof(movemodel_t));
memcpy(model, &trapez, sizeof(movemodel_t));
if(!model->init_limits) goto fail;
movemodel_t *m = calloc(1, sizeof(movemodel_t));
*m = trapez;
moveparam_t *max = &l->max, *min = &l->min;
if(min->speed < 0.) min->speed = -min->speed;
if(max->speed < 0.) max->speed = -max->speed;
@@ -47,10 +46,13 @@ movemodel_t *model_init(limits_t *l){
chkminmax(&min->coord, &max->coord);
chkminmax(&min->speed, &max->speed);
chkminmax(&min->accel, &max->accel);
if(!model->init_limits(l)) return NULL;
return model;
fail:
free(model); return NULL;
m->Min = l->min;
m->Max = l->max;
m->movingstage = STAGE_STOPPED;
m->state = ST_STOP;
pthread_mutex_init(&m->mutex, NULL);
DBG("model inited");
return m;
}
int model_move2(movemodel_t *model, moveparam_t *target, double t){
@@ -59,5 +61,5 @@ int model_move2(movemodel_t *model, moveparam_t *target, double t){
// only positive velocity
if(target->speed < 0.) target->speed = -target->speed;
// don't mind about acceleration - user cannot set it now
return model->calculate(target, t);
return model->calculate(model, target, t);
}