def setActuators(self, actuator_values): """Send the actuator actions.""" parsed_values = [] for actuator, value in actuator_values: if int(value): print "ActuatorHandler: Setting actuator", actuator, "to", value else: print "ActuatorHandler: Taking no action on zero setting of", actuator continue # Parse the action action_match = ACTION_RE.match(actuator) action = action_match.group('action') # Verify that it's either a simple or complex action if action_match and action in COMPLEX_ACTUATORS: actuator = COMPLEX_ACTUATORS[action] value = action_match.group('target') elif actuator in SIMPLE_ACTUATORS: # No target for a simple action value = None else: raise ValueError("Don't know how to %s. " % actuator + "Maybe it should be a custom proposition and not an actuator.") # Notify about the actuator and store the result for the command self.state_mgr.notify_actuator(action, value) parsed_values.append((actuator, value)) send_ltl_commands(parsed_values, self.state_mgr.pub)
def gotoRegion(self, current_region, next_region): """Send a drive message to the specified region and return True if we arrive.""" if current_region == next_region: # We don't print anything as this message would come up all the time # But do release the lock, as we will be stopping motion if we were moving. if self.have_lock: self.state_mgr.motion_lock.release() self.have_lock = False self.next_region = None return False elif self.next_region == next_region: # In test mode, always get there if self.test_mode or self.state_mgr.location == next_region: # For the sake of test mode, lie about the true location if self.test_mode: self.state_mgr.location = next_region print "MotionHandler: Finished moving from", current_region, "to", next_region self.state_mgr.motion_lock.release() self.have_lock = False print "Released motion lock." return True else: # Keep doing what we're doing return False else: if self.have_lock: print "Already have lock" else: print "Acquiring lock..." if self.have_lock or self.state_mgr.motion_lock.acquire(False): self.have_lock = True print "Got motion lock." print "MotionHandler: Moving from", current_region, "to", next_region self.next_region = next_region room_name = next_region send_ltl_commands(((DRIVE_COMMAND, room_name),), self.state_mgr.pub) return False else: print "MotionHandler: Couldn't get motion lock. Not moving." return False
def stopActuators(self): """Stop all actuators.""" print "Stopping automaton by request." send_ltl_commands((), self.state_mgr.pub)