From b3d38cf6ef1878953853982f21d01d3ad4a97441 Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 2 Feb 2008 00:06:26 +0000 Subject: [PATCH] new units arrangements for speed --- hostside/record.c | 8 +++++--- hostside/safety.h | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/hostside/record.c b/hostside/record.c index 45bcca6..43448ee 100644 --- a/hostside/record.c +++ b/hostside/record.c @@ -9,6 +9,8 @@ * train step = / * seg has [-]|$ * seg at + * + * speed is in um/s, upwait and downwait are in us */ #include @@ -188,9 +190,9 @@ void record_train_step(Train *tra, int step, int speed, int upw, int downw) { curvebufsz++; new->step= step; - new->speed= speed; - new->upwait= upw; - new->downwait= downw; + new->speed= speed * 1e-6 * SPEED_UNIT; + new->upwait= upw * 1e-3; + new->downwait= downw * 1e-3; } static int speedcurveentry_compare(const void *av, const void *bv) { diff --git a/hostside/safety.h b/hostside/safety.h index d741131..61ca48e 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -19,9 +19,13 @@ typedef short TimeInterval; /*ms*/ * 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 */ -#define SPEED_SHIFT 7 +#define SPEED_SHIFT 16 /* units of 15um/s, max distance 2^15mm =~ 32m */ #define SPEED_UNIT (1L<