summaryrefslogtreecommitdiffhomepage
path: root/digital/mimot/tools/mimot/mex.py
diff options
context:
space:
mode:
Diffstat (limited to 'digital/mimot/tools/mimot/mex.py')
-rw-r--r--digital/mimot/tools/mimot/mex.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/digital/mimot/tools/mimot/mex.py b/digital/mimot/tools/mimot/mex.py
index b32f2925..a190c1cc 100644
--- a/digital/mimot/tools/mimot/mex.py
+++ b/digital/mimot/tools/mimot/mex.py
@@ -24,8 +24,10 @@
"""Mex interface to mimot."""
from utils.observable import Observable
+import simu.mex.msg
ID_AUX = 0xc8
+ID_LIMITS = 0xcc
class Mex:
"""Handle communications with simulated mimot."""
@@ -54,7 +56,50 @@ class Mex:
aux.angle = float (angle) / 1024
aux.notify ()
+ class Limits (Observable):
+ """Motor limits.
+
+ - min, max: limits in radian.
+
+ """
+
+ def __init__ (self, pack, index):
+ Observable.__init__ (self)
+ self.pack = pack
+ self.index = index
+ self.min = None
+ self.max = None
+ self.register (self.__notified)
+
+ def __notified (self):
+ self.pack.set (self.index, self.min, self.max)
+
+ class Pack:
+ """Handle emission of several limits for one message."""
+
+ def __init__ (self, node):
+ self.node = node
+ self.limits = [ None, None, None, None ]
+
+ def set (self, index, min, max):
+ self.limits[index * 2] = min
+ self.limits[index * 2 + 1] = max
+ self.__send ()
+
+ def __send (self):
+ m = simu.mex.msg.Msg (ID_LIMITS)
+ for l in self.limits:
+ if l is None:
+ li = -1
+ else:
+ li = int (l * 1024)
+ m.push ('l', li)
+ self.node.send (m)
+
def __init__ (self, node):
self.aux = (self.Aux (), self.Aux ())
self.__aux_pack = self.Aux.Pack (node, self.aux)
+ self.__limits_pack = self.Limits.Pack (node)
+ for index, aux in enumerate (self.aux):
+ aux.limits = self.Limits (self.__limits_pack, index)