Initialization, Shutdown, and Spinning¶
A collection of functions for writing a ROS program.
A typical ROS program consists of the following operations:
Create one or more ROS nodes
Process node callbacks
After a node is created, items of work can be done (e.g. subscription callbacks) by spinning on
The following functions can be used to process work that is waiting to be executed:
When finished with a previously initialized
Context (ie. done using
all ROS nodes associated with the context), the
shutdown() function should be called.
This will invalidate all entities derived from the context.
create_node(node_name, *, context=None, cli_args=None, namespace=None, use_global_arguments=True, enable_rosout=True, start_parameter_services=True, parameter_overrides=None, allow_undeclared_parameters=False, automatically_declare_parameters_from_overrides=False)¶
Create an instance of
str) – A name to give to the node.
Context) – The context to associated with the node, or
Nonefor the default global context.
str]) – Command line arguments to be used by the node. Being specific to a ROS node, an implicit –ros-args scope flag always precedes these arguments.
str) – The namespace prefix to apply to entities associated with the node (node name, topics, etc).
Falseif the node should ignore process-wide command line arguments.
Falseif the node should ignore rosout logging.
Falseif the node should not create parameter services.
- A list of
Parameterwhich are used to override the
initial values of parameters declared on this node.
- param allow_undeclared_parameters
if True undeclared parameters are allowed, default False. This option doesn’t affect parameter_overrides.
- A list of
bool) – If True, the “parameter overrides” will be used to implicitly declare parameters on the node during creation, default False.
- Return type
An instance of the newly created node.
init(*, args=None, context=None)¶
Initialize ROS communications for a given context.
Shutdown a previously initialized context.
This will also shutdown the global executor.
Execute work and block until the context associated with the executor is shutdown.
Callbacks will be executed by the provided executor.
This function blocks.
spin_once(node, *, executor=None, timeout_sec=None)¶
Execute one item of work or wait until a timeout expires.
One callback will be executed by the provided executor as long as that callback is ready before the timeout expires.
If no executor is provided (ie.
None), then the global executor is used. It is possible the work done is for a node other than the one provided if the global executor has a partially completed coroutine.
spin_until_future_complete(node, future, executor=None, timeout_sec=None)¶
Execute work until the future is complete.
Callbacks and other work will be executed by the provided executor until
Trueor the context associated with the executor is shutdown.
- Return type