  Robots working in real environments need to adapt to unexpected changes to
avoid failures. This is an open and complex challenge that requires robots to
timely predict and identify the causes of failures to prevent them. In this
paper, we present a causal method that will enable robots to predict when
errors are likely to occur and prevent them from happening by executing a
corrective action. First, we propose a causal-based method to detect the
cause-effect relationships between task executions and their consequences by
learning a causal Bayesian network (BN). The obtained model is transferred from
simulated data to real scenarios to demonstrate the robustness and
generalization of the obtained models. Based on the causal BN, the robot can
predict if and why the executed action will succeed or not in its current
state. Then, we introduce a novel method that finds the closest state
alternatives through a contrastive Breadth-First-Search if the current action
was predicted to fail. We evaluate our approach for the problem of stacking
cubes in two cases; a) single stacks (stacking one cube) and; b) multiple
stacks (stacking three cubes). In the single-stack case, our method was able to
reduce the error rate by 97%. We also show that our approach can scale to
capture multiple actions in one model, allowing to measure timely shifted
action effects, such as the impact of an imprecise stack of the first cube on
the stacking success of the third cube. For these complex situations, our model
was able to prevent around 75% of the stacking errors, even for the challenging
multiple-stack scenario. Thus, demonstrating that our method is able to
explain, predict, and prevent execution failures, which even scales to complex
scenarios that require an understanding of how the action history impacts
future actions.
