*/
};
+static const char *posnpname(Segment *move, MovPosComb poscomb) {
+ return poscomb<0 ? "?" : move->i->poscombs[poscomb].pname;
+}
+
+static void ouposn_moving(Change *chg) {
+ Segment *move= chg->move;
+ oprintf(UPO, "movpos %s position %s moving\n",
+ move->i->pname, posnpname(move, chg->actual));
+}
+
+static void motion_done(Segment *move) {
+ move->moving= 0;
+ move->motion= 0;
+ move->movposcomb= r->h.actual;
+ oprintf(UPO, "movpos %s position %s stable\n",
+ move->i->pname, posnpname(move, move->movposcomb));
+}
+
+#define PRPOSN_CHG(chg) \
+ (chg)->move->i->pname, \
+ (chg)->actual<0 ? "?" : (chg)->move->i->poscombs[(chg)->actual].pname
+
/*========== points ==========*/
/*
int allow_failure;
ErrorCode ec;
-fprintf(stderr," point confirm\n");
+ oprintf(DUPO("point") "confirm %s n=%d maxdelay=%d"
+ " (res: n=%d deadline=[t+]%d)\n",
+ move->i->pname, n_motions, maxdelay_ms,
+ r->n_motions, r->deadline);
/* If the segment is moving, these motions are already based on the
* actual physical position which is stored in the existing request.
newdeadline= pt_maxdelay_reldeadline(maxdelay_ms);
}
allow_failure= newdeadline < r->deadline;
+ oprintf(DUPO("point") " newdeadline=t+%d allow_failure=%d\n",
+ newdeadline, allow_failure);
newdeadline += pt_cslot;
/* state A or R */
/* states of existing: */
PointReq *existing=
move->moving ? (PointReq*)move->motion : 0; /* U or C */
- if (existing) pt_dequeue(existing); /* U or CA */
+ if (existing) {
+ oprintf(DUPO("point")
+ " existing %s n=%d deadline=t+%d\n",
+ existing->h.move->i->pname,
+ existing->n_motions,
+ existing->deadline - pt_slot);
+ pt_dequeue(existing); /* U or CA */
+ }
/* state A or RA */
memcpy(r->motions, motions, sizeof(r->motions[0])*n_motions);
/* state CA */
ec= pt_enqueue(&pt_confirmed, r);
+ oprintf(DUPO("point") " pt_enqueue=%s\n", ecstr(ec));
assert(allow_failure || !ec);
if (existing) { /* CA */
* or ec!=0 state C but bad C
*/
- if (!ec) {
- move->moving= 1;
- move->motion= chg;
- move->movposcomb= -1;
- pt_check_action();
- }
+ if (ec) return;
- return ec;
+ move->moving= 1;
+ move->motion= chg;
+ move->movposcomb= -1;
+ ouposn_moving(chg);
+ pt_check_action();
+ return 0;
}
static void point_destroy(Change *chg) { /* X->XA and then free it */
static void pt_check_action(void) {
PicInsn piob;
+fixme add more oprintf DUPO from about here onwards
+
if (!pt_confirmed.n) {
if (sta_state == Sta_Finalising) resolve_motioncheck();
return;
assert(m->posn < m->i->posns);
enco_pic_point(&piob, m->i->boob[m->posn]);
serial_transmit(&piob);
+ oprintf(UPO, "movpos %s point %s%d\n", r->move->i->pname,
+ m->i->pname, m->posn);
pt_cdu_charged= 0;
MovPosComb above_weight= m->i->weight * m->i->posns;
r->actual= above*above_weight + m->posn*m->i->weight + below;
if (r->h.actual >= 0 || !r->n_motions)
r->h.actual= r->actual;
+ ouposn_moving(&r->h);
}
if (!r->n_motions) {
assert(move->moving && move->motion == (Change*)r);
pt_queue_remove_index(&pt_confirmed,0);
pt_mark_as_allocated(r); /* now state A aka Done */
- move->movposcomb= r->h.actual;
- move->moving= 0;
- move->motion= 0;
+ motion_done(move);
free(r);
pt_check_action();
}
PointReq *r= pt_confirmed.l[i];
Segment *move= r->h.move;
assert(move->motion == (Change*)r);
- move->moving= 0;
- move->motion= 0;
- move->movposcomb= r->h.actual;
+ motion_done(move);
free(r);
}
pt_confirmed.n= 0;
/*========== dummy `nomove' kind ==========*/
static Change *nomove_allocate(int alloc_motions) {
-fprintf(stderr," nomove allocate %d\n",alloc_motions);
+ oprintf(DUPO("movfeatkind-momove") "allocate %d\n",alloc_motions);
return mmalloc(sizeof(Change));
}
static void nomove_destroy(Change *chg) {
}
static ErrorCode nomove_reserve(Change *chg, Segment *move, int ms) {
-fprintf(stderr," nomove reserve\n");
+ oprintf(DUPO("movfeatkind-nomove") "reserve\n");
return 0;
}
static ErrorCode nomove_confirm(Change *chg, Segment *move, int n_motions,
const Motion *motions, int ms) {
-fprintf(stderr," nomove confirm\n");
+ oprintf(DUPO("movfeatkind-nomove") "confirm\n");
nomove_destroy(chg);
return 0;
}
int n_motions=0;
Motion motions[movei->n_movfeats];
+fixme make these debug
fprintf(stderr," motions... best=%lu actual=%ld\n",target,actual);
for (feat=0, feati=movei->movfeats;
feat<movei->n_movfeats;