summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2009-05-17 22:20:41 +0200
committerNicolas Schodet2009-05-17 22:20:41 +0200
commitf833faabec7718e112d12203342804be0e19c604 (patch)
treedc722422c733607847537bbf78a5ac00d560abd0
parent38a645f2887b311d2d32f32f555e5b484b16f3b4 (diff)
* digital/io, host/simu:
- added contacts.
-rw-r--r--digital/io/src/simu.host.c9
-rw-r--r--digital/io/tools/io/mex.py44
l---------host/simu/mex1
-rw-r--r--host/simu/robots/aquajim/model/bag.py1
4 files changed, 55 insertions, 0 deletions
diff --git a/digital/io/src/simu.host.c b/digital/io/src/simu.host.c
index f13f84a5..e3c9fc69 100644
--- a/digital/io/src/simu.host.c
+++ b/digital/io/src/simu.host.c
@@ -44,6 +44,7 @@ enum
MSG_SIMU_IO_SHARPS = 0xb3,
MSG_SIMU_IO_PATH = 0xb4,
MSG_SIMU_IO_PWM = 0xb5,
+ MSG_SIMU_IO_CONTACT = 0xb6,
};
/** Requested servo position. */
@@ -72,11 +73,19 @@ uint8_t PORTB;
/** Contact registers. */
uint8_t PORTC, PINC;
+void
+handle_contact (void *user, mex_msg_t *msg)
+{
+ mex_msg_pop (msg, "B", &PINC);
+}
+
/** Initialise simulation. */
void
simu_init (void)
{
mex_node_connect ();
+ mex_node_register (MSG_SIMU_IO_CONTACT, handle_contact, 0);
+ PINC = 0x3f;
simu_servo_update_cpt = 1;
simu_switch_update_cpt = 1;
simu_sharps_update_cpt = 1;
diff --git a/digital/io/tools/io/mex.py b/digital/io/tools/io/mex.py
index 6f762ccd..d3c814ef 100644
--- a/digital/io/tools/io/mex.py
+++ b/digital/io/tools/io/mex.py
@@ -24,6 +24,7 @@
"""Mex interface to io."""
from utils.observable import Observable
+import simu.mex.msg
ID_JACK = 0xb0
ID_COLOR = 0xb1
@@ -31,6 +32,7 @@ ID_SERVO = 0xb2
ID_ADC = 0xb3
ID_PATH = 0xb4
ID_PWM = 0xb5
+ID_CONTACT = 0xb6
SERVO_NB = 6
SERVO_VALUE_MAX = 255
@@ -40,6 +42,9 @@ ADC_NB = 6
PWM_NB = 1
PWM_VALUE_MAX = 1024
+CONTACT_NB = 2
+CONTACT_INIT = 0x3f
+
class Mex:
"""Handle communications with simulated io."""
@@ -157,6 +162,42 @@ class Mex:
pwm.value = float (value) / PWM_VALUE_MAX
pwm.notify ()
+ class Contact (Observable):
+ """Contact input.
+
+ - state: True (open) or False (closed).
+
+ """
+
+ def __init__ (self, pack, index):
+ Observable.__init__ (self)
+ self.pack = pack
+ self.index = index
+ self.state = None
+ self.register (self.__notified)
+
+ def __notified (self):
+ self.pack.set (self.index, self.state)
+
+ class Pack:
+ """Handle emission of several contacts for one message."""
+
+ def __init__ (self, node):
+ self.node = node
+ self.contacts = CONTACT_INIT
+
+ def set (self, index, state):
+ if state is None or state:
+ self.contacts |= 1 << index
+ else:
+ self.contacts &= ~(1 << index)
+ self.__send ()
+
+ def __send (self):
+ m = simu.mex.msg.Msg (ID_CONTACT)
+ m.push ('B', self.contacts)
+ self.node.send (m)
+
def __init__ (self, node):
self.jack = self.Switch (node, ID_JACK)
self.color_switch = self.Switch (node, ID_COLOR)
@@ -167,4 +208,7 @@ class Mex:
self.path = self.Path (node)
self.pwm = tuple (self.PWM () for i in range (0, PWM_NB))
self.__adc_pwm = self.PWM.Pack (node, self.pwm)
+ self.__contact_pack = self.Contact.Pack (node)
+ self.contact = tuple (self.Contact (self.__contact_pack, i)
+ for i in range (CONTACT_NB))
diff --git a/host/simu/mex b/host/simu/mex
new file mode 120000
index 00000000..5075d07f
--- /dev/null
+++ b/host/simu/mex
@@ -0,0 +1 @@
+../mex \ No newline at end of file
diff --git a/host/simu/robots/aquajim/model/bag.py b/host/simu/robots/aquajim/model/bag.py
index 31827c35..929d240a 100644
--- a/host/simu/robots/aquajim/model/bag.py
+++ b/host/simu/robots/aquajim/model/bag.py
@@ -34,6 +34,7 @@ class Bag:
def __init__ (self, scheduler, table, link_bag):
self.jack = Switch (link_bag.io.jack)
self.color_switch = Switch (link_bag.io.color_switch)
+ self.contact = [ Switch (contact) for contact in link_bag.io.contact ]
self.position = Position (link_bag.asserv.position)
self.elevator_door = MotorBasic (link_bag.io.pwm[0], scheduler,
2 * pi, 0, pi / 2)