import math
import strfmt
# The amount of chain that is moved through one full rotation, in meters
const gearCircumference* = math.PI * 0.10
type
Dir* = enum
CW, CCW
MachineState* = object of RootObj
lpos*: float
rpos*: float
ldir*: Dir
rdir*: Dir
lenable*: bool
renable*: bool
Hal* = object of RootObj
steprads*: float
current*: MachineState
Motion* = object of RootObj
ln*: uint32
lhz*: uint32
rn*: uint32
rhz*: uint32
ldir*: Dir
rdir*: Dir
proc writeformat*(o: var Writer, x: Dir, fmt: Format) =
writeformat(o, $x, fmt)
proc `$`*(m: Motion): string =
"[left {0.ln}@{0.lhz}hz, right {0.rn}@{0.rhz}hz]".fmt(m)
proc `$`*(ms: MachineState): string =
return ("[left p={0.lpos} d={0.ldir} e={0.lenable} " &
"right p={0.rpos} d={0.rdir} e={0.renable}]").fmt(ms)