RosNodeΒΆ
Inherits: RefCounted
A ROS 2 Node that manages publishers, subscribers, and other communication interfaces.
DescriptionΒΆ
The RosNode is the primary interface for interacting with the ROS 2 network. It provides factory methods to create publishers, subscribers, clients, and services, and allows management of node-level parameters and timers.
A node must be initialized using init() before it can be used to create other communication components.
MethodsΒΆ
count_publishers(topic: String) |
|
count_subscribers(topic: String) |
|
create_action_client(action_name: String, action_type: Variant, qos: RosQoS = null) |
|
create_action_server(action_name: String, action_type: Variant, execute_callback: Callable, goal_callback: Callable = Callable(), qos: RosQoS = null) |
|
create_client(srv_name: String, srv_type: Variant, qos: RosQoS = null) |
|
create_publisher(topic: String, type: Variant, qos: RosQoS = null) |
|
create_service(srv_name: String, srv_type: Variant, callback: Callable, qos: RosQoS = null) |
|
create_subscription(topic: String, type: Variant, callback: Callable, qos: RosQoS = null) |
|
create_timer(seconds: float, callback: Callable) |
|
void |
declare_parameter(name: String, default_value: Variant) |
get_name() const |
|
get_namespace() const |
|
get_parameter(name: String) |
|
void |
|
now() |
|
resolve_frame(frame_id: String) |
|
void |
set_parameter(name: String, value: Variant) |
SignalsΒΆ
parameter_changed(name: String, value: Variant) π
Emitted whenever a node parameter is updated by an external tool or by set_parameter() locally.
Method DescriptionsΒΆ
int count_publishers(topic: String) π
Returns the number of publishers currently active on a specific topic in the ROS 2 graph.
int count_subscribers(topic: String) π
Returns the number of subscribers currently active on a specific topic in the ROS 2 graph.
RosActionClient create_action_client(action_name: String, action_type: Variant, qos: RosQoS = null) π
Creates and returns a RosActionClient for the specified action_name and action_type (e.g. "example_interfaces/action/Fibonacci"). Use qos to configure the Quality of Service for the action client.
RosActionServer create_action_server(action_name: String, action_type: Variant, execute_callback: Callable, goal_callback: Callable = Callable(), qos: RosQoS = null) π
Creates and returns a RosActionServer for the specified action_name and action_type. Incoming goals are auto-accepted and handed to execute_callback on the main thread as a RosServerGoalHandle, which must be driven to a terminal state. The goal_callback can optionally be used to reject goals. Use qos to configure the Quality of Service for the action server. See RosActionServer for a full example.
RosClient create_client(srv_name: String, srv_type: Variant, qos: RosQoS = null) π
Creates and returns a RosClient for the specified service name and type. Use qos to configure the Quality of Service for the client.
RosPublisher create_publisher(topic: String, type: Variant, qos: RosQoS = null) π
Creates and returns a RosPublisher to send messages to a specific topic. Use qos to configure the Quality of Service for the publisher.
RosService create_service(srv_name: String, srv_type: Variant, callback: Callable, qos: RosQoS = null) π
Creates and returns a RosService server for the specified service name and type. The callback is triggered whenever a request is received. Use qos to configure the Quality of Service for the service server.
RosSubscriber create_subscription(topic: String, type: Variant, callback: Callable, qos: RosQoS = null) π
Creates and returns a RosSubscriber to receive messages from a specific topic. The callback is triggered for every new message received, always on the Godot main thread. Use qos to configure the Quality of Service for the subscription.
RosTfBroadcaster create_tf_broadcaster() π
Creates and returns a RosTfBroadcaster for publishing coordinate transforms into the TF2 system.
RosTfListener create_tf_listener() π
Creates and returns a RosTfListener for looking up coordinate transforms in the TF2 system.
RosTimer create_timer(seconds: float, callback: Callable) π
Creates and returns a RosTimer that triggers the callback at the specified seconds interval, synced with the ROS 2 executor's clock.
void declare_parameter(name: String, default_value: Variant) π
Declares a parameter on the node with a default_value. Parameters must be declared before they can be retrieved or modified by external tools.
Returns the name of the node as registered in the ROS 2 graph.
String get_namespace() const π
Returns the namespace of the node.
Variant get_parameter(name: String) π
Returns the current value of the parameter with the specified name.
Dictionary get_topic_names_and_types() π
Returns a Dictionary containing all currently active topic names as keys and their associated message types as values.
void init(node_name: String, namespace: String = "") π
Initializes the node with a node_name and an optional namespace. This must be called before using any other functions of the node.
Returns the current ROS 2 system time as a RosMsg of type builtin_interfaces/msg/Time.
String resolve_frame(frame_id: String) π
Prepends the node's namespace to a frame_id if it is not already absolute, helping resolve local frame names in multi-agent simulations.
void set_parameter(name: String, value: Variant) π
Sets the value of a previously declared parameter on the node.