From: ian Date: Sat, 19 Apr 2008 00:02:41 +0000 (+0000) Subject: new units: doubles everywhere; wip new safety X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=f87206e8b1e72d8aa4e7e4425eabce60b2a40c19;p=trains.git new units: doubles everywhere; wip new safety --- diff --git a/hostside/analyse-speeds b/hostside/analyse-speeds index bc9d866..1742248 100755 --- a/hostside/analyse-speeds +++ b/hostside/analyse-speeds @@ -99,12 +99,12 @@ perl <$o.table.tmp >$o.record.tmp -ne ' sub calcwait ($$) { my ($step,$wholetime) = @_; return 0 if $step<0 || $step>=$steps; - return $wholetime * 1000.0 * + return $wholetime * ($speed[$step+1] - $speed[$step]) / $max; } for ($step=0; $step<$nxt; $step++) { - printf "train %s step %d=%d %d/%d\n", - "'$train'", $step, $speed[$step]*1e6, + printf "train %s step %d=%f %f/%f\n", + "'$train'", $step, $speed[$step]*1e3, calcwait($step-1,'$acceltime'), calcwait($step,'$deceltime') or die $!; diff --git a/hostside/persist.c b/hostside/persist.c index 1335bc7..739b5aa 100644 --- a/hostside/persist.c +++ b/hostside/persist.c @@ -373,7 +373,7 @@ 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:%d+-%d\n", + printf("train %s at %s%s:%f+-%f\n", tra->pname, tra->backwards ? "-" : "", tra->foredetect->i->pname, tra->maxinto, tra->uncertainty); } diff --git a/hostside/record-l.l b/hostside/record-l.l index 578f51f..07f7803 100644 --- a/hostside/record-l.l +++ b/hostside/record-l.l @@ -33,6 +33,7 @@ end { STR END; } [0-9]{0,8} { record_yylval.num= strtoul(yytext,0,10); return NUM; } [0-9]{9} { record_yyerror("number too long"); } +[0-9][0-9]*\.[0-9]* { record_yylval.dbl= strtod(yytext,0); return DBL; } [-+:=~/] { record_yylval.name= 0; return yytext[0]; } diff --git a/hostside/record-y.y b/hostside/record-y.y index 903fefd..12b003e 100644 --- a/hostside/record-y.y +++ b/hostside/record-y.y @@ -14,16 +14,19 @@ static Train *cur_train; FeaturesFeature *feature; FeaturesAddr *feataddr; int num; + double dbl; } %token TRAIN FEATURE SEG IS AT HAS STEP HOME END IDENT FEATLETTER %token NL %token NUM +%token DBL %type ident %type train %type seg %type backwards +%type dbl %type feature %type feataddr @@ -37,16 +40,16 @@ file: end | line NL { record_tempzone_clear(); } file line: /* empty */ - | TRAIN train IS NUM NUM '+' NUM '+' NUM + | TRAIN train IS NUM dbl '+' dbl '+' dbl { if ($2) record_train_is($2,$4,$5,$7,$9); } - | TRAIN train AT backwards seg ':' NUM '+' '-' NUM + | TRAIN train AT backwards seg ':' dbl '+' '-' dbl { if ($2) record_train_at($2,$4,$5,$7,$10); } | TRAIN train HOME { cur_train=$2; } segments { } - | TRAIN train STEP NUM '=' NUM NUM '/' NUM + | TRAIN train STEP NUM '=' dbl dbl '/' dbl { if (!trains) record_train_step_count(); else if ($2) record_train_step($2,$4,$6,$7,$9); } @@ -68,8 +71,11 @@ backwards: /* empty */ { $$= 0; } segments: { cur_train= (void*)-1; } | backwards seg { record_train_home(cur_train,$1,$2); } segments + ident: TRAIN | SEG | IS | AT | HAS | STEP | HOME | END | IDENT | FEATLETTER +dbl: DBL + | NUM { $$= $1 } seg: ident { $$= record_pname2seg($1); } train: ident { $$= record_pname2train($1); } diff --git a/hostside/record.c b/hostside/record.c index 9b54706..c9106a0 100644 --- a/hostside/record.c +++ b/hostside/record.c @@ -297,9 +297,9 @@ void record_train_step(Train *tra, int step, int speed, int upw, int downw) { curvebufused++; new->step= step; - new->speed= speed * 1e-6 * SPEED_UNIT; - new->upwait= upw * 1e-3; - new->downwait= downw * 1e-3; + new->speed= speed; + new->upwait= upw; + new->downwait= downw; } static int speedcurveentry_compare(const void *av, const void *bv) { diff --git a/hostside/resolve.c b/hostside/resolve.c index 32a55c6..0c7bc33 100644 --- a/hostside/resolve.c +++ b/hostside/resolve.c @@ -320,7 +320,7 @@ int resolve_complete(void) { } if (d->owner) - d->until_detect= 1; + d->until_detect= 1e-3; if (d->i->n_poscombs>1) { d->movposcomb= -1; diff --git a/hostside/safety.h b/hostside/safety.h index 4d22969..2dcb0c6 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -11,30 +11,22 @@ /*========== more basic types etc. ==========*/ -typedef short TimeInterval; /*ms*/ +typedef double TimeInterval; /*s*/ /*---------- units and scales ----------*/ /* * Distances are in mm. - * Times are in ms. - * Speeds are in fixed point: unit is 1/SPEED_UNIT m/s - * - * To calculate with speeds and times without using floating point - * it turns out that we can cope with distances of up to - * 2^(31-SPEED_SHIFT) mm + * Times are generally in s. */ -#define SPEED_SHIFT 16 /* units of 15um/s, max distance 2^15mm =~ 32m */ -#define SPEED_UNIT (1L<accel.more); tra->accel.more.callback= estop_done; - tra->accel.more.duration= ESTOP_DEADTIME; + tra->accel.more.duration= TIMEINTERVAL2MS(ESTOP_DEADTIME); toev_start(&tra->accel.more); } @@ -69,12 +69,14 @@ static void adjust_next(Train *tra, int inautostop) { if (tra->accel.target > tra->accel.commanded) { tra->accel.commanded++; - tra->accel.more.duration= tra->accel.curve[tra->accel.commanded].upwait; + tra->accel.more.duration= + TIMEINTERVAL2MS(tra->accel.curve[tra->accel.commanded].upwait); newspeed= tra->accel.curve[tra->accel.commanded].speed; } else if (tra->accel.target < tra->accel.commanded) { newspeed= tra->accel.curve[tra->accel.commanded].speed; tra->accel.commanded--; - tra->accel.more.duration= tra->accel.curve[tra->accel.commanded].downwait; + tra->accel.more.duration= + TIMEINTERVAL2MS(tra->accel.curve[tra->accel.commanded].downwait); } else { return; } @@ -164,7 +166,7 @@ void speedmanager_speedchange_request(Train *tra, long speed) { if (curve[found].speed < speed && speed != INT_MAX) logmsg(EC_Invalid, tra,0, - "requested speed %ld excessive; capping at %ld", + "requested speed %ld excessive; capping at %f", speed, curve[found].speed); changereq_internal(tra, found, 0); diff --git a/layout/data2safety b/layout/data2safety index 95c1eb9..cfac5be 100755 --- a/layout/data2safety +++ b/layout/data2safety @@ -493,7 +493,7 @@ sub writeout () { ($comb / $featr->{Weight}) % $featr->{Posns}); } o("$delim\n"); - o(sprintf " { %-7s%4d", + o(sprintf " { %-7s%7.3f", '"'.$pi.'",', $segr->{Dist}[$comb]); for ($end=0; $end<2; $end++) { diff --git a/layout/layout-data.h b/layout/layout-data.h index bf57f2c..f6eb3e2 100644 --- a/layout/layout-data.h +++ b/layout/layout-data.h @@ -17,12 +17,13 @@ typedef int TrainNum; typedef int SegmentNum; typedef long MovPosComb; -typedef long Speed; typedef int BoardObject; typedef int Small; -typedef int Distance; typedef short SegmentNumInMap; +typedef double Speed; +typedef double Distance; + typedef enum { mfk_none, mfk_point