/* 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 */
* 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);
}
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;
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 */
/* 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 */
/*---------- 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 */