chiark / gitweb /
Clearer definition of meaning of margins, maxinto, etc.
authorian <ian>
Sun, 27 Jul 2008 16:00:15 +0000 (16:00 +0000)
committerian <ian>
Sun, 27 Jul 2008 16:00:15 +0000 (16:00 +0000)
hostside/safety.c
hostside/safety.h

index 95ef1adb2fc2278a3b5ce28e50effd44fe558345..1de397038d402513299558cf8caf0fad94b8abf9 100644 (file)
@@ -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 */
index abb3bacb565bb714e1cdd5077846481883789029..6f918a5129b5b835ec47ef68d9d27a007fbfd3a9 100644 (file)
@@ -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 */