{'fraction_non_alphanumeric': 0.03630226630846593, 'fraction_numerical': 0.008507267341737273, 'mean_word_length': 4.491772271609609, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Reactive Task and Motion Planning under Temporal Logic Specifications

We present a task-and-motion planning (TAMP) algorithm robust against a human operator's cooperative or adversarial interventions. Interventions often invalidate the current plan and require replanning on the fly. Replanning can be computationally expensive and often interrupts seamless task execution. We introduce a dynamically reconfigurable planning methodology with behavior tree-based control strategies toward reactive TAMP, which takes the advantage of previous plans and incremental graph search during temporal logic-based reactive synthesis. Our algorithm also shows efficient recovery functionalities that minimize the number of replanning steps. Finally, our algorithm produces a robust, efficient, and complete TAMP solution. Our experimental results show the algorithm results in superior manipulation performance in both simulated and real-world tasks.


I. INTRODUCTION
Consider the problem of collaborative operation between humans and robots [1]. A central challenge is responding in realtime to changes that might render the current robot task incomplete or inefficient. For example, we might like to ask a robot to "pack up all the objects into the box" as shown in Fig. 1. To achieve this complex goal, taskand-motion planning (TAMP) has been widely used for producing a sequence of actions [2]- [5]. During execution, a human partner might help the robot by packing up some of the objects or providing tools (e.g., a tray) to the robot. However, such changes may make the current plan invalid. The robot's plan might not have accounted for the new tool. Operating alongside human partners may require replanningand-execution on the fly.
A popular replanning-and-execution approach is reactive synthesis that finds control strategies to react to environmental model changes including object position [6]- [8], proposition [9], and uncertainty [10] while satisfying a given task specification [11], [12]. However, its reasoning process often requires the planner to construct a graph explicitly capturing feasible states (i.e., nodes) and edge connectivity between the states to find solutions. A wide range of model changes due to interventions leads to computationally expensive state-graph (re-)construction and search. Further, this graph reconstruction may lower execution efficiency, pausing ongoing motion until a new plan is reestablished. Fig. 1: A capture of our "3-block+tray" transfer task. Given a temporal logic-based goal specification F G(all obj in r 2 ), our UR5 robot produces a complete task-and-motion plan to transfer objects from r 1 to r 2 . When a human operator provides a movable tray r 3 , our system reactively synthesizes a new plan that utilizes r 3 to produce efficient (i.e., minimum-distance cost) behaviors. and also shows seamless execution using a behavior tree.
We propose a reactive TAMP method that hierarchically reacts to various levels of task interventions (e.g., the position changes of objects, addition/deletion of objects) by introducing complementary layers of planning and execution. The planning layer includes complete and efficient reactive synthesis using linear temporal logic (LTL) suitable to formally specify complex objectives and interventions [13]- [16]. In detail, the method produces a sequence of action plans combining symbolic and (joint space) motion-cost based geometric searches over the LTL automata. Given environmental changes, our first contribution is to show how to find a new plan with minimal search effort by incrementally expanding the search space and leveraging experience such as previously explored paths and corresponding costs.
For the execution layer, we propose a behavior tree (BT) that conditionally activates sub-control policies (i.e., subtrees) to reactively follow action plans from the planning layer. BTs have been widely used to handle new or partially updated policies, as well as environmental changes [17]- [19]. We use the modularity of BTs, which allows easier composition, addition, and deletion of policies on the fly, to partially update policies without pausing ongoing executions. Our second contribution is to show that the recovery strategies of conditional BTs [7], [20] can minimize expensive replanning steps with LTL. By relaxing the activation conditions of trees, we maximize the recovery range and minimize replanning requests given environment changes such as object relocation.
In this work, we consider a robot that conducts a pick-andplace task of multiple objects where a human operator either cooperatively or adversarially could move the same objects. The robot can recognize the unexpected changes only by observing the location of objects. We assume that the robot does not suffer from partial and uncertain observations in this work. We do not explicitly model the human as another agent but rather consider as a part of the environment. We show our robot is able to adaptively change its plan on the fly to complete a given task. The key contributions include: • We present a robust TAMP method that hierarchically reacts to various environment changes or new temporal logic specifications. • Our planning layer provides quickly replanned solutions based on past experience, online graph extension, and reconfigurable BT structures. • Our execution layer allows seamless plan execution even with environment changes and computation delays. • We demonstrate that our method outperforms various baselines in terms of time efficiency and motion costeffectiveness via physics-based simulations. We also conduct proof-of-concept experiments with a UR5 robot from Universal Robots.

II. TEMPORAL-LOGIC PLANNING
We present a brief introduction to the LTL planning framework (more details in [21]) and show how we define variables used in the framework.
The planning problem studied in this work is to move a set of objects from initial locations to desired goal locations while overcoming environmental changes that might occur unpredictably. To enable temporal reasoning and guarantee task completion, we adopt temporal logic-based planning to synthesize a plan for the robot that achieves LTL task specifications, owing to its correct-by-design nature.
We model the robot and its workspace as a transition system (TS), which can be defined as tuples as follows: where S is a finite set of states (s ∈ S), s 0 is an initial state, A is a set of actions, δ t : S × A → S is a deterministic transition relation, Π is a set of atomic propositions, and L : S → 2 Π is a labeling function that maps each state to a subset of atomic propositions that hold true.
We compose an object o i with a region r j to denote a state s in TS, i.e., s = o i r j , implying that the object o i is located in the region r j . Let O = {o 1 , ..., o n |o i ∈ R 3 } be the set of n prehensile object states exist in the workspace of the robot, where o i is the 3D positional vector of the i-th object. The objects are placed in m discrete and non-overlapping regions which we achieve by abstractly partitioning a continuous 3D workspace. We denote the set of m region states by R = {r 1 , ..., r m |r j ∈ R 3 }. The robot can observe which objects belong to which region through its perception. For multiple objects we represent a state s by splitting pairs of an object o i and region r j by underscore, e.g., s = o 1 r 1 o 2 r 3 . The cardinality of S is |R| |O| . An element of the action set A is represented by move o i r j that is to pick an object o i from its current location and place o i in region r j . An atomic proposition π ∈ Π corresponds to a state s ∈ S that is either true or false statements that must be specified for a given task. For example, π = o i r j is true if an object o i is in a region r j , or false otherwise. L maps a state s ∈ S to a set of true atomic propositions L(s) ⊆ Π.
An LTL formula ϕ is a combination of Boolean operators and temporal operators, which is involved with a set of atomic propositions (⊆ Π). The formula ϕ can express non-Markovian temporal properties, such as temporally-extended goals. The syntax of the formula ϕ over Π is as follows: where we denote π ∈ Π, "negation" (¬), "disjunction" (∨), "next" (X ), and "until" (U). We can additionally derive a Boolean operator "conjunction" (∧) and temporal operators "always" (G) and "eventually" (F) from the basic syntax. A detailed explanation can be found in [21]. A word is an infinite sequence of atomic propositions in Π defined over the alphabet 2 Π . There exists a union of inifinite words that satisfies a given formula ϕ. Alternatively, the nondeterministic Büchi automaton (BA) constructed according to [22] is generally used to check the satisfiability of ϕ.
where Q b is a finite set of states (q b ∈ Q b ); q b,0 is an initial state; Σ = 2 Π is an alphabet from the LTL formula; We then generate a product automaton (PA) by producting the TS and BA as follows.
PA becomes a search graph used for finding a plan. Finding a valid path that starts from an initial state (s 0 , q b,0 ) to one of accepting states (s F , q b,F ) where q b,F ∈ F b implies computing a feasible plan ξ = {(s i , q b,i )} i={0,1,...,F } that achieves a given formula ϕ.
We study a scenario where unexpected human intervention affects the state of objects. A human operator might add new objects, remove existing objects, or move an object to a different region. This is equivalent to keeping the LTL specification ϕ as it is while dynamically modifying the TS and PA to reflect the changes. Previous works also considered the same reactive approach as ours [9], [10], or relaxed the LTL specification ϕ instead while keeping the TS [23], [24] for handling the changes. However, they mostly focused on navigation tasks.
The objective in this work is that the robot places all objects O to desired goal regions among regions R. Although human intervention occurs unpredictably, the robot must be able to correct TS and adjust its plan to accomplish a given task. Besides robustness, we would like the proposed replanning algorithm to additionally exhibit time efficiency and completeness.

III. DYNAMICALLY RECONFIGURABLE PLANNING
We address the proposed problem by directly finding a plan over the PA that satisfies an LTL formula ϕ, i.e., placing all objects O in desired goal regions R. We achieve this by a hierarchical architecture (Fig. 2) that disentangles the highlevel planning from low-level motor control commands. We handle unexpected changes by human intervention in upper layers of the architecture.
The entire proposed hierarchical architecture consists of three layers: (1) The high-level planning layer computes a high-level plan that satisfies LTL specifications; (2) The middle-level execution layer dynamically constructs BT to make high-level plans executable for low-level controller of the robot; and (3) The low-level layer outputs control inputs used in actuators. The inputs to the architecture are a robot model, information about workspace, and LTL specifications ϕ and the ouput is low-level control inputs. Additional inputs are environmental changes that can be detected via perception. Three desirable properties we aim at are robustness (against intervention), efficiency (in computing a plan), and completeness. We achieve robustness efficiently by (1) handling intervention without involving the expensive task planner and only calling the planner when necessary; (2) reusing partial plans from the past; (3) computing a cost-effective plan by incorporating a motion cost computed by inverse kinematics; and (4) maintaining a partial graph of PA. We achieve completeness by employing an LTL-based planning.
In Section III-A, we present the capability of each component in our system and the pseudo-code of the framework. In Section III-B, we introduce the search algorithm with motion cost to achieve a cost-effective solution. In Section III-C, we present two ways of speeding up the search algorithms: reusing partial plans and maintaining a partial graph of PA.
In Section III-D, we explain the BT reconstruction in detail.

A. Robust Hierarchical System Design
In this subsection, we highlight which component of the hierarchical structure deals with which environmental changes. These components are in charge of different replanning queries that arrive at random time, including search graph construction and experience-based graph search in the highlevel layer, and BT in the middle-level layer. In particular, we consider the following types of environmental changes: object relocation while previous plans are feasible or infeasible, and the addition and removal of objects and regions. Note again that the change in an LTL formula ϕ is not considered.
The process of the system handling environmental changes is illustrated in Alg. 1. In line 5, when the object is relocated to one of existing regions, there are cases where the previous plans can be reused if the plans have been reserved as subtrees in the BT (details are explained in Section III-D). In particular, if there are still executable subtrees (line 6), the expensive task planner will not be queried. For example, as shown in Fig. 1, if the robot fails to pick up a block due to perception error, the BT will re-activate specific subtrees to attempt to grasp the block again.
Object relocation could also occur where previous plans are no longer feasible. To handle this case, our system will use the same graph (skipping line 13) and query a search algorithm to produce a new plan (line 16). Particularly, the search algorithm (Section III-B) improves its planning efficiency by reusing the planning experiences computed and cached from the previous queries and maintaining a partial graph (Section III-C). The BT will then receive the new plan and add/delete subtrees while keeping reusable subtrees for execution (line 17) (Section III-D).
When the number of objects and that of regions change, our system will reconstruct the TS and PA (line 13) before querying the experience-based graph search for planning (line 16) and send the new plan to the BT for execution (line 17) (Section III-D).

B. Planning for LTL specifications
We use a weighted directed graph G = (V, E, w) to represent the PA and deploy a graph search algorithm for planning. In particular, each q p ∈ Q p corresponds to a node v ∈ V . For each q p and q p where q p ∈ δ p (q p ), there is an edge e ∈ E between the nodes associated with q p and q p .
We incorporate the notion of motion cost into the PA as a weight w on an edge e of G. We compute the motion cost as the incremental displacement of a robot's end effector, which can be obtained from a skill library assumed to be given. For example, when a manipulator approaches some location, the motion cost can be computed by inverse kinematics and saved as one of skills in the library. This allows for cost-effective plans with respect to a cumulative motion cost.
To increase the planning efficiency, we propose two improvements over general graph search algorithms: (1) leveraging the computations from the past to reduce the computation in motion costs for a new replanning query; and (2) constructing G on the fly to avoid the overhead of generating a graph from scratch whenever the world changes.

C. Search Acceleration
We attempt to speed up the search algorithm by reusing previous plans and partially constructing a search graph. When searching for a path in G, computing a motion cost on edge is costly as it requires solving an inverse kinematics problem. We cache the motion cost of edges newly explored so far as well as corresponding node names as a table data structure. If a new plan during replanning visits a node that has been previously visited, we look up the motion cost table to avoid inverse kinematics recomputation. Reusing previous plans expedites the search as environmental changes often affect only a small part of G.
Graph reconstruction is computationally expensive when the number of objects and that of regions vary. The complexity of fully reconstructing the PA grows exponentially as the number of new objects increases. The cardinality of Q p is |S|×|Q b | where |S| = |R| |O| . To fully construct the graph G, the program needs to check for valid transitions for all pairs ∀q p , q p ∈ Q p , which results in O(|Q p | 2 ) = O(|R| 2|O| |Q b | 2 ). Our system constructs G on the fly within the search (Alg. 1 line 16) to reduce this overhead, rather than fully constructing it before the search. With an admissible heuristic, our system can avoid expanding all v ∈ V and avoid constructing the entire G while finding the same path when heuristics are not used. In particular, within the search algorithm (line 16), when a node associated with q p is chosen to be expanded, the system will query δ p to produce the list of next states {q p } = δ p (q p ) and add them to V and E accordingly. In the worst case, if the heuristic is not effective at all, all nodes in V will be expanded, and G will be fully constructed. We call this approach partial graph construction. We show the efficiency of partial graph construction against the approach of fully constructing G every time before the search (full graph construction) in Section V.

D. Behavior Tree & Reconfiguration
The BT is a compositional decision-making system that can group a set of behaviors, execute between groups at a fixed frequency, and change the structure on the fly. The execution starts from the root of the BT. It then gradually traverses the execution permission (the tick) from the root to child nodes. Once a node receives the tick, the node execution returns: 1) SUCCESS if the node execution was successfully completed, 2) RUNNING if the execution is not completed yet, 3) FAILURE if the execution was failed, and 4) INVALID otherwise. Fig. 3 shows the execution flow given a sequence of action plans, where → and ? represent sequence and selector behaviors, respectively (see details in [25]). There are previous works [24], [26], [27] adopting both the LTL and BT for synthesizing controls from high-level plans. However, their methods cannot deal with environmental changes studied in this work.
We now describe how to build the internal structure of the BT given a high-level plan and reconfigure it on the fly. 1) Automatic tree construction: We convert a sequence of action plans P to a sequence of subtrees Ψ, which can be attached to the task root of a BT. Similar to the planning domain description language (PDDL [28]), we use preconditions and effects to achieve complex sequences of behaviors similar to [20], [27]. To build the tree, we parse a plan P into a sequence of action tuples T = {(A 1 , C 1 pre , C 1 post ), (A 2 , C 2 pre , C 2 post ), ...}, where A i , C i pre , and C i post represent an action, a pre-condition, and a postcondition, respectively. For example, given two consecutive states (o 1 r 1 o 2 r 1 , o 1 r 2 o 2 r 1 ), the action is o 1 's move from r 1 to r 2 , where C pre = {o 1 r 1 , o 2 r 1 } and C post = {o 1 r 2 , o 2 r 1 }.
We then convert the tuple to a state condition-based subtree as shown in Fig. 3a, where C R represents a set of running conditions (e.g., o 1 r hand o 2 r 1 ) from [7] and the State Update decorator forces the current state to be updated after the Algorithm 2: BT Reconfiguration. P i A and Ψ i A represent the action name of the i-th action tuple and subtree, respectively. Likewise, P and A with the subscript C represent their preconditions. The superscript −i accesses the ith element from last.
Output: Ψ 1 P ← (P 1 , ..., P n ) // A seq. of action Remove subtrees at Ψ j:−i Remove ∀s ∈ Ψ 1:|Ψ|−n 15 end completion of an action. Note that C i post equals to C i+1 pre in this sequential plan so that we can ignore post conditions. This structure can also re-execute the previous actions if the current state satisfies the precondition. However, the statebased condition may be too conservative in that a full state specification cannot ignore unrelated environmental changes.
Alternatively, we introduce a relaxed version of subtree constructor, the action condition-based subtree (see Fig. 3b), that is designed to prevent unnecessary replanning given unrelated or minor environmental changes such as object additions, deletions, and repositions. The subtree also allows more recovery behaviors. In particular, the precondition node checks soft conditions including the location of the target object, object source, and object destination (e.g., C pre = o 1 r 1 ). We also use a customized selector, called chooser [25], as a root of each subtree that is to prevent interruption from higher priority of sibling subtrees. This enables BT to complete an ongoing action.
2) Online reconfiguration: We introduce how we can reconfigure a BT without interfering with running tasks (i.e., running subtrees) on the fly. Given environmental changes, the planner will produce a new plan P , which may not be completely different from the previous plan P so it is not necessary to reconstruct a sequence of subtrees S from scratch. Alg. 2 shows how we can find sharable subtrees between P and P from the back. If there is a new action in P , we add a new subtree to S. Otherwise, we remove the unmatched subtrees. Note that if there are any running and non-interruptible subtrees, our framework postpones the change of the subtree until the return of the subtree is changed.

