def __init__(self, world, name = "Motor", block = None, link = None, angle = 0.0, cfg = None, **params): Component.__init__(self, name) # define motor slots self.initialize_slots = True self.status_slot = StrSlot(IDLE) self.angle_slot = DoubleSlot(angle) self.pos_slot = Vec3Slot() self._lastAngle = angle self.addSlot("status", self.status_slot) self.addSlot("angle", self.angle_slot) self.addSlot("pos", self.pos_slot) self._angle_forwader = NotificationForwarder(self._onAngleChanged) self.angle_slot.addDependent(self._angle_forwader) self.initialize_slots = False self.world = world self.cfg = cfg self.block = block self.link = link self._remainingTime = self.cfg['timeout'] self._createComponents() self._configureComponents() self._connectComponents() # add joint to world self.world.add(self._joint) # listen to events eventManager().connect(STEP_FRAME, self._onStepFrame)
def __init__(self, world, name="Robot", cfg = None, data = None): Component.__init__(self, name) self.world = world self.modules = [] self.cfg = cfg self.brain = None self.interactive = True self._preState = None self._action = None self._actionDone = True self._steps = 0 self._initialPos = 0 self._totalWalked = 0 self._timer = getScene().timer() self._beforeExecution = self._timer.time eventManager().connect(STEP_FRAME, self._onStepFrame)
def testEventManager(self): """Test the EventManager class. """ em = eventManager() em.disconnectAll() rec = Receiver() em.connect("Spam", rec) em.connect("Spam", rec.otherCallback) em.event("Spam") self.assertEqual([("spam",0),("other",)], rec.called) em.disconnect("Spam", rec) rec.called = [] em.event("Spam") self.assertEqual([("other",)], rec.called) em.disconnect("Spam", rec.otherCallback) rec.called = [] em.event("Spam") self.assertEqual([], rec.called) # Check priorities em.connect("Spam", rec) em.connect("Spam", rec.otherCallback, priority=5) em.event("Spam") self.assertEqual([("other",), ("spam",0)], rec.called) # Add another receiver which must still be there after disconnect("Spam") has been called em.connect("Eggs", rec) em.disconnect("Spam") rec.called = [] em.event("Spam") self.assertEqual([], rec.called) # Check that the Eggs receiver is still there... em.event("Eggs", arg2=5, arg1=3) self.assertEqual([("eggs", 3, 5)], rec.called) rec.called = [] em.event("Eggs", 1, 2) self.assertEqual([("eggs", 1, 2)], rec.called) # Check disconnectAll() em.connect("Spam", rec) em.disconnectAll() rec.called = [] em.event("Spam") em.event("Eggs", 3, 4) self.assertEqual([], rec.called)
def testEventManager(self): """Test the EventManager class. """ em = eventManager() em.disconnectAll() rec = Receiver() em.connect("Spam", rec) em.connect("Spam", rec.otherCallback) em.event("Spam") self.assertEqual([("spam", 0), ("other", )], rec.called) em.disconnect("Spam", rec) rec.called = [] em.event("Spam") self.assertEqual([("other", )], rec.called) em.disconnect("Spam", rec.otherCallback) rec.called = [] em.event("Spam") self.assertEqual([], rec.called) # Check priorities em.connect("Spam", rec) em.connect("Spam", rec.otherCallback, priority=5) em.event("Spam") self.assertEqual([("other", ), ("spam", 0)], rec.called) # Add another receiver which must still be there after disconnect("Spam") has been called em.connect("Eggs", rec) em.disconnect("Spam") rec.called = [] em.event("Spam") self.assertEqual([], rec.called) # Check that the Eggs receiver is still there... em.event("Eggs", arg2=5, arg1=3) self.assertEqual([("eggs", 3, 5)], rec.called) rec.called = [] em.event("Eggs", 1, 2) self.assertEqual([("eggs", 1, 2)], rec.called) # Check disconnectAll() em.connect("Spam", rec) em.disconnectAll() rec.called = [] em.event("Spam") em.event("Eggs", 3, 4) self.assertEqual([], rec.called)
def testRemoveReceiver(self): """Test removing a receiver while the callbacks are still being called. (this has been a bug in earlier versions) """ em = eventManager() em.disconnectAll() rec = Receiver(em=em) em.connect("Remove", rec) em.connect("Remove", rec.onSpam) em.connect("Remove", rec.otherCallback) em.event("Remove") self.assertEqual([("remove",),("spam",0),("other",)], rec.called) rec.called = [] em.event("Remove") self.assertEqual([("spam",0),("other",)], rec.called)
def testRemoveReceiver(self): """Test removing a receiver while the callbacks are still being called. (this has been a bug in earlier versions) """ em = eventManager() em.disconnectAll() rec = Receiver(em=em) em.connect("Remove", rec) em.connect("Remove", rec.onSpam) em.connect("Remove", rec.otherCallback) em.event("Remove") self.assertEqual([("remove", ), ("spam", 0), ("other", )], rec.called) rec.called = [] em.event("Remove") self.assertEqual([("spam", 0), ("other", )], rec.called)