From 840c8efb0d16b687a685edcd799359e4054d3362 Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 4 May 2008 23:46:56 +0000 Subject: [PATCH] optimistic point setting not yet tested as current home shinkansen placement does not work; also speed 60 anticlockwise seemed not to work --- hostside/commands.c | 13 +++++----- hostside/record.c | 2 ++ hostside/safety.c | 59 +++++++++++++++++++++++++++++++++++++++++---- hostside/safety.h | 4 ++- 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/hostside/commands.c b/hostside/commands.c index 653af23..b7ffd1f 100644 --- a/hostside/commands.c +++ b/hostside/commands.c @@ -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 } }; diff --git a/hostside/record.c b/hostside/record.c index c42b78d..d6e1a96 100644 --- a/hostside/record.c +++ b/hostside/record.c @@ -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) diff --git a/hostside/safety.c b/hostside/safety.c index ebe7b49..2d9b6b4 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -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"); diff --git a/hostside/safety.h b/hostside/safety.h index 520867b..e6ab4c1 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -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); -- 2.30.2