chiark / gitweb /
optimistic point setting not yet tested as current home shinkansen placement does...
authorian <ian>
Sun, 4 May 2008 23:46:56 +0000 (23:46 +0000)
committerian <ian>
Sun, 4 May 2008 23:46:56 +0000 (23:46 +0000)
hostside/commands.c
hostside/record.c
hostside/safety.c
hostside/safety.h

index 653af2359cbf6a03ca5c5f97efd1794b9f022f7a..b7ffd1f60a901c6017dc393ee373c81209baedd8 100644 (file)
@@ -272,11 +272,12 @@ static int cmd_speed(ParseState *ps, const CmdInfo *ci) {
 }
 
 const CmdInfo toplevel_cmds[]= {
-  { "!pic",       cmd_pic,    CIXF_ANYSTA|CIXF_FORCE   },
-  { "!nmra",      cmd_nmra,                            },
-  { "noop",       cmd_noop,   CIXF_ANYSTA              },
-  { "movpos",     cmd_movpos                           },
-  { "!movpos",    cmd_movpos, CIXF_ANYSTA|CIXF_FORCE   },
-  { "speed",      cmd_speed                            },
+  { "!pic",       cmd_pic,        CIXF_ANYSTA|CIXF_FORCE   },
+  { "!nmra",      cmd_nmra,                                },
+  { "noop",       cmd_noop,       CIXF_ANYSTA              },
+  { "movpos",     cmd_movpos                               },
+//{ "autopoint",  cmd_autopoint                            },
+  { "!movpos",    cmd_movpos,     CIXF_ANYSTA|CIXF_FORCE   },
+  { "speed",      cmd_speed                                },
   { 0 }
 };
index c42b78d2d86db4725b19acb2e4882d79b0954169..d6e1a968756420cea0adb1c38d445f7453d8d923 100644 (file)
@@ -414,6 +414,7 @@ static void alloc(void) {
        tra->foredetect= 0;
        tra->uncertainty= tra->maxinto= 0;
        tra->backwards= 0;
+       tra->autopoint= 1;
        for (step=0; step<=SPEEDSTEPS; step++)
          tra->speedcurve[step]= -1;
       }        
@@ -427,6 +428,7 @@ static void alloc(void) {
        seg->movposcomb= -1;
        seg->moving= 0;
        seg->i= segi;
+       seg->autopoint= 1;
       }
 
     if (phase==0)
