From c8d4bd0e0f79dc8e49ad0074a1e67317e903c41f Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 14 May 2011 01:28:54 +0200 Subject: digital/io-hub, host/simu: add contacts --- host/simu/robots/robospierre/model/clamp.py | 36 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'host/simu/robots/robospierre/model/clamp.py') diff --git a/host/simu/robots/robospierre/model/clamp.py b/host/simu/robots/robospierre/model/clamp.py index 9bb8bacc..e2592aa8 100644 --- a/host/simu/robots/robospierre/model/clamp.py +++ b/host/simu/robots/robospierre/model/clamp.py @@ -29,13 +29,19 @@ from math import pi, cos, sin class Slot: """Slot which can contain a pawn.""" - def __init__ (self, x, y, z, side, door_motor): + def __init__ (self, x, y, z, side, door_motor, contact): self.x = x self.y = y self.z = z self.side = side - self.pawn = None self.door_motor = door_motor + self.contact = contact + self.set_pawn (None) + + def set_pawn (self, pawn): + self.pawn = pawn + self.contact.state = pawn is None + self.contact.notify () class Clamp (Observable): @@ -60,7 +66,7 @@ class Clamp (Observable): SLOT_SIDE = 6 def __init__ (self, table, robot_position, elevation_motor, - rotation_motor, clamping_motor, door_motors): + rotation_motor, clamping_motor, door_motors, slot_contacts): Observable.__init__ (self) self.table = table self.robot_position = robot_position @@ -71,19 +77,19 @@ class Clamp (Observable): door_motors[2], None, door_motors[3], None) self.slots = ( Slot (self.BAY_OFFSET, 0, 0 * self.BAY_ZOFFSET, 0, - door_motors[0]), + door_motors[0], slot_contacts[0]), Slot (self.BAY_OFFSET, 0, 1 * self.BAY_ZOFFSET, 0, - None), + None, slot_contacts[1]), Slot (self.BAY_OFFSET, 0, 2 * self.BAY_ZOFFSET, 0, - door_motors[1]), + door_motors[1], slot_contacts[2]), Slot (-self.BAY_OFFSET, 0, 0 * self.BAY_ZOFFSET, 1, - door_motors[2]), + door_motors[2], slot_contacts[3]), Slot (-self.BAY_OFFSET, 0, 1 * self.BAY_ZOFFSET, 1, - None), + None, slot_contacts[4]), Slot (-self.BAY_OFFSET, 0, 2 * self.BAY_ZOFFSET, 1, - door_motors[3]), + door_motors[3], slot_contacts[5]), Slot (0, self.BAY_OFFSET, 2 * self.BAY_ZOFFSET, None, - None)) + None, slot_contacts[6])) self.load = None self.robot_position.register (self.__robot_position_notified) self.elevation_motor.register (self.__elevation_notified) @@ -98,7 +104,7 @@ class Clamp (Observable): if slot.pawn is None: p = self.__get_floor_elements (slot.side) if p is not None: - slot.pawn = p + slot.set_pawn (p) p.pos = None p.notify () changed = True @@ -133,14 +139,16 @@ class Clamp (Observable): if self.clamping == 0 and self.load is None: # Load an element. slot = self.__get_clamp_slot () - if slot: - self.load, slot.pawn = slot.pawn, self.load + if slot and slot.pawn is not None: + self.load = slot.pawn + slot.set_pawn (None) elif self.clamping == self.CLAMPING_STROKE \ and self.load is not None: # Unload an element. slot = self.__get_clamp_slot () if slot and slot.pawn is None: - self.load, slot.pawn = slot.pawn, self.load + slot.set_pawn (self.load) + self.load = None self.notify () def __get_floor_elements (self, side): -- cgit v1.2.3