A common approach in robotics for navigation- and perception-heavy tasks is to use a global behavior tree that describes the robot’s actions in different situations. This architecture, as shown in Figure 1, is used here to describe and execute the cleaning strategy. The Py Trees for ROS python package is used to implement a behaviour tree due to its high level of documentation, aswell as native support in ROS 2.

The behavior tree provides a hierarchical approach for coordinating navigation, perception, and cleaning actions. It also provides a clear structure for debugging. As seen in Figure 1, the robot first explores the environment, then pauses its coverage task whenever an object is detected, approaches the object, checks whether it is still visible, picks it up, and places it in the appropriate basket.
Input: Coverage segments , planner type
Output: Task result (success / cancelled / stopped)
sortByLength(, descending)
,
While :
dequeue(),
nav2.goThroughPoses(toROSPath())
Repeat until nav2.isTaskComplete():
nav2.getFeedback()
publishFeedback(, , .remainingPoses)
If cancelRequested: nav2.cancelTask(), return CANCELLED
If stopRequested: nav2.cancelTask(), return STOPPED
If pauseRequested:
nav2.cancelTask()
computeRemainingSegment(, getRobotPos())
prepend to (resume from current pose)
Repeat until pauseRequested: spinOnce()
nav2.goThroughPoses(toROSPath())
publishFeedback(, , 0)
Return SUCCESS