typedef struct {
Train *train;
unsigned
- accelerating:1,
+ neednewplan:1,
stopping:1,
done_first_new_fdet:1,
usecurrentposn:1, /* for pred_getmovpos */
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;
}
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;
}
/*========== 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;
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 {
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 {
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);
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);
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,
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);
}
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;
}