chiark / gitweb /
new units arrangements for speed
authorian <ian>
Sat, 2 Feb 2008 00:06:26 +0000 (00:06 +0000)
committerian <ian>
Sat, 2 Feb 2008 00:06:26 +0000 (00:06 +0000)
hostside/record.c
hostside/safety.h

index 45bcca6158c07ef7e4349a1c698c2fd3790bf2bf..43448ee8c9f9a860d17032415eda5dd5c84a59c0 100644 (file)
@@ -9,6 +9,8 @@
  *  train <trainpn> step <step>=<speed> <upwait>/<downwait>
  *  seg <segpn> has [-]<ownerpn>|$
  *  seg <segpn> at <movposcomb>
+ *
+ * speed is in um/s, upwait and downwait are in us
  */
 
 #include <sys/mman.h>
@@ -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) {
index d7411315e8d4dc5920e4d3ecddbd6d2bfe95c4a0..61ca48e9e52df62fbe77c41c28da78ff4d52052c 100644 (file)
@@ -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<<SPEED_SHIFT) /* ms/mm */
 
 /*========== state of the layout ==========*/