betfsm.TickingState

Implements a 'ticking' state, i.e. a state that takes a longer time, but cooperatively yields the initiative back to the caller (cooperative concurrency):

stateDiagram-v2 direction LR classDef successClass fill:darkgreen,color:white classDef tickingClass fill:yellow,color:black classDef otherClass fill:darkorange,color:white classDef abortClass fill:darkred,color:white classDef centerClass text-align:center entry --> doo : returns <br>CONTINUE or TICK doo --> exit : returns not TICK doo --> doo: returns<br>TICK entry -->exit: returns <br>not TICK or CONTINUE exit --> entry : exit() finished <br> or reset() called doo --> exit : reset() called entry: calls entry()<br>if TICK return TICK<br>if exception return ABORT doo: calls doo()<br> if TICK return TICK <br>if exception return ABORT exit: calls exit()<br> return outcome<br>if exception return ABORT class entry centerClass
note

You can choose whether to tick between entry() and doo() by letting entry() return CONTINUE

note

exit() is always called when execute is called for the last time, even when there are exceptions.

note

expects the following methods to be overridden by subclases:

  • entry()
  • doo()
  • exit()
  • reset() (but call super().reset() )
warning

use is similar to State, but if it returns TICKING, it is expected to be called again, if not, the user needs to call reset() before using the state again.

__init__(name, outcomes)

Parameters:
  • name (str) –

    name of the TickingState. This is meant to be an instance-name, not a class-name. if equal to None, one will be generated from class name and sequence number.

  • outcomes (List[str]) –

    all possible outcomes of the state, TICKING and ABORT will be added.

accept(visitor)

calls the visitor with itself and possibly iterates over its children.

See also

Visitor

doo(blackboard)

is repeatedly called after the first time execute() is called.

Parameters:
  • blackboard (Blackboard) –
Returns:
  • str

    A string with value: TICKING (execute will return and next time will call doo() );

  • str

    OTHER string (execute will call immediately exit(), i.e. without a tick )

Note

if this throws an exception, outcome=ABORT and and exit() is called immediately If one likes more detailed behavior, doo needs to catch the exception itself.

entry(blackboard)

called the first time execute() is called.

Parameters:
  • blackboard (Blackboard) –
Returns:
  • str

    A string with value: CONTINUE (execute will call directly doo() ); TICKING (execute will return and next time will call doo() ); OTHER string ( exit() will be immediately called, without a tick)

Note

can raise exception, equivalent to returning ABORT. In that case exit() is called. If one likes more detailed behavior, entry needs to catch the exception itself.

exit()

method that is always called when execute is called the last time

Returns:
  • str

    A string the outcome (next time execute will call entry() )

Note

method has no blackboard parameter, since it could be called from reset() which does not and should not know the blackboard parameter.

Warning

can't raise an exception!

get_global_registry() classmethod

A log where nodes are only added, a single publisher can periodically erase all nodes from this log. This allows to capture all notes that where active during a period. This is only done when it is turned on by assigning an empty dict to global_publish_log

reset()

External reset of the TickingState to its initial condition. Subclasses should also reset all the children of themselves exit() is called when appropriate