IV. EXPERIMENTAL SETUP A. Statistical Evaluation
We evaluated our method with baselines on two environment settings in a physics-based simulator, GAZEBO (Ver. 7) [29]. The manipulation settings were composed of colored blocks, trays, and/or baskets (see Fig. 5). Given an LTL specification, ϕ = FG(all obj in r 2 ), our method generated a plan for transferring all blocks from r 1 to r 2 . Note that other LTL specifications can also be handled in our framework. Per each method and setting, we created 30 test scenarios by randomly placing objects in the beginning and then introduced an additional environmental change, such as repositioning, adding, or deleting a randomly selected object at a random time. Descriptions of each scenario and setting are as follow: 1) In the 3-block scenario, as shown in Fig.  5(a), there are three blocks initially located at r 1 . The desired plan is to move each block one after another from r 1 to r 2 . 2) In the 3-block + tray scenario, as shown in Fig. 5(b), there are three blocks initially located at r 1 and a movable tray r 3 near r 1 . The optimal plan is to transfer all the blocks to r 3 first, move r 3 near r 2 , and then relocate blocks from r 3 to r 2 . By leveraging r 3 , the robot can reduce the total motion costs of transferring blocks from r 1 to r 2 .

B. Demonstration Setup
We demonstrated the proposed method on two manipulation scenarios of a real UR5 robot (see Fig. 5). The robot observed objects using an Intel D435 RGB-D camera mounted on the wrist. It first recognized object segments by using Detectron2 [30] with Mask R-CNN [31] from Facebook, where we trained Detectron2 images collected from similar settings after labeling it via COCO Annotator [32]. The segments were then used for estimating the 3D pose and grasping point of each object from the depth image. Here, we assumed there are unique colors of objects to assign unique ID. An operator randomly relocated, added, or removed objects including a tray during the experiment.

