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
Routine Actions:#
These control a Routine by name on the Monitor that hosts it.
start_routine
pause_routine
resume_routine
abort_routine
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#
Action to send a ROS2 service request to a given service name/type |
|
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 |
|
Action to send a ROS2 service request to a component’s main 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 |
|
Action to send a ROS2 action goal to a given ROS2 action server name and type |
|
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 |
|
Action to send a ROS2 action to a component’s main 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 |
|
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 |
|
Action to start a given component |
|
Action to stop a given component |
|
Action to restart a given component |
|
Action to reconfigure a given component |
|
Action to update (change) the value of a component config parameter |
|
Action to update (change) the values of a list of component config parameters |
|
Action to log a message. |
|
Action to start a routine by name. |
|
Action to pause a running routine, preempting the step in flight. |
|
Action to resume a paused routine, re-entering the step it stopped at. |
|
Action to end a routine now, running its |
|
Action to dwell for a while, as a step of a routine. |
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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- ros_sugar.actions.start_routine(*, routine_name: str) ros_sugar.core.action.Action#
Action to start a routine by name.
Equivalent to triggering the
Routineobject itself, and useful where the recipe has the name rather than the object.- Parameters:
routine_name (str) – Name the routine was declared with
- Return type:
- ros_sugar.actions.pause_routine(*, routine_name: str) ros_sugar.core.action.Action#
Action to pause a running routine, preempting the step in flight.
- Parameters:
routine_name (str) – Name the routine was declared with
- Return type:
- ros_sugar.actions.resume_routine(*, routine_name: str) ros_sugar.core.action.Action#
Action to resume a paused routine, re-entering the step it stopped at.
- Parameters:
routine_name (str) – Name the routine was declared with
- Return type:
- ros_sugar.actions.abort_routine(*, routine_name: str, reason: str = 'aborted by request') ros_sugar.core.action.Action#
Action to end a routine now, running its
on_abort.Written for the case it exists for: a higher priority event, such as an emergency stop, cutting a procedure short.
launcher.on(emergency_stop, abort_routine(routine_name="pick_object", reason="emergency stop"))
- Parameters:
routine_name (str) – Name the routine was declared with
reason (str) – Recorded in the routine’s cursor and logged
- Return type:
- ros_sugar.actions.wait(*, duration: float, name: Optional[str] = None) ros_sugar.core.action.Action#
Action to dwell for a while, as a step of a routine.
Every other step settles as soon as it is called, so “hold here for thirty seconds” has no other spelling. Stopping the step, by aborting or pausing its routine, ends the wait at once and gives back the worker it holds.
patrol = Routine( "patrol", steps=[ Action(arm.go_home), wait(duration=30.0, name="settle"), Action(arm.scan), wait(duration=5.0, name="settle_again"), Action(arm.go_home, name="back_home"), ], )
- Parameters:
duration (float) – Seconds to wait
name (Optional[str]) – Name of the step, which a routine needs when it waits more than once, since step names must be unique. Defaults to “wait”
- Return type: