ros_sugar.core.fallbacks#

Fallbacks

Module Contents#

Classes#

Fallback

Fallback action and execution tracking

ComponentFallbacks

Components Fallbacks contain the set of Actions to be executed when a failure status is detected (See Status class). Fallbacks are defines with an Action or a list of Actions to be executed in order. Each Action in the list is retried until max_retries is reached.

API#

class ros_sugar.core.fallbacks.Fallback#

Fallback action and execution tracking

reset_current_idx()#

Reset the current action index to zero

reset_retries()#

Reset the current retries index to zero

reset()#

Reset the current action and the retries index to zero

class ros_sugar.core.fallbacks.ComponentFallbacks(on_any_fail: Optional[ros_sugar.core.fallbacks.Fallback] = None, on_component_fail: Optional[ros_sugar.core.fallbacks.Fallback] = None, on_algorithm_fail: Optional[ros_sugar.core.fallbacks.Fallback] = None, on_system_fail: Optional[ros_sugar.core.fallbacks.Fallback] = None, on_giveup: Optional[ros_sugar.core.fallbacks.Fallback] = None)#

Components Fallbacks contain the set of Actions to be executed when a failure status is detected (See Status class). Fallbacks are defines with an Action or a list of Actions to be executed in order. Each Action in the list is retried until max_retries is reached.

Default behavior in a Component:

The default behavior in a Component is for the component to broadcast the status on any detected failure. By default the component sets ‘on_any_fail’ Fallback to ‘Action(self.broadcast_status)’ with ‘max_retries=None’.

Action(s) set for ‘on_any_fail’ is executed for any failure for which no fallback action is defined.

Usage in a Component:

    from ros_sugar.component import BaseComponent
    from ros_sugar.action import Action

    my_component = BaseComponent(node_name='test_component')

    # Set fallback for component failure to restart the component
    my_component.on_component_fail(fallback=Action(my_component.restart))

    # Change fallback for any failure
    my_component.on_fail(fallback=Action(my_component.restart))

    # First broadcast status, if another failure happens -> restart
    my_component.on_fail(fallback=[Action(my_component.broadcast_status), Action(my_component.restart)])
property giveup: bool#

Getter of component giveup, True if no more fallbacks are available for a type of failure

Returns:

Giveup

Return type:

bool

reset() None#

Reset all fallback execution tracking indices to 0 and the retries tracking indices to 0

reset_execution_indices() None#

Reset all fallback execution tracking indices to 0

reset_retries()#

Reset all fallback retries tracking indices to 0

execute_giveup()#

Execute the component giveup method when all fallbacks fail

execute_component_fallback() bool#

Execute the next component fallback method for component failure

Returns:

Giveup: If no more fallbacks are available to be executed

Return type:

bool

execute_algorithm_fallback() bool#

Execute the next algorithm fallback method for algorithm failure

Returns:

Giveup: If no more fallbacks are available to be executed

Return type:

bool

execute_system_fallback() bool#

Execute the next system fallback method for system failure

Returns:

Giveup: If no more fallbacks are available to be executed

Return type:

bool

execute_generic_fallback() bool#

Execute the next algorithm fallback method for any failure

Returns:

Giveup: If no more fallbacks are available to be executed

Return type:

bool