From: ian Date: Sat, 17 May 2008 23:58:38 +0000 (+0000) Subject: replace "accelerating" with flags parameter to predict X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=3146cc9546682a630a344084a8d357c4cbbe5b30;p=trains.git replace "accelerating" with flags parameter to predict --- diff --git a/hostside/safety.c b/hostside/safety.c index 814bbcf..0a79b9c 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -238,7 +238,7 @@ Segment *segments; typedef struct { Train *train; unsigned - accelerating:1, + neednewplan:1, stopping:1, done_first_new_fdet:1, usecurrentposn:1, /* for pred_getmovpos */ @@ -437,7 +437,7 @@ static int nose_nextseg(TrackLocation *t, TrackAdvanceContext *c, assert(!t->seg->now_present); if (!t->seg->owner) return predict_problem(u, t->seg, "route not yet set"); - if (!u->accelerating) { + if (!u->neednewplan) { *mpc_io= movpos_change_intent(t->seg->motion); goto movement_ok; } @@ -446,7 +446,7 @@ static int nose_nextseg(TrackLocation *t, TrackAdvanceContext *c, if (t->seg->motion) { /* We already have a plan. */ route_plan= movpos_change_intent(t->seg->motion); - if (!u->accelerating) { + if (!u->neednewplan) { *mpc_io= route_plan; goto movement_ok; } @@ -631,7 +631,7 @@ static int optunwind_nextseg(TrackLocation *t, TrackAdvanceContext *c, /*========== prediction entrypoint ==========*/ -ErrorCode predict(Train *tra, int accelerate, struct timeval tnow, +ErrorCode predict(Train *tra, struct timeval tnow, unsigned flags, PredictionProblemCallback *ppc, void *ppcu) { PredictUserContext u; Segment *foredet; @@ -642,18 +642,19 @@ ErrorCode predict(Train *tra, int accelerate, struct timeval tnow, u.train= tra; u.problem_callback= ppc; u.problem_callback_u= ppcu; - u.accelerating= accelerate > 0; + u.neednewplan= !!(flags & PREDF_NEWPLAN); u.maxspeed= speedmanager_speed_maxestimate(u.train, tnow); - u.stopping= accelerate<=0 && speedmanager_stopping(u.train); + u.stopping= !(flags & PREDF_NEWPLAN) && speedmanager_stopping(u.train); u.stopping_distance= speedmanager_stoppingdistance(u.train, tnow); oprintf(DUPO("safety") " predict ***starting*** %s%s maxspeed=%f" - " (speed %f try %f, step %d%s) stopdist=%d accelerate=%d %s\n", + " (speed %f try %f, step %d%s) stopdist=%d flags=%c%c %s\n", tra->backwards?"-":"",tra->pname, u.maxspeed, tra->speed.speed, tra->speed.try_speed, tra->speed.step, tra->speed.decel.running ? " decel" : "", u.stopping_distance, - accelerate, + "-j"[ !!(flags & PREDF_JUSTDET) ], + "-n"[ !!(flags & PREDF_NEWPLAN) ], u.stopping ? " stopping" : ""); FOR_SEG { @@ -730,7 +731,7 @@ ErrorCode predict(Train *tra, int accelerate, struct timeval tnow, u.fdetc.trackend= pred_trackend; u.tailc.nextseg= tail_nextseg; - if (accelerate<0 && u.stopping) { + if ((flags & PREDF_JUSTDET) && u.stopping) { /* we actually know exactly where we are */ u.fdetc.distance= u.stopping_distance; } else { @@ -966,7 +967,7 @@ void safety_notify_detection(Segment *seg) { tra->uncertainty= tra->maxinto= maxinto; report_train_position(tra); - ec= predict(tra,-1,tnow, detection_report_problem, 0); + ec= predict(tra,tnow,PREDF_JUSTDET, detection_report_problem, 0); if (!ec) return; assert(ec == EC_SignallingPredictedProblem); @@ -976,7 +977,7 @@ void safety_notify_detection(Segment *seg) { report_train_position(tra); speedmanager_safety_stop(tra,tnow); - ec= predict(tra,-1,tnow, 0,(char*)"safety commanding stop"); + ec= predict(tra,tnow,PREDF_JUSTDET, 0,(char*)"safety commanding stop"); assert(!ec); assert(!ec); diff --git a/hostside/safety.h b/hostside/safety.h index 1745021..c286697 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -109,20 +109,19 @@ ErrorCode safety_check_movposchange(Segment *seg, PredictionProblemCallback *ppc, void *ppcu); /* If this check success, caller may call movpos_change */ -ErrorCode predict(Train *tra, int accelerate, struct timeval tnow, +#define PREDF_JUSTDET 001u + /* we have just detected the train entering its foredetect so we + * can subtract the uncertainty from the stopping distance */ +#define PREDF_NEWPLAN 002u + /* the existing plan is not necessarily sufficient as + * we are intending to accelerate or change a movpos */ + +ErrorCode predict(Train *tra, struct timeval tnow, unsigned flags, PredictionProblemCallback *ppc, void *ppcu); /* Lower-level interface for speedmanager etc. * Caller must call this with different situations until it succeeds! * Caller may pass ppc=0 and ppcu=(char*)"some context" to - * cause safety_panic if it fails. - * - * accelerate should be: - * -1 if we have just detected the train entering its foredetect - * so we can subtract the uncertainty from the stopping distance - * 0 if whatever we are doing will not disturb the existing plan - * 1 if we the existing plan is not necessarily sufficient as - * we are intending to accelerate or something - */ + * cause safety_panic if it fails. */ void report_train_position(Train *tra); void report_train_ownerships(Train *tra, Segment *furthest, diff --git a/hostside/speed.c b/hostside/speed.c index 627eff5..3ed94e8 100644 --- a/hostside/speed.c +++ b/hostside/speed.c @@ -118,7 +118,7 @@ static ErrorCode request_core(Train *tra, int step, struct timeval tnow, toev_start(&tra->speed.decel); tra->speed.speed= vnow; if (ppc || ppcu) { - ec= predict(tra,0,tnow, 0,(char*)"deceleration forbidden"); + ec= predict(tra,tnow,0, 0,(char*)"deceleration forbidden"); assert(!ec); } xmit(tra); @@ -126,11 +126,11 @@ static ErrorCode request_core(Train *tra, int step, struct timeval tnow, } tra->speed.try_speed= vtarg; - ec= predict(tra,1,tnow, ppc,ppcu); + ec= predict(tra,tnow,PREDF_NEWPLAN, ppc,ppcu); if (ec) { tra->speed.try_speed= -1; - ec2= predict(tra,0,tnow, 0,(char*)"abandoned acceleration"); + ec2= predict(tra,tnow,0, 0,(char*)"abandoned acceleration"); assert(!ec2); return ec; }