def post(self): content = request.data.decode('utf-8') logger.info(f'request content={content}') result = {'result': 'failure'} try: r_mode = get_attr_value(content, 'r_mode') posx = get_attr_value(content, 'x') posy = get_attr_value(content, 'y') deviceid = get_id(content) floor = self.get_floor_by_robot(deviceid) logger.info( f'received position: r_mode={r_mode}, posx={posx}, posy={posy}, robot_id={deviceid}, floor={floor}' ) if r_mode == 'Standby': content = self.orion.get_attrs(deviceid, 'r_state')['r_state'] current_state = content['value'].strip() state_datetime = parser.parse( content['metadata']['TimeInstant']['value'].strip()) now = datetime.datetime.now(timezone('Asia/Tokyo')) delta_sec = (now - state_datetime).total_seconds() if current_state not in ( const.GUIDING, const.RETURNING ) or delta_sec < self.robot_state_check_wait_sec: message = f'cannot accept command at StopMovmentAPI, current_state={current_state}, deviceid={deviceid} '\ f'r_mode={r_mode}, posx={posx}, posy={posy}, floor={floor}, delta_sec={delta_sec}' logger.debug(message) result['result'] = 'not acceptable' result['message'] = message else: if current_state == const.GUIDING: r_state = const.SUSPENDING else: r_state = const.WAITING attributes = [{ 'name': 'r_state', 'value': r_state, }] message = self.orion.update_attributes( deviceid, self.type, attributes) result['result'] = 'success' result['message'] = message except AttrDoesNotExist as e: logger.error(f'AttrDoesNotExist: {str(e)}') raise BadRequest(str(e)) except NGSIPayloadError as e: logger.error(f'NGSIPayloadError: {str(e)}') raise BadRequest(str(e)) except DestinationFormatError as e: logger.error(f'DestinationFormatError: {str(e)}') raise BadRequest(str(e)) except Exception as e: logger.exception(e) raise e return jsonify(result)
def post(self): content = request.data.decode('utf-8') logger.info(f'request content={content}') result = {'result': 'ignore'} try: r_mode = get_attr_value(content, 'r_mode') posx = get_attr_value(content, 'x') posy = get_attr_value(content, 'y') deviceid = get_id(content) floor = self.get_floor_by_robot(deviceid) logger.info( f'received position: r_mode={r_mode}, posx={posx}, posy={posy}, robot_id={deviceid}, floor={floor}' ) robot_attrs = self.robot_orion.get_attrs(deviceid, 'r_state,destx,desty') current_state = robot_attrs['r_state']['value'].strip() destx = robot_attrs['destx']['value'].strip() desty = robot_attrs['desty']['value'].strip() if posx is not None and posy is not None and floor is not None and current_state == const.GUIDING: destinations = Destination().get_destinations_by_dest_led_pos( posx, posy, floor) if destinations is not None: for destination in destinations: try: if const.DEST_POS_X in destination and float(destination[const.DEST_POS_X]) == float(destx) and \ const.DEST_POS_Y in destination and float(destination[const.DEST_POS_Y]) == float(desty): if const.DEST_LED_ID in destination and destination[ const.DEST_LED_ID] is not None: dest_led_id = destination[ const.DEST_LED_ID] message = self.dest_led_orion.send_cmd( dest_led_id, self.dest_led_type, 'action', 'on') result['result'] = 'success' result['message'] = message break except (ValueError, TypeError): pass except AttrDoesNotExist as e: logger.error(f'AttrDoesNotExist: {str(e)}') raise BadRequest(str(e)) except NGSIPayloadError as e: logger.error(f'NGSIPayloadError: {str(e)}') raise BadRequest(str(e)) except DestinationFormatError as e: logger.error(f'DestinationFormatError: {str(e)}') raise BadRequest(str(e)) except Exception as e: logger.exception(e) raise e return jsonify(result)
def post(self): content = request.data.decode('utf-8') logger.info(f'request content={content}') result = {'result': 'failure'} try: value = get_attr_value(content, 'dest') dest = Destination().get_destination_by_name(value) dest_name = dest.get(DEST_NAME) if not dest_name: raise DestinationFormatError('dest_name is empty') try: dest_floor = int(dest.get(DEST_FLOOR)) except (TypeError, ValueError): raise DestinationFormatError('dest_floor is invalid') if const.SLACK_WEBHOOK in dest: slack.send_message_to_slack(dest[const.SLACK_WEBHOOK], dest_name) if dest_floor == 2: logger.info(f'call facedetect to pepper({self.pepper_2_id}), dest_name={dest_name}, floor={dest_floor}') message = self.orion.send_cmd(self.pepper_2_id, self.type, 'facedetect', 'start') else: message = f'nothing to do, dest_name={dest_name}, floor={dest_floor}' logger.info(message) result['result'] = 'success' result['message'] = message except AttrDoesNotExist as e: logger.error(f'AttrDoesNotExist: {str(e)}') raise BadRequest(str(e)) except NGSIPayloadError as e: logger.error(f'NGSIPayloadError: {str(e)}') raise BadRequest(str(e)) except DestinationDoesNotExist as e: logger.error(f'DestinationDoesNotFound: {str(e)}') raise BadRequest(str(e)) except DestinationFormatError as e: logger.error(f'DestinationFormatError: {str(e)}') raise BadRequest(str(e)) except Exception as e: logger.exception(e) raise e return jsonify(result)
def post(self): content = request.data.decode('utf-8') logger.info(f'request content={content}') result = {'result': 'failure'} try: value = get_attr_value(content, 'state') if value == 'on': message = self.orion.send_cmd(self.pepper_1_id, self.type, 'welcome', 'start') result['result'] = 'success' result['message'] = message except AttrDoesNotExist as e: logger.error(f'AttrDoesNotExist: {str(e)}') raise BadRequest(str(e)) except NGSIPayloadError as e: logger.error(f'NGSIPayloadError: {str(e)}') raise BadRequest(str(e)) except Exception as e: logger.exception(e) raise e return jsonify(result)
def post(self): content = request.data.decode('utf-8') logger.info(f'request content={content}') result = {'result': 'failure'} try: robot_id = get_id(content) state = get_attr_value(content, 'r_state') message = self.orion.send_cmd(robot_id + const.TABLET_SUFFIX, self.type, 'state', state) result['result'] = 'success' result['message'] = message except AttrDoesNotExist as e: logger.error(f'AttrDoesNotExist: {str(e)}') raise BadRequest(str(e)) except NGSIPayloadError as e: logger.error(f'NGSIPayloadError: {str(e)}') raise BadRequest(str(e)) except Exception as e: logger.exception(e) raise e return jsonify(result)
def post(self): content = request.data.decode('utf-8') logger.info(f'request content={content}') result = {'result': 'failure'} try: destx = get_attr_value(content, 'destx') desty = get_attr_value(content, 'desty') visitor_id = get_attr_value(content, 'visitor_id') try: floor = int(get_attr_value(content, 'floor')) except (TypeError, ValueError): raise DestinationFormatError('dest_floor is invalid') if destx is not None and desty is not None and floor in ( 1, 2) and visitor_id is not None: robot_id = self.get_available_robot_from_floor(floor) current_state = self.orion.get_attrs( robot_id, 'r_state')['r_state']['value'].strip() if current_state != const.WAITING: message = f'cannot accept command at StartMovementAPI, current_state={current_state}, robot_id={robot_id} '\ f'destx={destx}, desty={desty}, floor={floor}, visitor_id={visitor_id}' logger.warning(message) result['result'] = 'not acceptable' result['message'] = message else: attributes = [{ 'name': 'r_state', 'value': const.GUIDING, }, { 'name': 'destx', 'value': destx, }, { 'name': 'desty', 'value': desty, }, { 'name': 'visitor', 'value': visitor_id, }] self.orion.update_attributes(robot_id, self.type, attributes) value = f'r_cmd|Navi|x|{destx}|y|{desty}' message = self.orion.send_cmd(robot_id, self.type, 'robot_request', value) result['result'] = 'success' result['message'] = message except AttrDoesNotExist as e: logger.error(f'AttrDoesNotExist: {str(e)}') raise BadRequest(str(e)) except NGSIPayloadError as e: logger.error(f'NGSIPayloadError: {str(e)}') raise BadRequest(str(e)) except DestinationFormatError as e: logger.error(f'DestinationFormatError: {str(e)}') raise BadRequest(str(e)) except Exception as e: logger.exception(e) raise e return jsonify(result)
def post(self): content = request.data.decode('utf-8') logger.info(f'request content={content}') result = {'result': 'ignore'} try: arrival = get_attr_value(content, 'arrival') if arrival is not None: id = get_id(content) destService = Destination() destination = destService.get_destination_by_dest_human_sensor_id( id) if destination is not None and const.DEST_FLOOR in destination: try: floor = int(destination[const.DEST_FLOOR]) except (TypeError, ValueError): raise DestinationFormatError('dest_floor is invalid') robot_id = self.get_available_robot_from_floor(floor) robot_attrs = self.robot_orion.get_attrs( robot_id, 'r_state,destx,desty') current_state = robot_attrs['r_state']['value'] try: destx = float(robot_attrs['destx']['value']) desty = float(robot_attrs['desty']['value']) except (TypeError, ValueError): destx = float('inf') desty = float('inf') if (current_state != const.SUSPENDING or destx != float(destination.get(const.DEST_POS_X)) or desty != float(destination.get(const.DEST_POS_Y))): message = f'cannot accept command at Arrival, current_state={current_state}, robot_id={robot_id}'\ f'destx={destx}, desty={desty}, floor={floor}' logger.warning(message) result['result'] = 'not acceptable' result['message'] = message else: if const.DEST_LED_ID in destination and destination[ const.DEST_LED_ID] is not None: dest_led_id = destination[const.DEST_LED_ID] self.dest_led_orion.send_cmd( dest_led_id, self.dest_led_type, 'action', 'off') initial = destService.get_initial_of_floor(floor) initial_pos_x = initial.get(const.DEST_POS_X) initial_pos_y = initial.get(const.DEST_POS_Y) if initial_pos_x is None or initial_pos_y is None: raise DestinationFormatError( 'initial dest_pos_x or dest_pos_y is empty') attributes = [{ 'name': 'r_state', 'value': const.RETURNING, }, { 'name': 'destx', 'value': '', }, { 'name': 'desty', 'value': '', }] self.robot_orion.update_attributes( robot_id, self.robot_type, attributes) value = f'r_cmd|Navi|x|{initial_pos_x}|y|{initial_pos_y}' message = self.robot_orion.send_cmd( robot_id, self.robot_type, 'robot_request', value) logger.info( f'guide_robot({robot_id}) return to the initial position of floor({floor})' ) result['result'] = 'success' result['message'] = message except AttrDoesNotExist as e: logger.error(f'AttrDoesNotExist: {str(e)}') raise BadRequest(str(e)) except NGSIPayloadError as e: logger.error(f'NGSIPayloadError: {str(e)}') raise BadRequest(str(e)) except DestinationFormatError as e: logger.error(f'DestinationFormatError: {str(e)}') raise BadRequest(str(e)) except Exception as e: logger.exception(e) raise e return jsonify(result)