chiark / gitweb /
restoring uncertainty
authorian <ian>
Mon, 21 Apr 2008 00:52:01 +0000 (00:52 +0000)
committerian <ian>
Mon, 21 Apr 2008 00:52:01 +0000 (00:52 +0000)
hostside/persist.c
hostside/record-y.y
hostside/record.c
hostside/resolve.c
hostside/safety.c
hostside/safety.h
hostside/speed.c

index 4221eacfae8fb002bef084f8cf4b13b6ad219562..01171e520f9bf36211c2f61dd117a97bc5b3927f 100644 (file)
@@ -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 ||
index 25193d3b2738cd1a919f92d2f51c36e588a02841..984fa9cdad85c82945dc0843f7103aa4991c8b2e 100644 (file)
@@ -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);
index fc68746561c6dcf219226a173a3e4b505cf9e5f0..b75964bbc9298df2041780fbc1a9e1ea71c0ff64 100644 (file)
@@ -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;
index 8f05587678a3e452cd76c8af08690d0278e4f878..c4629473f09ac2d3b0bb2e165a9a654771f322db 100644 (file)
@@ -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= &notify->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);
     }
index 6874a01239f4cbacdca876c4f04e16ee41cb8a6a..1d00aeab6458ea0ea2d6935740caf5f4042eea92 100644 (file)
@@ -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;
index e21531bf1acea8f4b6f075ed3e7873cd708f5a92..e80a073e475e17b5cedfba6e8dddac70a0578695 100644 (file)
@@ -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
index d67df9c91770123eb24c213aabbec238b02c79b5..fcdaecf68a1e2d8aef282f678a4c8f4e6a4a3486 100644 (file)
@@ -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;
 }