betfsm.Fallback

Bases: GeneratorWithList

Implements a behaviortree-like Fallback node
  • executes a child and if it is a failure, continues with the next child. Otherwise it returns the outcome of the child that did not fail. If all children fail it returns CANCEL.
  • definition of failure can be overridden using callback but by default is corresponds to a CANCEL outcome. The failure callback can not only depend on the outcome but also on some information in the blackboard

There is a method add_state to add underlying nodes to the Fallback node, these are executed in order.

If any node succeeds, this outcome is directly returned; if a node returns TICKING, the fallback node returns TICKING; and if the node returns CANCEL, the execution of the next node in the list is started (without any intermediate tick!).

stateDiagram-v2 classDef successClass fill:darkgreen,color:white classDef tickingClass fill:yellow,color:black classDef otherClass fill:darkorange,color:white classDef abortClass fill:darkred,color:white [*] --> Loop Loop --> state_1 : current_state==1 Loop --> state_2 : current_state==2 Loop --> CANCEL : last state failed state_1 --> Loop : CANCEL state_2 --> Loop : CANCEL state_1 --> TICKING : TICKING state_2 --> TICKING : TICKING state_1 --> OTHER : OTHER outcome state_2 --> OTHER : OTHER outcome class SUCCEED successClass class OTHER otherClass class TICKING tickingClass class CANCEL abortClass

__init__(name, children=[], failure=lambda bb, outc: outc == CANCEL)

Parameters:
  • name (str) –

    name of the sequence

  • children (List[TickingState], default: [] ) –

    a list of states you can use add_state(...) to add children.

  • failure (Callable[[Dict, str], bool], default: lambda bb, outc: outc == CANCEL ) –

    This callback defines what a failure is, can use blackboard or outcome. A callback with signature: def failure(bb:Blackboard,outcome:str)->bool

warning

The failure callback should also take into account TICKING outcomes.