From: ian Date: Mon, 21 Apr 2008 00:52:01 +0000 (+0000) Subject: restoring uncertainty X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=a1bca6b21aaef60d84d2b50fea37bcd8a4e0c8d8;p=trains.git restoring uncertainty --- diff --git a/hostside/persist.c b/hostside/persist.c index 4221eac..01171e5 100644 --- a/hostside/persist.c +++ b/hostside/persist.c @@ -373,9 +373,11 @@ void persist_entrails_run_converter(void) { if (!tra->pname || !tra->foredetect || !tra->foredetect->i || !tra->foredetect->i->pname) continue; - printf("train %s at %s%s\n", + printf("train %s at %s%s:%d-+%d\n", tra->pname, tra->backwards ? "-" : "", - tra->foredetect->i->pname); +fixme tra->backwards is wrong + need to provide both tra->backwards and tr_backwards + tra->foredetect->i->pname, tra->mininto, tra->uncertainty); } FOR_SEG { if (seg->i != segi || !segi->pname || diff --git a/hostside/record-y.y b/hostside/record-y.y index 25193d3..984fa9c 100644 --- a/hostside/record-y.y +++ b/hostside/record-y.y @@ -44,8 +44,8 @@ line: /* empty */ | TRAIN train IS NUM NUM '+' NUM '+' NUM { if ($2) record_train_is($2,$4,$5,$7,$9); } - | TRAIN train AT backwards seg - { if ($2) record_train_at($2,$4,$5); + | TRAIN train AT backwards seg ':' NUM '+' '-' NUM + { if ($2) record_train_at($2,$4,$5,$7,$10); } | TRAIN train AT backwards seg ':' NUM '+' '-' NUM { if ($2) record_train_at($2,$4,$5,$7,$10); diff --git a/hostside/record.c b/hostside/record.c index fc68746..b75964b 100644 --- a/hostside/record.c +++ b/hostside/record.c @@ -184,7 +184,7 @@ void record_train_is(Train *tra, int addr, int head, int det, int tail) { tra->tail= tail; } -void record_train_at(Train *tra, int backw, Segment *seg, int maxi, int unc) { +void record_train_at(Train *tra, int backw, Segment *seg, int mini, int unc) { tra->foredetect= seg; tra->maxinto= maxi; tra->uncertainty= unc; @@ -402,6 +402,7 @@ static void alloc(void) { tra->pname= *trap= pname; tra->addr= -1; tra->foredetect= 0; + tra->uncertainty= tra->maxinto= 0; tra->backwards= 0; for (step=0; step<=SPEEDSTEPS; step++) tra->speedcurve[step]= -1; diff --git a/hostside/resolve.c b/hostside/resolve.c index 8f05587..c462947 100644 --- a/hostside/resolve.c +++ b/hostside/resolve.c @@ -357,15 +357,32 @@ int resolve_complete(void) { return 0; } -void resolve_motioncheck(void) { - SEG_IV; - assert(sta_state == Sta_Finalising); +static int rtf_nextseg(TrackLocation *t, struct TrackAdvanceContext *c, + MovPosComb *mpc_io, Segment *before) { + if (t->seg->owner != before->owner) + return -1; + t->seg->owner->foredetect= t->seg; +} + +static void resolve_train_finalise(Train *tra) { + TrackLocation t; + TrackAdvanceContext tc; + + t.seg= tra->foredetect; + t.remain= 0; + t.backwards= t.seg->tr_backwards; + tc.distance= INT_MAX; + tc.nextseg= rtf_nextseg; + tc.getmovpos= 0; + tc.trackend= 0; + + trackloc_advance(&t,&tc); + - FOR_SEG - if (seg->moving) return; - FOR_SEG { - if (seg->res_detect) { + for (;;) { + + Segment *notify, *onwards; const SegPosCombInfo *pci; const SegmentLinkInfo *link; @@ -376,7 +393,7 @@ void resolve_motioncheck(void) { assert(notify->movposcomb >= 0); pci= ¬ify->i->poscombs[notify->movposcomb]; - link= notify->tr_backwards ? &pci->backwards : &pci->forwards; + link= &pci->link[notify->tr_backwards]; if (!SOMEP(link->next)) break; onwards= &segments[link->next]; @@ -385,6 +402,27 @@ void resolve_motioncheck(void) { notify= onwards; } + + +void resolve_motioncheck(void) { + SEG_IV; + assert(sta_state == Sta_Finalising); + + FOR_SEG + if (seg->moving) return; + + FOR_SEG + if (seg->res_detect) { + assert(seg->owner); + seg->owner->foredetect= seg; /* initial guess */ + } + + + FOR_TRA + resolve_train_finalise(tra); + + FOR_SEG { + if (seg->res_detect) { safety_notify_detection(notify); } diff --git a/hostside/safety.c b/hostside/safety.c index 6874a01..1d00aea 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -498,14 +498,19 @@ ErrorCode predict_confirm(Train *tra, int accelerate, u.problem_callback= ppc; u.problem_callback_u= ppcu; - trackloc_set_maxinto(&u.fdet, foredet, foredet->tr_backwards); - trackloc_set_maxinto(&u.tail, foredet, !foredet->tr_backwards); + u.fdetc.getmovpos= pred_getmovpos; + u.tailc.getmovpos= pred_getmovpos; + + trackloc_set_exactinto(&u.fdet, &u.fdetc, foredet, foredet->tr_backwards, + tra->maxinto); + u.tail= u.fdet; + ec= trackloc_reverse_exact(&u.tail, &u.tailc); assert(!ec); /* find the train's tail and mark it present */ - u.tailc.distance= tra->detectable + (tra->backwards ? tra->head : tra->tail); + u.tailc.distance= tra->detectable + (tra->backwards ? tra->head : tra->tail) + + tra->uncertainty + MARGIN_TAIL; u.tailc.nextseg= initpresent_nextseg; - u.tailc.getmovpos= pred_getmovpos; u.tailc.trackend= pred_trackend_panic; u.tailc.u= &u; @@ -597,16 +602,19 @@ static void detection_report_problem(Train *tra, Segment *seg, void safety_notify_detection(Segment *seg) { Train *tra; + TrackLoc tloc; ErrorCode ec; if (seg->det_ignore) return; if (!seg->det_expected) safety_panic(0,seg, "unexpected detection"); - + if (seg->movposcomb < 0) + safety_panic(tra,seg, "track route not set and train has arrived"); + tra= seg->owner; tra->foredetect= seg; - if (tra->foredetect->movposcomb < 0) - safety_panic(tra,seg, "track route not set and train has arrived"); + tra->uncertainty= tra->maxinto= + seg->i->poscombs[seg->movposcomb].dist; ec= predict_confirm(tra, 0, detection_report_problem, 0); if (!ec) return; diff --git a/hostside/safety.h b/hostside/safety.h index e21531b..e80a073 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -40,6 +40,7 @@ struct Train { /* Location: */ struct Segment *foredetect; + Distance maxinto, uncertainty; unsigned backwards:1, /* train is moving backwards wrt its own front and back */ @@ -332,6 +333,7 @@ int trackloc_reverse_exact(TrackLocation *t, TrackAdvanceContext *c); /*---------- safety margin parameters ----------*/ #define MARGIN_NOSE 6 +#define MARGIN_TAIL 6 #define MARGIN_SPEED 1.2 #if 0 diff --git a/hostside/speed.c b/hostside/speed.c index d67df9c..fcdaecf 100644 --- a/hostside/speed.c +++ b/hostside/speed.c @@ -15,6 +15,9 @@ static void xmit(Train *tra) { static void decel_done(TimeoutEvent *toev) { Train *tra= (void*)((char*)toev - offsetof(Train, speed.decel)); tra->speed.speed= tra->speedcurve[tra->speed.step]; + if (tra->sigstopping) { + assert(!tra->speed.step); + resolve_train_ } static const SpeedRange *stop_info(Train *tra, double speed) { @@ -38,7 +41,8 @@ static double current_speed(Train *tra, const struct timeval tnow) { if (left_to_go <= 0) { toev_stop(&tra->speed.decel); - return tra->speed.speed= tra->speedcurve[tra->speed.step]; + decel_done(&tra->speed.decel); + return tra->speed.speed; } v2= tra->speed.speed; @@ -115,6 +119,7 @@ ErrorCode speedmanager_speedchange_request(Train *tra, int step, toev_stop(&tra->speed.decel); tra->speed.speed= vtarg; tra->speed.try_speed= -1; + tra->sigstopping= 0; xmit(tra); return 0; }