ros_sugar.core.action#

Actions

Module Contents#

Classes#

Action

Actions are used by Components and by the Launcher to execute specific methods.

LogInfo

Overrides the LogInfo Action for ros2 launch to change the hard-codded logger name

API#

class ros_sugar.core.action.Action(method: Callable, args: tuple = (), kwargs: Optional[Dict] = None)#

Actions are used by Components and by the Launcher to execute specific methods.

Actions can either be:

  • Actions paired with Events: in this case the Action is executed by a Launcher when an event is detected

  • Actions paired with Fallbacks: in this case the Action is executed by a Component when a failure is detected

Actions are defined with:

  • method (Callable)

  • args: Arguments to be passed to the method when executing the action

  • kwargs: Keyword arguments to be passed to the method when executing the action

Usage Example:

    from ros_sugar.component import BaseComponent
    from ros_sugar.config import BaseComponentConfig

    def function():
        print("I am executing action!")

    my_component = BaseComponent(node_name='test_component')
    new_config = BaseComponentConfig(loop_rate=50.0)
    action1 = Action(method=my_component.start)
    action2 = Action(method=my_component.reconfigure, args=(new_config, True)),)
    action3 = Action(method=function)
event_parser(method: callable, output_mapping: Optional[str] = None, **new_kwargs)#

Add an event parser to the action. This method will be executed before the main action executable. The returned value from the method will be passed to the action executable as a ketword argument using output_mapping

Parameters:
  • method (callable) – Method to be executed before the main action executable

  • output_mapping (Optional[str], optional) – keyword argument name to pass the parser returned value to the action main method, defaults to None

property executable#

Get the action callable

Returns:

description

Return type:

type

property args#

Getter of action arguments

Returns:

description

Return type:

type

property kwargs#

Getter of action keyword arguments

Returns:

description

Return type:

type

property parent_component#

Getter of parent component class name if it is a component action, else None

Returns:

description

Return type:

str | None

property action_name: str#

Getter of the action name Equals exact executable name if it is not a component action Equals method name in the component if it is a component action

Returns:

description

Return type:

str

property component_action: bool#

component_action.

Return type:

bool

property dictionary: Dict#

Property to get/set the event using a dictionary

Returns:

Event description dictionary

Return type:

Dict

property json: str#

Property to get/set the event using a json

Returns:

Event description dictionary as json

Return type:

str

launch_action(monitor_node: Optional[ros_sugar.core.node.BaseNode] = None) Union[launch.actions.OpaqueCoroutine, launch.actions.OpaqueFunction]#

Get the ros launch action

Returns:

description

Return type:

OpaqueCoroutine | OpaqueFunction

class ros_sugar.core.action.LogInfo(*, msg: str, logger_name: Optional[str] = None, **kwargs)#

Bases: launch.actions.LogInfo

Overrides the LogInfo Action for ros2 launch to change the hard-codded logger name

Parameters:

LogInfoROSAction (LogInfoROSAction) – Action that logs a message when executed

execute(context: launch.LaunchContext) None#

Execute the action.