chiark / gitweb /
get stopping distance right in !u.stopping case
authorian <ian>
Sun, 8 Jun 2008 11:44:27 +0000 (11:44 +0000)
committerian <ian>
Sun, 8 Jun 2008 11:44:27 +0000 (11:44 +0000)
hostside/safety.c

index 485b639f473a4e12786d3c78bc1815ab19096904..0f2500f14ef1025001b26e48381d2f7529b799d0 100644 (file)
@@ -793,14 +793,17 @@ ErrorCode predict(Train *tra, struct timeval tnow, unsigned flags,
   u.fdetc.trackend= pred_trackend;
   u.tailc.nextseg= tail_nextseg;
 
-  if ((flags & PREDF_JUSTDET) && u.stopping) {
+  if (!u.stopping) {
+    /* we're carrying on until the next segment */
+    u.fdetc.distance= u.fdet.remain;
+  } else if (flags & PREDF_JUSTDET) {
     /* we actually know exactly where we are */
-    u.fdetc.distance= u.stopping_distance;
-  } else {
-    u.fdetc.distance= tra->uncertainty + u.stopping_distance;
-    u.elapsed= -tra->uncertainty / u.maxspeed;
+    u.fdetc.distance= 0;
+  } else { /* stopping, but we're mid-segment */
+    u.fdetc.distance= tra->uncertainty;
   }
-  u.fdetc.distance += MARGIN_NOSE;
+  u.elapsed= -u.fdetc.distance / u.maxspeed; /* imagine we're already there */
+  u.fdetc.distance += u.stopping_distance + MARGIN_NOSE;
   u.was_distance= u.fdetc.distance;
 
   ec= trackloc_advance(&u.fdet,&u.fdetc);