From: ian Date: Sun, 27 Jul 2008 16:00:15 +0000 (+0000) Subject: Clearer definition of meaning of margins, maxinto, etc. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=d389d5552c7fc3ab918b8e98db2e0194f3824ebd;p=trains.git Clearer definition of meaning of margins, maxinto, etc. --- diff --git a/hostside/safety.c b/hostside/safety.c index 95ef1ad..1de3970 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -670,8 +670,12 @@ static int fdet_nextseg(TrackLocation *t, TrackAdvanceContext *c, /* Advance the tail */ - u->tailc.distance= advanced; - r= trackloc_advance(&u->tail,&u->tailc); assert(!r); + u->tailc.distance += advanced; + if (u->tailc.distance > 0) { + r= trackloc_advance(&u->tail,&u->tailc); + assert(!r); + assert(!u->tailc.distance); + } /* Final adjustments, prepare for next iteration */ @@ -768,11 +772,13 @@ ErrorCode predict(Train *tra, struct timeval tnow, unsigned flags, * so we must instead extend our idea of the length of the train. */ - int effective_length= MARGIN_TAIL + tail_length(tra) + tra->detectable; + int tail_walkback= MARGIN_NOSE + tail_length(tra) + tra->detectable; + int tail_advance_delaydist= MARGIN_TAIL; + int effective_into_fdet= tra->maxinto - tra->uncertainty; if (effective_into_fdet < 0) { - effective_length += -effective_into_fdet; - effective_into_fdet += -effective_into_fdet; + tail_advance_delaydist += effective_into_fdet; + effective_into_fdet -= effective_into_fdet; assert(!effective_into_fdet); } @@ -791,7 +797,7 @@ ErrorCode predict(Train *tra, struct timeval tnow, unsigned flags, u.tailc.getmovpos= pred_getmovpos; u.tailc.nextseg= initpresent_nextseg; u.tailc.trackend= pred_trackend_panic; - u.tailc.distance= effective_length; + u.tailc.distance= tail_walkback; u.tail= u.fdet; @@ -821,6 +827,7 @@ ErrorCode predict(Train *tra, struct timeval tnow, unsigned flags, u.fdetc.getmovpos= pred_getmovpos; u.fdetc.trackend= pred_trackend; u.tailc.nextseg= tail_nextseg; + u.tailc.distance= -tail_advance_delaydist; if (!u.stopping) { /* we're carrying on until the next segment */ diff --git a/hostside/safety.h b/hostside/safety.h index abb3bac..6f918a5 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -41,6 +41,15 @@ struct Train { /* Location: */ struct Segment *foredetect; Distance maxinto, uncertainty; + /* Front of train's detectable portion (the `reference') is at + * most maxinto into foredetect, but may be up to uncertainty + * further back (which may put it in a previous segment). If the + * train is stationary it owns the track forwards from the + * foremost reference possibility, plus ->head, plus MARGIN_NOSE + * (and if it is not stationary it may own more). It owns the + * track backwards from the rearmost reference possibility for + * ->detectable plus ->tail plus MARGIN_NOSE. + */ unsigned backwards:1, /* train is moving backwards wrt its own front and back */ autopoint:1, /* set points automatically if point has autopoint too */ @@ -388,8 +397,8 @@ int trackloc_set_exactinto(TrackLocation *t, TrackAdvanceContext *c, /*---------- safety margin parameters ----------*/ -#define MARGIN_NOSE 6 /*mm*/ -#define MARGIN_TAIL 6 /*mm*/ +#define MARGIN_NOSE 6 /*mm*/ /* physical spare at each end of train */ +#define MARGIN_TAIL 6 /*mm*/ /* spare when in motion only */ #define MARGIN_SPEED 1.2 /*ratio*/ #define MARGIN_AUTOPOINTTIME 500 /*ms*/ #define UNMARGIN_ROUNDING 1e-4 /* mm/ms; for 1s, leads to max err of 100um */