ros_sugar.actions

Component-level Actions:

These actions operate directly on Sugarcoat BaseComponent instances to manage lifecycle, configuration, or intrinsic interfaces.

  • start

  • stop

  • restart

  • reconfigure

  • update_parameter

  • update_parameters

  • trigger_component_service

  • send_component_service_request

  • trigger_component_action_server

  • send_component_action_server_goal

System-level Actions:

These actions interact with standard ROS2 interfaces (Topics, Services, Actions) and system utilities.

  • log

  • publish_message

  • send_srv_request

  • trigger_service

  • send_action_goal

  • trigger_action_server

Usage Example:

    from ros_sugar.actions import start, log, trigger_service

    # Component Lifecycle Action
    my_component = BaseComponent(node_name='test_component')
    action_start = start(component=my_component)

    # System/Logic Action
    action_log = log(msg="I am executing a cool action!")

    # ROS2 Interface Action
    action_srv = trigger_service(
        srv_name='/add_two_ints',
        srv_type=AddTwoInts
    )

Actions

Pre-defined component and system level actions.

Module Contents

Functions

send_srv_request

Action to send a ROS2 service request to a given service name/type

trigger_service

Action to trigger a ROS2 service. The action will try to create the service request out of the incoming event topic, if failed it will trigger the server with a default request value

send_component_service_request

Action to send a ROS2 service request to a component’s main service

trigger_component_service

Action to trigger a component’s main service The action will try to create the service request out of the incoming event topic, if failed it will trigger the server with a default request value

send_action_goal

Action to send a ROS2 action goal to a given ROS2 action server name and type

trigger_action_server

Action to trigger a ROS2 action server with given name and type The action will try to create the service request out of the incoming event topic, if failed it will trigger the server with a default request value

send_component_action_server_goal

Action to send a ROS2 action to a component’s main action server

trigger_component_action_server

Action to trigger a component’s action server The action will try to create the service request out of the incoming event topic, if failed it will trigger the server with a default request value

publish_message

Action to publish a ROS2 message on a given topic. If both publish_rate and publish_period are not provided, the message will be published once

start

Action to start a given component

stop

Action to stop a given component

restart

Action to restart a given component

reconfigure

Action to reconfigure a given component

update_parameter

Action to update (change) the value of a component config parameter

update_parameters

Action to update (change) the values of a list of component config parameters

log

Action to log a message.

API

ros_sugar.actions.send_srv_request(*, srv_name: str, srv_type: type, srv_request_msg: Any) ros_sugar.core.action.Action

Action to send a ROS2 service request to a given service name/type

Parameters:
  • srv_name (str) – Service name

  • srv_type (type) – Service type (ROS2 service)

  • srv_request_msg (Any) – Service request message

Returns:

Sending request action

Return type:

Action

ros_sugar.actions.trigger_service(*, srv_name: str, srv_type: type) ros_sugar.core.action.Action

Action to trigger a ROS2 service. The action will try to create the service request out of the incoming event topic, if failed it will trigger the server with a default request value

Parameters:
  • srv_name (str) – Service name

  • srv_type (type) – Service type (ROS2 service)

Returns:

Sending request action

Return type:

Action

ros_sugar.actions.send_component_service_request(*, component: ros_sugar.core.component.BaseComponent, srv_request_msg: Any) ros_sugar.core.action.Action

Action to send a ROS2 service request to a component’s main service

Parameters:
  • component (BaseComponent) – Sugarcoat Component

  • srv_request_msg (Any) – Service request message

Returns:

Sending request action

Return type:

Action

ros_sugar.actions.trigger_component_service(*, component: ros_sugar.core.component.BaseComponent) ros_sugar.core.action.Action

Action to trigger a component’s main service The action will try to create the service request out of the incoming event topic, if failed it will trigger the server with a default request value

Parameters:

component (BaseComponent) – Sugarcoat Component

Returns:

Sending request action

Return type:

Action

ros_sugar.actions.send_action_goal(*, server_name: str, server_type: type, request_msg: Any) ros_sugar.core.action.Action

Action to send a ROS2 action goal to a given ROS2 action server name and type

Parameters:
  • action_name (str) – ROS2 action name

  • action_type (type) – ROS2 action type

  • action_request_msg (Any) – ROS2 action goal message

Returns:

Sending goal action

Return type:

Action

