# On Managing Knowledge for MAPE-K Loops in Self-Adaptive Robotics Using a Graph-Based Runtime Model
## 5 Implementation
### Software Architecture  
The instantiation of our system architecture in the intralogistics scenario is shown in Figure 6. In the Monitor step we have three major modules involved. The NavigationAgent is responsible for annotating in the DSR information related to the navigation and localisation framework. In this step, the information is related with the battery level and also with the presence of close obstacles, reaching a goal, or bumping with an obstacle. The PersonDetectionAgent and the ContainerDetectionAgent are in charge of annotating in the DSR the presence and location of people and roll containers, respectively. The framework was built using \"You Only Look Once\" (YOLO v3) and included within a Neural Compute Stick 2 (VPU from Intel), using the OpenVINO framework. For dealing with both tasks, images were captured using the Intel Realsense camera mounted in the robot. Figure 5: The CARY robot approaches to a roll container, picks it up, and moves the container towards a new destination. The Analyze step consists of three relevant modules. The ContextProviderAgent is the responsible of collecting information about the context from the DSR, fuzzying it, and providing these topics to a first fuzzy inference engine implemented in the FuzzyEngine. This engine generates high-level metrics related with non-functional properties (safety, mission_completion or power_autonomy), and has been designed using the FuzzyLite Libraries for Fuzzy Logic Control [27]. In the FuzzyEngine, a second inference engine uses these metrics, and the temporal evolution of the state of the world, for quantifying the relevance of the collection of tentative actions that the robot can perform (e.g., abort the mission and move to the Charging station). The weights associated to each tentative action is updated in the DSR by the RecommenderAgent. Having taken the temporal evolution of these weights into consideration, the AdaptationAgent is the responsible for triggering a change in the course of action. To achieve this, this agent is linked to the decision makers. When the current action is stopped for executing a new one, it is the responsibility of the DSR update to maintaining the coordination among agents. At the Planning step, the course of action is mainly encoded in the CARY robot using the Global Management BT, responsible for the robot behaviour at a mission-level, and the PickUp Management BT, which allows the system to monitor the detection of the roll container and to autonomously move the robot to an alternative pose if the initial procedure fails. The Goal Management BT manages the requests of the human pickers, but it is possible, for instance, to abort a mission if the power autonomy is quickly decreasing or if the situation is unsafe. The modules in charge of executing these BTs are endowed within the BehaviourTreeAgent and the PickingBehaviourTreeAgent, respectively. These BTs are designed using the BehaviourTree.CPP library by [PERSON] [28]. Both BTs implement a nominal course of action (i.e., the set of actions sequentially performed by the robot in a normal execution) as their main branch. These nominal behaviours are then extended with alternative ones (identified at design-time), appearing as additional branches in the BT (see Figure 7). At runtime, the course of action is modified when required in response to the commands provided by the AdaptationAgent [26]. Figure 6: Software architecture for managing the CARY robot. In our case, the actuation of the robot is restricted to navigation commands (move to), pallet truck commands (raising and lowering the pallet truck), and interaction commands (warning messages that a mission has been completed or aborted). As shown in Figure 6, in addition to the interaction through the PickerWebInterface, the Execution part considers three modules. The aforementioned NavigationAgent is also responsible for managing the commands related to robot's motion.