index ebe7b49ee340c1cb17e2df432139073d3f886909..2d9b6b4aee7c89a13c8543101d2127ee982b714f 100644 (file)
@@ -235,6 +235,7 @@ typedef struct {
     count_time:1,
     accelerating:1,
     usecurrentposn:1, /* for pred_getmovpos */
+    optimistic:1, /* for autopoint */
     alwaysusemotions:1, /* for report_train_ownerships only */
     walk_compute_polarise:1, /* nose_nextseg still needs to worry */
     need_polarise:1, /* when we commit */
@@ -243,8 +244,8 @@ typedef struct {
   TrackLocation nose, fdet, tail;
   TrackAdvanceContext nosec, tailc, fdetc;
   TimeInterval elapsed; /* from now, minimum */
-  Distance was_distance;
-  Segment *hindmost;
+  Distance was_distance, autopoint_distance;
+  Segment *hindmost, *furthest;
 
   PredictionProblemCallback *problem_callback;
   void *problem_callback_u;
@@ -268,12 +269,15 @@ static ErrorCode predict_vproblem(PredictUserContext *u, Segment *seg,
 
   l= vasprintf(&message, fmt, al);  if (l <= 0) diem();
 
-  if (!u->problem_callback)
+  if (u->optimistic)
+    oprintf(DUPO("safety") " predict   optimistic problem %s\n", message);
+  else if (!u->problem_callback)
     safety_panic(u->train, seg, "unexpected problem predicted"
                 " (context: %s): %s", (char*)u->problem_callback_u, message);
   else
     u->problem_callback(u->train, seg, u->problem_callback_u, message);
 
+  free(message);
   return EC_SignallingPredictedProblem;
 }
 
@@ -292,7 +296,7 @@ static void pred_callback_debug(const char *what, TrackLocation *t,
   PredictUserContext *u= c->u;
   
   oprintf(DUPO("safety") " predict   %s"
-         " %s%s until=%ld dist=%d (was %d) %c%c%c.%c  %c%c%c.%c%c%c%c"
+         " %s%s until=%ld dist=%d (was %d) %c%c%c.%c  %c%c%c%c.%c%c%c%c"
          " elapsed=%ld nit=%d,%d\n",
          what,
          t->backwards?"-":"", t->seg->i->pname, (long)t->seg->until,
@@ -307,6 +311,7 @@ static void pred_callback_debug(const char *what, TrackLocation *t,
          "-t"[ u->count_time ],
          "-a"[ u->accelerating ],
          "-c"[ u->usecurrentposn ],
+         "-o"[ u->optimistic ],
          
          "-w"[ u->walk_compute_polarise ],
          "-n"[ u->need_polarise ],
@@ -432,6 +437,10 @@ static int nose_nextseg(TrackLocation *t, TrackAdvanceContext *c,
   } else {
     max_ms= u->elapsed;
   }
+
+  if (!u->train->autopoint || !t->seg->autopoint)
+    return predict_problem(u,t->seg,"will not automatically set point");
+
   ec= movpos_reserve(t->seg, max_ms, &route_reservation, route_plan, *mpc_io);
   if (ec) return predict_problem(u, t->seg, "cannot promise to"
                                 " set route: %s", ec2str(ec));
@@ -528,7 +537,13 @@ static int fdet_nextseg(TrackLocation *t, TrackAdvanceContext *c,
     u->walk_compute_polarise= u->need_polarise=
       (t->seg->seg_inverted ^ t->seg->tr_backwards ^
        u->train_polarity_inverted);
-  }
+
+    if (u->train->autopoint) {
+      const SegPosCombInfo *pci;
+      r= trackloc_getlink(t,c,&pci,0,-1);  assert(!r);
+      u->autopoint_distance= pci->dist;
+    }
+  }    
 
   if (u->walk_compute_polarise) {
     if (t->seg->will_polarise)
@@ -576,6 +591,21 @@ static int fdet_nextseg(TrackLocation *t, TrackAdvanceContext *c,
   return 0;
 }
 
+/*---------- backtracking the optimistic nose ----------*/
+
+static int optunwind_nextseg(TrackLocation *t, TrackAdvanceContext *c,
+                            MovPosComb *mpc_io, Segment *before) {
+  PredictUserContext *u= c->u;
+
+  if (t->seg == u->furthest ||
+      t->seg->motion)
+    return EC_SignallingHorizonReached;
+
+  t->seg->pred_present= 0;
+  t->seg->until= 0;
+  return 0;
+}
+
 /*---------- reporting position and ownership ----------*/
 
 void report_train_position(Train *tra) {
@@ -742,6 +772,25 @@ ErrorCode predict(Train *tra, int accelerate,
   ec= trackloc_advance(&u.fdet,&u.fdetc);
   if (ec && ec != EC_SignallingHorizonReached) goto xproblem;
 
+  /* look ahead for autopoint */
+
+  oprintf(DUPO("safety") " predict  optimism %d\n", u.autopoint_distance);
+
+  if (u.autopoint_distance) {
+    u.furthest= u.nose.seg;
+    u.optimistic= 1;
+    u.nosec.distance= u.autopoint_distance;
+    trackloc_advance(&u.nose,&u.nosec);
+
+    /* But actually we don't want to end up owning
+     * segments unless we have to for motions. */
+
+    u.nose.backwards ^= 1;
+    u.nosec.nextseg= optunwind_nextseg;
+    ec= trackloc_advance(&u.nose,&u.nosec);
+    assert(ec == EC_SignallingHorizonReached);
+  }
+
   /*----- commit to the plan -----*/
 
   oprintf(DUPO("safety") " predict  committing\n");
index 520867b63e2b38d41c33df029e77dbdce783cabe..e6ab4c14c5a870ba5cc04b7fa92bb7b97cea83cc 100644 (file)
@@ -43,6 +43,7 @@ struct Train {
   Distance maxinto, uncertainty;
   unsigned
     backwards:1, /* train is moving backwards wrt its own front and back */
+    autopoint:1, /* set points automatically if point has autopoint too */
 
   /* Startup resolution (resolve.c): */
     resolution:2; /* for use by speedmanager */
@@ -66,6 +67,7 @@ struct Segment {
   unsigned
     tr_backwards:1, /* train's motion is (would be) backwards wrt track */
     ho_backwards:1, /* home train has its front and rear backwards wrt track */
+    autopoint:1, /* set points automatically if train has autopoint too */
     seg_inverted:1, /* polarity is inverted */
     det_ignore:1, det_expected:1, /* safety.c */
     moving:1, /* feature(s) have been told to change */
@@ -282,7 +284,7 @@ int trackloc_getlink(TrackLocation *t, TrackAdvanceContext *c,
                     const SegPosCombInfo **pci_r /* 0 ok */,
                     const SegmentLinkInfo **link_r /* 0 ok */,
                     MovPosComb mpc /* -1: get from segment */);
-  /* Of c, only c->getmovpos is used.
+  /* Of c, only c->getmovpos is used.  t->remain is not used.
    * c may be 0 which works just like c->getmovpos==0. */
 
 Segment *segment_interferes(TrackAdvanceContext *c, Segment *base);