def map(self): """Get the associated pose map for this pose. :return: The Map object. """ from fetchcore.resources.maps import Map return Map.load(self.map_id)
def on_message(ws, message): """Handle the incoming WebSocket message. :param ws: The WebSocketApp which contains a reference to the associated Fetch client. :param message: The message sent from the server. """ try: # Attempt to parse the message as a JSON object payload = json.loads(message)['payload'] model = payload['model'].replace('api.', '') # TODO: check created/modified/deleted and handle differently # See if we know about this kind of model resource = None # TODO: add more models if model == 'log': from fetchcore.resources import Log resource = Log(**payload['data']) elif model == 'task': from fetchcore.resources import Task resource = Task(**payload['data']) elif model == 'action': from fetchcore.resources import Action resource = \ Action.get_action_class(payload['data']['action_definition'])(**payload['data']) elif model == 'robotstate': from fetchcore.resources.robots import RobotState resource = RobotState(**payload['data']) elif model == 'robot': from fetchcore.resources.robots import Robot resource = Robot(**payload['data']) elif model == 'revision': from fetchcore.resources.maps import Revision resource = Revision(**payload['data']) elif model == 'map': from fetchcore.resources.maps import Map try: # Image must be a dummy string since we don't receive it as part of change resource = Map(image="", **payload['data']) except Exception as err: print "Tried to make a map resource with %s, but got %s" % ( payload['data'], err) elif model == 'chargesettings': from fetchcore.resources import ChargeSettings resource = ChargeSettings(**payload['data']) elif model == 'hmisettings': from fetchcore.resources import HMISettings resource = HMISettings(**payload['data']) elif model == 'robotsettings': from fetchcore.resources import RobotSettings resource = RobotSettings(**payload['data']) elif model == 'stagesettings': from fetchcore.resources import StageSettings resource = StageSettings(**payload['data']) elif model == 'updatesettings': from fetchcore.resources import UpdateSettings resource = UpdateSettings(**payload['data']) if resource is not None: for callback in ws.client._callbacks: callback( resource, ResourceActions.__getattribute__( payload['action'].upper()), ResourceTypes.__getattribute__(model.upper())) else: logging.error("%s responded with unknown model '%s'." % (ws.url, model)) except (ValueError, KeyError, AttributeError) as e: logging.error("%s responded with malformed message '%s'. %s" % (ws.url, message, e))
def map(self): """Get the map object that this revision belongs to. :return: The Map object. """ return Map.load(self.map_id)
def map(self): """Get the map object for this robot. :return: The robot's map object. """ return None if self.map_id is None else Map.load(self.map_id)