V. RESULTS
We benchmarked our method against a set of baselines and demonstrated its robustness and efficiency via simulations. To show the performance of the execution layer, we compared three variations of the BT: online reconfiguration with action condition, online reconfiguration with state condition, and offline reconstruction with action condition over two scenarios. Note that the offline reconstruction stops a running node to remove all subtrees. It then constructs a new tree from scratch in an idle mode. Fig. 4 shows the online reconfiguration with action condition resulted in a smaller number of BT changes and took less completion time compared with that of (a) A "3-block" transfer task. An operator added and then repositioned objects during the task.
(b) A "3-block + tray" task. An operator provided a movable tray during the task. On the other hand, the offline reconstruction incurred longer average completion time than online BT. Overall, the results demonstrate that the online BT reconfiguration with action condition is the most efficient among the variations.
We benchmarked three search algorithms, A * with experience, A * , and Dijkstra, in the 3-block + tray scenario, each with three types of environmental changes (repositioning, adding, or deleting a block). We split all planning processes in each trial into (1) initial planning in the very beginning and (2) replannings, used for intervention handling. Table I highlights the robustness and efficiency of our hierarchical system. The column "# replan" presents that both means and medians of the number of replannings for object repositions are lower than those for additions and deletions across all algorithms. This result demonstrates that the system's efficiency in handling repositions by using the BT alone without the expensive replanning unless necessary. The mean of the number of replannings for object reposition is non-zero because sometimes it is necessary to replan. For example, if o i is repositioned to r 1 when r 3 is near r 2 , since the state o i r 1 r 3 r 2 is not in the optimal initial plan, no subtrees in BT can handle this case alone wihtout replanning. Table I highlights the efficiency of the experience-based search. A * with experience leverages the similarity between the initial plan and the plans for intervention handling. In Table I, A * with experience has a significantly lower total replanning time than A * and Dijkstra among all types of environmental changes. The initial planning time is almost the same across three algorithms due to a lack of experience in the very beginning. To demonstrate the overall efficiency, we report the completion time of each trial. Among all types of environmental changes, A * with experience achieves significantly shorter completion time due to faster replanning. The success rate is always 100% in Table I   (A * with planning experiences, A * , and Dijkstra), with partial graph construction, in handling 3 types of environmental changes (relocating 1 object, removing 1 object, and adding 1 object). The metrics used here are number of successes/number of trials, initial planning time (95% confidence interval (CI)), total replanning time (95% CI), number of replannings (mean, median), and completion time (95% CI).
over the full graph construction through simulations. We measured the time taken for both constructing the PA and replanning when an object was added as environmental changes for efficiency comparison. We fixed the number of regions to be five while varying the number of objects from two to six, resulting in the number of states in the PA to vary from 50 to 31, 250. We randomly generated locations of regions ten times. Fig. 6 shows the mean and the standard deviation of a total time measured over ten random environments for both graph construction methods. The full graph construction performed comparably with the partial graph construction up to 1, 250 states but started degrading exponentially afterward. We finally demonstrated the proposed TAMP method with a real UR5 robot. Fig. 5 shows captures of two representative intervention scenarios. Given the same LTL specification, our robot successfully initiated a complete task and motion plan to transfer all objects to another storage by visually recognizing the environment. When an operator added and relocated objects, the online BT enabled the robot to continue seamless task execution while replanning the new setup. The proposed graph construction and experience-based planning enabled the robot quickly to transition to a new plan. Given a new transfer tool (see Fig. 5b), our system could also show cost-effective behaviors by utilizing the tray as we humans do. These demonstrations show our framework enables the robot to achieve robust and efficient high-level planning and middle-level execution in human-robot operation scenarios.

VI. DISCUSSION & CONCLUSION
We introduce a hierachically reactive TAMP method, which generates a complete and semi-optimal task plan by using LTL and approximated motion costs. Our framework provides an efficient replanning approach leveraging experience-based graph search and node modification algorithms. In addition, to minimize the replanning and also maximize the recovery control capability, we combine it with a dynamically reconfigurable BT with the action condition subtree structure. Our statistical evaluation shows the superial efficiency compared to other baseline methods. We also demonstrate the robustness in real world with a UR5 robot.