ros_sugar.actions.trigger_action_server(*, server_name: str, server_type: type) ros_sugar.core.action.Action

Action to trigger a ROS2 action server with given name and type The action will try to create the service request out of the incoming event topic, if failed it will trigger the server with a default request value

Parameters:
  • action_name (str) – ROS2 action name

  • action_type (type) – ROS2 action type

Returns:

Sending goal action

Return type:

Action

ros_sugar.actions.send_component_action_server_goal(*, component: ros_sugar.core.component.BaseComponent, request_msg: Any) ros_sugar.core.action.Action

Action to send a ROS2 action to a component’s main action server

Parameters:
  • component (BaseComponent) – Sugarcoat Component

  • action_request_msg (Any) – ROS2 action goal message

Returns:

Sending goal action

Return type:

Action

ros_sugar.actions.trigger_component_action_server(*, component: ros_sugar.core.component.BaseComponent) ros_sugar.core.action.Action

Action to trigger a component’s action server The action will try to create the service request out of the incoming event topic, if failed it will trigger the server with a default request value

Parameters:

component (BaseComponent) – Sugarcoat Component

Returns:

Sending goal action

Return type:

Action

ros_sugar.actions.publish_message(*, topic: ros_sugar.io.topic.Topic, msg: Any, publish_rate: Optional[float] = None, publish_period: Optional[float] = None) ros_sugar.core.action.Action

Action to publish a ROS2 message on a given topic. If both publish_rate and publish_period are not provided, the message will be published once

Parameters:
  • topic (Topic) – Topic to publish

  • msg (Any) – Message to publish

  • publish_rate (Optional[float], optional) – Publishing rate (Hz), defaults to None

  • publish_period (Optional[float], optional) – Publishing period (s), defaults to None

Returns:

Publish message action

Return type:

Action

ros_sugar.actions.start(*, component: ros_sugar.core.component.BaseComponent) ros_sugar.core.action.Action

Action to start a given component

Parameters:

component (BaseComponent) – Component

Returns:

Component start action

Return type:

Action

ros_sugar.actions.stop(*, component: ros_sugar.core.component.BaseComponent) ros_sugar.core.action.Action

Action to stop a given component

Parameters:

component (BaseComponent) – Component

Returns:

Component stop action

Return type:

Action

ros_sugar.actions.restart(*, component: ros_sugar.core.component.BaseComponent, wait_time: Optional[float] = None) ros_sugar.core.action.Action

Action to restart a given component

Parameters:
  • component (BaseComponent) – Component

  • wait_time (Optional[float]) – Optional wait time n seconds between stop and start, defaults to None (i.e. no wait)

Returns:

Component restart action

Return type:

Action

ros_sugar.actions.reconfigure(*, component: ros_sugar.core.component.BaseComponent, new_config: Union[str, object], keep_alive: bool = False) ros_sugar.core.action.Action

Action to reconfigure a given component

Parameters:
  • component (BaseComponent) – Component

  • new_config (Union[str, object]) – Component config class or path to config file

  • keep_alive (bool, optional) – To keep the component running when reconfiguring, defaults to False

Returns:

Component reconfigure action

Return type:

Action

ros_sugar.actions.update_parameter(*, component: ros_sugar.core.component.BaseComponent, param_name: str, new_value: Any, keep_alive: bool = True) ros_sugar.core.action.Action

Action to update (change) the value of a component config parameter

Parameters:
  • component (BaseComponent) – Component

  • param_name (str) – Parameter name

  • new_value (Any) – Parameter value

  • keep_alive (bool, optional) – To keep the component running when updating the value, defaults to True

Returns:

Component parameter update action

Return type:

Action

ros_sugar.actions.update_parameters(*, component: ros_sugar.core.component.BaseComponent, params_names: List[str], new_values: List, keep_alive: bool = True) ros_sugar.core.action.Action

Action to update (change) the values of a list of component config parameters

Parameters:
  • component (BaseComponent) – Component

  • params_names (List[str]) – Parameters names

  • new_values (List) – Parameters values

  • keep_alive (bool, optional) – To keep the component running when updating the value, defaults to True

Returns:

Component parameter update action

Return type:

Action

ros_sugar.actions.log(*, msg: str, logger_name: Optional[str] = None) ros_sugar.core.action.LogInfo

Action to log a message.

Parameters:
  • msg (str)

  • logger_name (Optional[str])

Return type:

LogInfo