# Category Theory for Autonomous Robots: The Marathon 2 Use Case

Esther Aguado, Virgilio Gómez, Miguel Hernando, Claudio Rossi and Ricardo Sanz

( Universidad Politécnica de Madrid, Autonomous Systems Laboratory
and Center for Automation and Robotics; c/ José Gutierrez Abascal 2, 28006
Madrid, Spain
{e.aguado, virgilio.gomez.lambo, miguel.hernando, claudio.rossi,
<EMAIL_ADDRESS>
###### Abstract

Model-based systems engineering (MBSE) is a methodology that exploits system
representation during the entire system life-cycle. The use of formal models
has gained momentum in robotics engineering over the past few years. Models
play a crucial role in robot design; they serve as the basis for achieving
holistic properties, such as functional reliability or adaptive resilience,
and facilitate the automated production of modules. We propose the use of
formal conceptualizations beyond the engineering phase, providing accurate
models that can be leveraged at runtime. This paper explores the use of
Category Theory, a mathematical framework for describing abstractions, as a
formal language to produce such robot models. To showcase its practical
application, we present a concrete example based on the Marathon 2 experiment.
Here, we illustrate the potential of formalizing systems—including their
recovery mechanisms—which allows engineers to design more trustworthy
autonomous robots. This, in turn, enhances their dependability and
performance.

##  1 Introduction

Autonomous robot engineering constitutes a major challenge in system
development—design, construction, assurance, operation—due to their complexity
in both hardware/software and operational environments. Their construction
requires well-orchestrated and knowledge-intensive engineering processes that
can benefit from rigorous _Systems Engineering_ (SE) practices. Having a
suitable technology to develop _system models_ is a major step in solving this
challenge.

We use models to abstract and manage system complexity. Model-based systems
engineering (MBSE) is a semi-formalized methodology that exploits a system
representation with reduced detail so that its structure and behavior can be
managed. MBSE provides support for requirement definition, design, analysis,
verification, and validation throughout the entire life-cycle of intricate
systems.

Of all the aspects of the system, a highly critical one is _system
architecture_ [5], because it affects and even determines most of the
properties of the system. MBSE modeling of system architectures is a
cornerstone of reliable system construction. There are languages that support
MBSE, such as AADL [9] or SysML [22], which facilitate the definition,
communication, and maintenance of system models. These languages are typically
used to document and reason about the properties of the system and its
consistency. However, when systems are deployed in unpredictable environments,
it is hard to ensure its behavior at the development time.

We propose the use of _Category Theory_ (CT) as a framework to support system
modeling and behavioral analysis for complex Systems of Systems (SoS). CT is a
general theory of mathematical structures. It was invented in the 1940s to
unify and synthesize different areas in mathematics [30]. It can be seen as a
tool set for describing general structures and maintaining control over which
aspects are preserved when performing abstractions. Moreover, its mathematical
foundation enables powerful communication between apparently unrelated fields.

Our motivation is based on the difficulties in addressing the reality gap
between robot usage in a controlled environment and its deployment in open,
real-world scenarios. We aim to address dependability using robust models at
runtime as a tool to better understand the situation and react properly in
unstructured environments. In this article, we draw a landscape of how CT can
be used for this purpose. In particular, the main contributions are as
follows.

  * •

A brief guide on how to use CT to design systems,

  * •

its application to a state-of-the-art mobile robot, and

  * •

a discussion on the benefits of using CT in robotics.

Beyond this introduction, the paper is organized as follows. Section 2
addresses the description of some fundamental CT elements that can add value
in robotic engineering processes. Section 3 describes some related work on
applied CT in domains of close interest for roboticists—databases, knowledge
management, hierarchical systems, robotics, etc. Section 4 describes a
concrete use case: the Marathon 2 experiment on autonomous mobile robots in
real social environments. Section 5 describes the use of CT in the Marathon 2
use case. Finally, Section 6 discusses the potential use of CT in the modeling
of robotic systems in an MBSE context. The paper ends with some conclusions,
acknowledgments, and references.

##  2 Category Theory Concepts for Robotics

In this Section we define the specific language we will use to our CT-based
system model. CT allows us to be completely precise about otherwise informal
concepts [14]. We start with some basic elements to represent structures and
evolve them into more general formalisms, _operads_. Lastly, we introduce the
concept of _pushout_ , which provides a method to condense and combine data
from pre-existing structures.

Note that this introduction is just a basic description for robotics; for
further reading, refer to [16, 15, 2] from a mathematical perspective, [4]
from a computer science perspective, and [30, 11] for a scientific application
perspective with a strong mathematical flavor.

###  2.1 Basis: Category, Functor, and Natural Transformation

A _category_ $\mathcal{C}$, is a collection of elements with relations between
them. It constitutes an aggregation of objects with an imposed structure [19].
To specify a category, we need three constituents:

  * •

A collection of _objects_ , $\mathrm{Ob}(\mathcal{C})$,

  * •

a collection of _morphisms_ $f:X\to Y$, for every pair of objects
$X,Y\in\mathrm{Ob}(\mathcal{C})$, and

  * •

a _composition_ operation $g\circ f:X\to Z$ composing morphisms $f:X\to Y$ and
$g:Y\to Z$.

Additionally, categories must satisfy the following conditions:

  * •

identity: for every object $X\in\mathrm{Ob}(\mathcal{C})$, exists an identity
morphism $id_{X}:X\to X$.

  * •

associativity: for any three morphisms, $f:X\to Y$, $g:Y\to Z$, $h:Z\to W$,
the following expressions are equal: $(h\circ g)\circ f=h\circ(g\circ
f)=h\circ g\circ f$

  * •

unitality: for any morphism $f:X\to Y$, the composition with the identity
morphisms at each object does not affect the result, $id_{X}\circ f=f$ and
$f\circ id_{Y}=f$.

A simple example is the Set category, in which objects are sets, morphisms are
functions between sets, and a composition operation is the composition between
its functions.

A _functor_ $F$, is a map between two categories $\mathcal{C}$, $\mathcal{D}$.
It assigns objects to objects and morphisms to morphisms, preserving
identities and composition properties. Functors preserve structures when
projecting one category inside another.

Functors can map between the same types of category, such as
${\textbf{{Set}}}\to{\textbf{{Set}}}$, or between different categories, such
as ${\textbf{{Set}}}\to{\textbf{{Vect}}}$, between the category of sets and
the category of vector spaces.

A _natural transformation_ $\alpha$, is a structure-preserving mapping between
functors. Functors project images of a category inside another; whereas
natural transformations shift the projection defined by a functor $F$ into the
projection defined by a functor $G$. Diagram 1 relates these three concepts.
There are two categories $\mathcal{C},\mathcal{D}$ and two different functors
$F,G:\mathcal{C}\to\mathcal{D}$. The two functors are linked by the natural
transformation $\alpha:F\Rightarrow G$.

${\mathcal{C}}$${\mathcal{D}}$$\scriptstyle\mathrm{F}$$\scriptstyle G$$\alpha$
(1)

To specify a natural transformation, we define a morphism $\alpha_{c}:F(c)\to
G(c)$ for each object $c\in\mathcal{C}$, such that for every morphism $f:c\to
d$ in $\mathcal{C}$ the composition rule $\alpha_{d}\circ
F(f)=G(f)\circ\alpha_{c}$ holds. This condition is often expressed as the
commutative diagram shown in Diagram 2, where the natural transformation
morphisms are represented as dashed arrows. This means that the projection of
$\mathcal{C}$ in $\mathcal{D}$ through $F$ can be transformed into projections
through $G$. The commutative condition implies that the order in which we
apply the transformation does not matter.

${F(c)}$${G(c)}$${F(d)}$${G(d)}$$\scriptstyle{F(f)}$$\scriptstyle{\alpha_{c}}$$\scriptstyle{G(f)}$$\scriptstyle{\alpha_{d}}$
(2)

###  2.2 Representing Resources: Wiring Diagrams

Fong and Spivak [11] define wiring diagrams as an answer to the question “Can
I transform what I have into what I want?” Wiring diagrams constitute a CT-
formalization of engineering block diagrams. In these diagrams, boxes
represent transformations (i.e. morphisms in a category), wires represent
resources (i.e. objects in a category), and two boxes in series are the result
of composing morphisms.

In the broad sense, wiring diagrams depict monoidal categories
$(\mathcal{C},\otimes,\\{1\\})$, which are categories $\mathcal{C}$ equipped
with a tensor product $\otimes$ and a monoidal unit $\\{1\\}$ that allows the
combination of objects in the category. This structure provides a rationale to
place boxes in parallel in the diagram. Lastly, symmetric monoidal categories
(SMC) and its respective coherence conditions support the use of feedback
wires and swapping in these diagrams. A precise definition of wiring diagrams
can be found in [15] and [28].

###  2.3 Representing Networks: Operads and Algebras

Categories, functors, and natural transformations are the building blocks of
CT. They allow us to express objects, relationships among them, and
abstractions while preserving their structure. This approach imposes some
directionality since morphisms, functors, and natural transformations are maps
with a domain and a co-domain. From an engineering perspective, we could see
domains and co-domains as input and output ports, respectively. However, we
sometimes prefer to express systems in terms of networks in which ports exit
without a direction. CT provides a generalization over categories, operads, to
model assemblies of structures.

An _operad_ is a mathematical object that describes operations with multiple
inputs and one output [34]; classically, it only describes one object. We use
here what are commonly known as colored operads, which can hold many objects
(i.e. colors). Leinster [17] provides a precise definition of operads. An
operad consists of:

  * •

a set of objects $\mathrm{Ob}(\mathcal{O})=X_{1},\ldots,X_{n}$ each of which
can be seen as cells,

  * •

a set of morphisms $\varphi,\psi,\ldots$ that constitute the operations and
act as an assembly of cell interfaces creating an external interface, and

  * •

a composition formula $\circ$ or substitution, that enables the assembly of
morphisms, i.e. the composition of interfaces.

Operads allow us to define abstract operations, but we need to “fill” those
cells to ground them. An _algebra_ is an operad functor from the operad to the
Set category, $F:\mathcal{O}\to{\textbf{{Set}}}$ that produces a concrete
realization. It is subject to the operations and composition relations
specified by the operad. In practice, an algebra determines:

  * •

for any object, $x\in\mathcal{O}$, a set $F(x)$,

  * •

for any morphism in the operad, $f:(x_{1},\ldots,x_{n})\to y$ and for any
element $f_{i}\in F(x)$, a new object $f^{\prime}=F(f)(f_{1},\ldots,f_{n})\in
F(y)$.

Different algebras allow us to “fill” the operad structure from different
perspectives and then combine them using a morphism between algebras
$\delta:A\to B$. In Section 5, _we propose two algebras, structure and
behavior, for the system operad_. These algebras can be seen as the semantics
of the syntax established in the operad.

###  2.4 Combining information: Pushouts

So far we have introduced the machinery to focus on roles and structure via
categories and operads. In this work, our aim is to use abstractions to build
the best possible system for each situation. Pushouts serve as a valuable tool
in this process as they provide the best approximation of an object in a
category that satisfies certain conditions.

_Pushouts_ can be seen as a way to combine two objects in a category with a
common object so that all information is preserved. For example, in a category
$\mathcal{C}$ with three sets as objects, $X,Y,A\in\mathrm{Ob}(\mathcal{C})$,
we can have a set $A$ representing three robots,
$A=\\{robot\\_1,robot\\_2,robot\\_3\\}$, a set $X$ representing robot
grippers, $X=\\{finger\\_gripper,\\\ vacuum\\_gripper\\}$, and a set $Y$
representing the maximum speed (m/s) in wheeled robots, $Y=\\{1.5,3\\}$. There
are two morphisms in our category, $f:A\to X$ assigning $robot\\_1$ a maximum
speed of $1.5$ m/s and $robot\\_2$ a maximum speed of $3$ m/s; and morphism
$g:A\to Y$ assigning $robot\\_2$ to the $three\\_fingers\\_gripper$ and
$robot\\_3$ to the $vacuum\\_gripper$.

The pushout $X_{+A}Y$ can be seen as the summary of objects and its
relationships, in a Set category, a non-disjoint union. In this case, a set
$X_{+A}Y=\\{robot\\_1\\_speed\\_1.5,robot\\_2\\_$
$speed\\_3\\_and\\_finger\\_gripper,robot\\_3\\_vacuum\\_gripper\\}$ and its
corresponding morphisms to sets $X,Y$. Note that objects connected by
morphisms are seen as the same element, i.e. the same system made up of
subsystems $X,Y,A$.

Pushouts are usually expressed as Diagram 3 in which $f^{\prime},g^{\prime}$
are the pushout morphisms that respectively link $Y,X$ with the pushout object
$X_{+A}Y$. If this diagram commutes, i.e. $g^{\prime}\circ f=f^{\prime}\circ
g$, there exists a unique morphism $u:X_{+A}Y\to T$ such that Diagram 4 also
commutes. The dashed arrow represents the unique morphism, and the element $T$
represents the unique pushout object. $l_{x},l_{y}$ constitute the validity
limits of $T$ [18].

${A}$${Y}$${X}$${X_{+A}Y}$$\scriptstyle{g}$$\scriptstyle{f}$$\scriptstyle{f^{\prime}}$$\scriptstyle{g^{\prime}}$
(3)

${A}$${Y}$${X}$${X_{+A}Y}$${T}$$\scriptstyle{g}$$\scriptstyle{f}$$\scriptstyle{f^{\prime}}$$\scriptstyle{l_{y}}$$\scriptstyle{g^{\prime}}$$\scriptstyle{l_{x}}$$\scriptstyle{u}$
(4)

##  3 Related Work

CT has proven to be a powerful tool for abstract reasoning about mathematical
structures. However, it is still not as widely used in applied scenarios as
other mathematical disciplines, such as linear algebra or calculus. The main
reasons could be that it is a too specialized and abstract field, with a steep
learning curve, and the community. Besides its main uses in mathematics, it is
applied in computer science and software engineering; mainly to identify
commonalities and patterns across different domains. A notable contribution is
its use in the design and implementation of the C++ Standard Template Library
[32].

In recent years, the number of fields that implement CT-based approaches has
increased. In knowledge representation, Spivak [29] proposes the ontology log,
_olog_ , a CT-formalism similar to relational database schemas. It provides a
friendly definition language and supports safe data migration [31]. Aligned
with this approach, Patterson [24] introduces a relational ontology, which
seeks to bring ologs closer to description logics. These works rely on
categories, functors, and natural transformations and use pushouts to combine
information and generate new concepts from old ones.

From the robotics perspective, Censi [7] introduces the theory of co-design to
optimize multi-objective systems. Zardini [35] applies interconnected co-
design problems to a self-driving car. This approach applies wiring diagrams
to optimize resource allocation in the design phase.

Perhaps the vision of Lloyd is more in line with our work. Lloyd [19] suggests
the use of CT language and theory to study systems and reflexes on its
implications. Its domain application is biological sciences. In [18], he
provides a CT-centered approach to model and simulate the emergent properties
of intercellular interaction.

Like us, Bakirtzis [3] studies the unification of requirements, behaviors, and
architectures for complex systems. He proposes the use of wiring diagrams as
an alternative to engineering modeling languages such as SysML and provides a
grounding example on an unmanned aerial vehicle. Its perspective on
_contracted behaviors_ , which composes behaviors and requirements through an
algebra, has inspired our recovery model introduced in Section 5.3. The main
limitation of this approach is the directionality imposed by wiring diagrams.

The generalization provided by operads appears to be a better structure to
model complex systems. Schweiker et al. [27] propose the application of wiring
diagrams operad to model safe critical systems. In particular, they establish
viewpoints with a sound mathematical framework in which behaviors and error
propagation can be assessed from different perspectives. This model is applied
to evaluate the failure effects of air traffic management communication
channels on aircraft control. Our approach is based on the same abstract
construction, the operad of wiring diagrams, as fundamental structure for the
system model.

Breiner et al. [6] offer another perspective on using operads to model
systems. It uses the separation of concerns provided by operads to analyze a
length calibration device, the length scale interferometer (LSI), used at the
US National Institute of Standards and Technology (NIST). They model the
system interfaces as a port graph operad. Then, they use a functor between the
system and the probability of failure to perform the failure diagnosis. Foley
et al. [10] examine operad-based problem modeling from two angles. It takes a
top-down modeling approach using wiring diagrams operad to analyze the LSI
case from [6], and a down-top perspective using network operad to design a
search and rescue architecture and its design mission task plan.

These works show that CT is seen as a tool to increase the dependability and
explainability of the system, which is a major concern in any technology-
centered domain. The growing number of publications suggests the potential of
CT for practical use. However, there are still challenges in bridging the
abstraction provided by CT and the concrete implementation in real-world
scenarios. In this work, we try to take a step in that direction, defining a
model that can be used both at the design phase and during robot operation.

##  4 The Marathon 2 Use Case

The Marathon 2 experiment [20] proposes a guidance, navigation, and control
(GNC) solution for mobile robots, which has become a widely adopted stack for
handling perception, mapping, localization, path planning, and control. This
software, known as _Nav2_ , provides a design pattern that seeks modularity,
flexibility, and extensibility. Section 5 models the system deployed in this
experiment using CT.

The described experiment intends to cover a distance greater than a marathon
without human assistance. Specifically, a robot shall traverse 16 waypoints
several times in a university setup. In operation, the robot faced
difficulties such as human crowds and navigation around complex areas such as
a central staircase, a high-traffic bridge, a hallway, and a narrow doorway.

The robots used in the experiments, a Tiago [23] and a RB-1 [25] have similar
base dimensions and their speed was limited to 0.45 m/s for safety reasons,
which is below their maximum speed. They use differential steering on a
circular base, as required by the implementation of the Adaptive Monte Carlo
Localization (AMCL) [12] and the A∗ planner [13]. These robots use a laser and
a depth camera as the main sensors.

Figure 1 depicts the Marathon 2 architecture. It enables a mobile robot to
autonomously reach a goal state, such as a specific position and orientation
relative to a specific map. It takes as input a map, a goal pose, and the
current pose, and provides velocity commands to drive the robot. In the
experiments, the goal pose was the sequence of 16 waypoints. The software
relies on a behavior tree (BT) [8] to provide flexibility and adaptability to
perform the task. In this case, it coordinates (i) guidance through a path
planner to find the best route to the goal pose, (ii) navigation based on AMCL
for state estimation, and (iii) a controller to compute the path and local
information to generate a precise velocity control signal. Additionally, it
provides a recovery server to solve runtime contingencies.

Figure 1: Marathon 2 software architecture. ROS topics are depicted in bold
and starts with a “$\setminus$” symbol. The gray boxes are the main elements:
mission server, map server, robot and Nav2. The Nav2 subsystem is further
decomposed into the white boxes: state estimator or navigator, path planner or
guidance, and controller. Note that the path planner, the controller and the
Nav2 boxes have a diamond shape in the corner with an “R” representing that
exists available recovery actions for such subsystems.

###  4.1 Recoveries in Marathon 2

Marathon 2 uses ad-hoc solutions to handle contingencies. Recovery actions
depend on the specific failing component and the data it manages. As shown in
Figure 1, Marathon 2 provides recoveries for the path planner, the controller,
and the entire Nav2 subsystem. Nav2 logic uses a BT to orchestrate the
execution of tasks. Recoveries are encoded as BT fallbacks, triggered when the
specific task fails. In particular, (i) when the system cannot generate a
plan, it clears the global map used by the path planner; (ii) when the
controller fails to determine a suitable velocity, it clears the corresponding
area in the environmental model (i.e. local map); and (iii) when the whole GNC
process fails, it first clears the entire environmental model, then spins the
robot in place to reorient local obstacles, and ultimately waits a timeout.

Macenski et al. [20] identified two primary scenarios that triggered recovery
behaviors in the robot. The first scenario involved crowded spaces where the
robot was unable to compute a clear path to its destination. If the _clear map
recovery_ approach failed and the path was obstructed by people, the robot
used _wait recovery_ , which paused navigation until the path was clear. The
second scenario occurred when localization confidence was low, particularly in
long corridors with repetitive features and many people. In these cases, the
_spin recovery_ approach—in which the robot spins in place—was used to improve
the confidence in position before resuming its task.

While these ad-hoc recovery approaches did utilize the knowledge and
experience of engineers in dealing with contingencies, they lacked the ability
to provide a clear rationale for the robot’s actions. As a result, the
reasoning behind these approaches remained solely in the minds of the
engineers. This lack of transparency can give rise to concerns about the
reliability of the system, as a particular recovery approach may not be
appropriate for a given situation or may even adversely affect a properly
functioning subsystem. For example, the planner recovery approach, which
clears the global map, can propagate to the local map utilized by the
faultless controller.

##  5 CT-model for the Marathon 2

In this Section, we formalize the Marathon 2 use case in a model based on CT
with three intentions: (i) provide a formal model of the system with a strong
mathematical foundation, (ii) represent all valid equivalent designs, and
(iii) exploit that model at runtime, i.e. implement sound model-based
recoveries.

###  5.1 System model

Operads offer an effective modeling procedure for hierarchical structures. We
base our model on the wiring diagram operad, $\mathcal{W}$, similar to the
wiring diagram operad for dynamical systems explicitly defined in [33]. Our
building blocks, i.e. operad objects, are boxes $x\in\mathrm{Ob}(\mathcal{W})$
with two types of interface: resources required and resources provided. The
operad morphisms $\varphi,\psi,\ldots$ represent which composite interfaces
can be produced out of atomic ones, as explained in Section 2.2. The
composition formula $\circ$ ensures that morphisms can be composed creating
higher-level structures in terms of resources.

In Section 2.3 we claim that operads define abstract operations, they act as
“placeholders” to create a theory of composition [30]. We use algebras to
define the “fillings”, the concrete elements that provide and consume
resources. In robotics, those resources can be seen from three perspectives
(i) capability, (ii) structure, and (iii) behavior. Each viewpoint constitutes
an algebra, a way to provide meaning to the abstract structure.

####  5.1.1 Capability model

Capability refers to the “potential” ability of a system, i.e. what it is
intended to do to satisfy a need. Its algebra,
$C:\mathcal{W}\to{\textbf{{Set}}}$, gives meaning to resources in terms of
needs. In particular, the capability algebra produces an instance of a Set
category in which:

  * •

For every object $x\in\mathrm{Ob}(\mathcal{W})$, the set $C(x)$ is the set of
capabilities that provides and consumes resources from $x$.

  * •

For every morphism in the operad $f:(x_{1},\ldots,x_{n})\to y$ and for every
choice of capability $c_{1}\in C(x_{1}),\ldots,c_{n}\in C(x_{n})$ it creates a
composed capability $c^{\prime}=C(f)(c_{1},\ldots c_{n})\in C(y)$.

Figure 2 displays the main capabilities of the Marathon 2 system. The operad
structure is represented as boxes, the capability model is composed of two
interconnected cells corresponding to the physical interaction and the
computation of motion to reach the point. The mission specification and the
environmental perceptible features are external capabilities consumed by the
system but depicted for completeness.

Figure 2: Capability model of the Marathon 2 system. Atomic capabilities in
white boxes, composed capabilities in gray boxes. Lines in black represent
links between atomic capabilities and dotted blue lines, links between
composed capabilities.

####  5.1.2 Structural model

Structure represents the logical arrangement of components—hardware or
software—and its interactions. It defines the system, its composing
subsystems, and its connections. The structural algebra
$S:\mathcal{O}\to{\textbf{{Set}}}$, gives meaning to the subsystems required
to transform resources. In particular, the structural algebra produces an
instance of a Set category in which:

  * •

For every object $x\in\mathrm{Ob}(\mathcal{W})$, the set $S(x)$ is the set of
subsystems that provide and consume resources from $x$.

  * •

For every morphism in the operad $f:(x_{1},\ldots,x_{n})\to y$ and for every
choice of subsystem $s_{1}\in S(x_{1}),\ldots,s_{n}\in S(x_{n})$ it creates a
system out of subsystems $s^{\prime}=S(f)(s_{1},\ldots s_{n})\in S(y)$.

In the Marathon 2 system, the structural model consists of the robot and the
GNC subsystem. Its hierarchical decomposition is shown in Figure 3. The operad
structure is represented as boxes, the structural model is composed of two
interconnected cells corresponding to the sensor/actuator subsystem and the
Nav2 subsystem. The mission server and model map are external subsystems
providing resources to Marathon 2, they are depicted for completeness.

Figure 3: Structural model of the Marathon 2 system. Atomic subsystems in
white boxes, composed subsystems—i.e. system of system—in gray boxes. Lines in
black represent links between atomic subsystems and dotted blue lines, links
between composed subsystems.

####  5.1.3 Behavioral model

Behavior is generally understood as the visible actions of a system in
reaction to certain inputs, conditions, or stimuli. The behavioral algebra
$B:\mathcal{O}\to{\textbf{{Set}}}$, gives meaning to the information
flow—exchanged resources—and the resulting actions from the execution of robot
commands. In particular, the behavioral algebra produces an instance of a Set
category in which:

  * •

For every object $x\in\mathrm{Ob}(\mathcal{W})$, the set $B(x)$ is the set of
behaviors that provides and consumes resources—information pieces—from $x$.

  * •

For every morphism in the operad $f:(x_{1},\ldots,x_{n})\to y$ and for every
choice of behavior $b_{1}\in B(x_{1}),\ldots,b_{n}\in B(x_{n})$ it creates a
composed behavior, $b^{\prime}=B(f)(b_{1},\ldots b_{n})\in B(y)$.

A behavioral model specifies the actual response of the system in a particular
situation; unlike our previous models, in which the system emerges from the
combination of elements. In the behavioral model, this combination must also
occur in the right order. Wiring diagrams are the most extended formalism for
expressing the direction of resource consumption in SMC, as defined in Section
2.2. The behavior algebra produces a finite Set category, which constitutes an
SMC [30], so it can be expressed as a wiring diagram similar to the Nav2
subsystem in Figure 1. The behavioral Marathon 2 is a wiring diagram that has
(i) as boxes the concrete algorithms used according to [20], A∗ planner, an
AMCL state estimator, and a TEB controller, and (ii) as wires the ROS topics
depicted in bold in Figure 1. The composite behavior takes as input a map of
the environment and a goal position and drives the robot there.

###  5.2 Specification of a design

A system design provides the resulting conceptualization that satisfies the
three previously defined models. Figure 4 represents the relationship between
the three concepts. Capability models refine the needs that the system must
satisfy. These capabilities define requirements at different granularity.
Structural and behavioral models propose solutions to meet its corresponding
requirements. Solutions satisfying the three models provide the set of valid
designs. Eventually, the “best valid design” alternative is the one to be
realized.

Figure 4: Relation between capability, structural and behavioral model with
requirements. These models are used to establish the best valid system design.

This process can be seen as a pushout $Structure\leftarrow Capability\to
Behavior$ with requirements $SR,BR$ as morphisms between capabilities and
structure or behavior. As shown in Diagram 5, designs are a combination of
both. If the diagram commutes, it means that it is equivalent to creating a
design that first satisfies behavioral requirements and then structural ones,
or vice versa. In this case, there exists a unique pushout object, known as
_realization_. The realization shall be the unique design that maximizes the
capabilities of the system. In most systems, this is the design that maximizes
behavioral performance and minimizes structural cost. For this reason, the
pushout limits of validity are $max\\_perf,min\\_cost$.

${Capability}$${Structure}$${Behavior}$${Designs}$${Realization}$$\scriptstyle{SR}$$\scriptstyle{BR}$$\scriptstyle{BR^{\prime}}$$\scriptstyle{min\\_cost}$$\scriptstyle{SR^{\prime}}$$\scriptstyle{max\\_perf}$$\scriptstyle{u}$
(5)

###  5.3 CT-Model-based Recoveries

Models shall be used throughout the system life-cycle. We propose the use of
CT-models at runtime to reconfigure the system and increase its resiliency.
Today, most subsystems have specific recovery actions to ensure proper
operation at the component level. However, to fully address the open issues in
dependability, the system must be aware of these atomic recoveries and how
they affect other components and its shared resources. CT provides the formal
framework for mapping between components and behaviors.

During robot deployment, changes in the environment or system contingencies
may cause that the best designed realization is no longer valid. In this case,
we propose a functor mapping to generate new _valid_ structural and behavioral
models. These new models then evolve into a _recovered_ realization.

From a CT perspective, there is a functor $\delta:S\to B$ to establish the map
between structure-Set category and behavior-Set category resulting from its
corresponding algebras. When a contingency arises, there is an alternative
mapping $\delta^{\prime}:S^{\prime}\to B^{\prime}$ with the recovery changes
applied. Diagram 6 expresses a natural transformation as defined in Section
2.1. There are two maps $\delta,\delta^{\prime}$ between the realization
category and the realization category _recovered_. The natural transformation
$\alpha$ relates these two maps.

${Realization}$${Realization^{\prime}}$$\scriptstyle\mathrm{\delta}$$\scriptstyle\delta^{\prime}$$\alpha$
(6)

The implications of the natural transformation are decomposed in Diagram 7. A
valid recovery is the one that makes this diagram commute.

${S(r)}$${S(r^{\prime})}$${B(r)}$${B(r^{\prime})}$$\scriptstyle{\delta}$$\scriptstyle{\alpha_{str}}$$\scriptstyle{\delta^{\prime}}$$\scriptstyle{\alpha_{beh}}$
(7)

Marathon 2 recoveries described in Section 4.1 deal with crowded environments
and lack of localization confidence. According to our CT model, this affects
the behavioral model. For example, when the planner cannot compute a path
because the map is “full of obstacles”, no component is damaged. However, the
solution to this recovery, clearing the global map, may affect the local map
model and the controller component. In this case, a change in the behavioral
model $\alpha_{beh}$ produces a recovered structure model $S(r^{\prime})$
through the map $d^{\prime opp}$ that sends behaviors to structures.

Another possible contingency is a failure in the laser sensor; in this case,
its functionality can be provided by an alternative component, such as the
depth camera. In this scenario, the system requires an additional element to
transform the point cloud output produced by the depth camera into a laser
scan message. Therefore, a contingency in the structural model affects the
behavior of the system by changing the information flow. According to Diagram
7, a change in the structural model $\alpha_{str}$ produces a recovered
behavioral model $B(r^{\prime})$ through the map $\delta^{\prime}$.

##  6 Discussion on CT-driven System Modeling

System models constitute a vehicle for the realization of systems. They can be
used throughout its entire life-cycle; for example, to define requirements,
establish a design, analyze it, and verify and validate it. Formalisms can
help engineers—and the robot itself—identify potential problems, examine
complex systems, and communicate ideas with others in a clear and unambiguous
way. Moreover, they provide consistency and systematization to increase the
reusability of the model. As CT is “the language” of abstract mathematics, it
becomes the perfect approach to represent systems at different levels of
abstraction.

Applied CT has become an increasingly attractive field, as evidenced by the
notable growth in publications and research. Although it has a steep learning
curve, it can be smoothed out with practitioners and collaborations across
domains. The main concern when CT is applied in robotics is the lack of tool
support. There is a framework under development, _Catlab_
111https://github.com/AlgebraicJulia/Catlab.jl, for applied and computational
CT written in the Julia language. However, we believe that CT models can be
seen as meta-models that provide a robust formal foundation to OWL ontologies,
widely used in robotics [21]. To operationalize them, we shall produce user-
friendly interfaces for developers to ease the use of CT models in applied
domains.

There are several potential research directions that could be pursued in this
area. On the one hand, examine other paradigmatic use-cases in robotics from
the CT perspective can be a powerful way to refine model abstractions and show
practitioners the value of this approach. The EU-funded ROBOMINERS and
CORESENSE projects try to do this. Another promising approach could be the
application of the discrete-time process operad formalism [26], to model and
analyze system dynamics.

In our case, our next actions will be (i) measure the impact of CT model
exploitation in terms of how it affects robot performance and mission
fulfillment in real-world scenarios, which we have already addressed from the
ontological perspective [1]; and (ii) extend the model to other activities in
the system life-cycle, such as mission specification, performance metrics,
testing, _etc_. These concepts can be used for validation using compositional
viewpoint equations, as suggested by [27, 6].

##  7 Conclusions

In this article, we propose the use of formal abstract theories—Category
Theory—for modeling in robotics. We suggest an approach to help system
engineers in the initial phases of understanding CT. Furthermore, we
illustrate how these formal tools can provide a systematic approach to
addressing the situations that a system engineer may encounter. This is of
special importance when building robust and adaptive robots that are systems
of extreme complexity.

Following this approach, we subsequently apply the proposed concepts to model
the adaptive robot experiment outlined in [20]. This system serves as a
fundamental yet impactful use case of the _Nav2_ stack, widely extended to
control mobile robots within the ROS community.

The formal conceptualization goes beyond the engineering phases and endows
robots with tools for better understanding of situations, which is a powerful
asset towards achieving robustness and resiliency. We propose an approach to
leverage explicit engineering knowledge during robot operation, which enhances
the robot’s dependability. In particular, we model system recoveries as (i)
functorial mappings between system realizations, and (ii) natural
transformations between structural and behavioral models.

However, there are still many open issues with respect to a full use of CT
models in robotic systems. The two main problems that we shall confront are
the steep learning curve of these methods, and the lack of engineering-grade
tool support. We contemplate the potential use of these formalizations as
ontological meta-models, widely used in robotics nowadays. In future work, we
aim to extend this model-based approach to other aspects of the robot system
life-cycle.

In conclusion, we believe that the steps shown in this article toward
formalizing designs and its recoveries are a promising method to enhance robot
autonomy. If we have learned something from the past of science and
technology, is that effective scientific conceptualizations of real-world
phenomena open enormous possibilities for new technology.

## ACKNOWLEDGMENTS

This work was partially supported by the ROBOMINERS project with funding from
the European Union’s Horizon 2020 Research and Innovation Programme (Grant
Agreement No. 820971), by the CORESENSE project with funding from the European
Union’s Horizon Europe Research and Innovation Programme (Grant Agreement No.
101070254), and by a grant from Programa Propio of Universidad Politécnica de
Madrid.

## References

  * [1] E. Aguado, Z. Milosevic, C. Hernández, R. Sanz, M. Garzon, D. Bozhinoski, and C. Rossi.  Functional self-awareness and metacontrol for underwater robot autonomy.  Sensors, 21(4):1–28, 2021.
  * [2] S. Awodey.  Category Theory.  Oxford Logic Guides. Oxford: Oxford University Press, 2 ed. edition, 2010\.
  * [3] G. Bakirtzis, C. H. Fleming, and C. Vasilakopoulou.  Categorical semantics of cyber-physical systems theory.  ACM Trans. Cyber-Phys. Syst., 5(3), jul 2021.
  * [4] M. Barr and C. Wells.  Category Theory for Computing Science.  Prentice-Hall International series in Computer Science. Prentice Hall, 1990.
  * [5] L. Bass, P. Clements, and R. Kazman.  Software Architecture in Practice, 4th Edition.  Addison-Wesley Professional, 2021.
  * [6] S. Breiner, B. Pollard, E. Subrahmanian, and O. Marie-Rose.  Modeling hierarchical system with operads.  Electronic Proceedings in Theoretical Computer Science, 323:72–83, sep 2020.
  * [7] A. Censi.  A mathematical theory of co-design.  ArXiv, 2015.
  * [8] M. Colledanchise and P. Ögren.  Behavior Trees in Robotics and AI.  CRC Press, jul 2018.
  * [9] P. Feiler, D. Gluch, and J. Hudak.  The Architecture Analysis & Design Language (AADL): An Introduction.  Technical Report CMU/SEI-2006-TN-011, Software Engineering Institute, Carnegie Mellon University, Pittsburgh, PA, 02 2006.
  * [10] J. D. Foley, S. Breiner, E. Subrahmanian, and J. M. Dusel.  Operads for complex system design specification, analysis and synthesis.  Proceedings of the Royal Society A: Mathematical, Physical and Engineering Sciences, 477(2250):20210099, 2021.
  * [11] B. Fong and D. I. Spivak.  Seven Sketches in Compositionality: An Invitation to Applied Category Theory.  Cambridge University Press, 2019.
  * [12] D. Fox.  Kld-sampling: Adaptive particle filters.  In T. Dietterich, S. Becker, and Z. Ghahramani, editors, Advances in Neural Information Processing Systems, volume 14. MIT Press, 2001\.
  * [13] K. Konolige.  A gradient method for realtime robot control.  In Proceedings. 2000 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS 2000) (Cat. No.00CH37113), volume 1, pages 639–646 vol.1, 2000.
  * [14] D. Kozen, C. Kreitz, and E. Richter.  Automating proofs in category theory.  In U. Furbach and N. Shankar, editors, Automated Reasoning, pages 392–407, Berlin, Heidelberg, 2006. Springer Berlin Heidelberg.
  * [15] S. M. Lane.  Categories for the Working Mathematician.  Graduate Texts in Mathematics. Springer New York, NY, 1998.
  * [16] F. Lawvere and S. Schanuel.  Conceptual Mathematics: A First Introduction to Categories.  Cambridge University Press, 1997.
  * [17] T. Leinster.  Higher Operads, Higher Categories.  London Mathematical Society Lecture Note Series. Cambridge University Press, 2004.
  * [18] K. A. Lloyd.  A category-theoretic approach to agent-based modeling and simulation.  Technical report, Watt Systems Technologies Inc., 2010.
  * [19] K. A. Lloyd.  Category theoretic foundations for systems science and engineering.  In G. S. Metcalf, K. Kijima, and H. Deguchi, editors, Handbook of Systems Sciences, pages 1227–1249. Springer Singapore, Singapore, 2021.
  * [20] S. Macenski, F. Martín, R. White, and J. Ginés Clavero.  The marathon 2: A navigation system.  In 2020 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), 2020.
  * [21] A. Olivares-Alarcos, D. Beßler, A. Khamis, P. Goncalves, M. Habib, J. Bermejo-Alonso, M. Barreto, M. Diab, J. Rosell, J. Quintas, J. Olszewska, H. Nakawala, E. Pignaton, A. Gyrard, S. Borgo, G. Alenyà, M. Beetz, and H. Li.  A review and comparison of ontology-based approaches to robot autonomy.  Knowledge Engineering Review, 2019.  cited By 32.
  * [22] OMG.  Systems Modeling Language (OMG SysML) version 1.6.  OMG Specification formal/2019-11-01, Object Management Group, 2019.
  * [23] PAL Robotics.  Tiago mobile manipulator.  http://pal-robotics.com/robots/tiago/.  Accessed on February 25, 2023.
  * [24] E. Patterson.  Knowledge representation in bicategories of relations.  ArXiv, 2017.
  * [25] Robotnik.  RB-1 mobile manipulator.  https://robotnik.eu/products/mobile-manipulators/rb-1/.  Accessed on February 25, 2023.
  * [26] D. Rupel and D. I. Spivak.  The operad of temporal wiring diagrams: formalizing a graphical language for discrete-time processes, 2013.
  * [27] K. S. Schweiker, S. Varadarajan, D. I. Spivak, P. Schultz, R. Wisnesky, and P. Marco.  Operadic analysis of distributed systems.  Technical report, NASA Center for AeroSpace Information, 2015.
  * [28] P. Selinger.  A survey of graphical languages for monoidal categories.  In New Structures for Physics, pages 289–355. Springer Berlin Heidelberg, 2010.
  * [29] D. I. Spivak.  Ologs: A categorical framework for knowledge representation.  PLoS ONE 7(1): e24274, 2012.
  * [30] D. I. Spivak.  Category Theory for the Sciences.  The MIT Press, 2014.
  * [31] D. I. Spivak and R. Wisnesky.  Relational foundations for functorial data migration.  In Proceedings of the 15th Symposium on Database Programming Languages, DBPL 2015, page 21–28, New York, NY, USA, 2015. Association for Computing Machinery.
  * [32] A. Stepanov and D. Rose.  From Mathematics to Generic Programming.  Pearson Education, 2014.
  * [33] D. Vagner, D. I. Spivak, and E. Lerman.  Algebras of open dynamical systems on the operad of wiring diagrams, 2014\.
  * [34] D. Yau.  Operads of Wiring Diagrams.  Springer International Publishing, 2018.
  * [35] G. Zardini, D. Milojevic, A. Censi, and E. Frazzoli.  Co-design of embodied intelligence: A structured approach.  In 2021 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), pages 7536–7543, 2021.