ROS 2 Python API Reference (rclpy)
Node
__init__(self, node_name)
Creates a node with a given name.
create_publisher(self, msg_type, topic, qos_profile)
Creates a publisher to send messages.
- msg_type: Message type (e.g., String)
- topic: Name of the topic
- qos_profile: Quality of Service setting (e.g., 10)
create_subscription(self, msg_type, topic, callback, qos_profile)
Creates a subscriber to receive messages.
- callback: Function called when a message is received.
create_service(self, srv_type, srv_name, callback)
Creates a service.
- srv_type: Service type (e.g., AddTwoInts)
- srv_name: Service name
- callback: Function to process requests.
create_client(self, srv_type, srv_name)
Creates a client to call a service.
- srv_type: Service type
- srv_name: Service name
create_timer(self, timer_period_sec, callback)
Creates a timer that calls the callback periodically.
- timer_period_sec: Time in seconds
- callback: Function called on each tick
declare_parameter(self, name, value)
Declares a parameter on the node.
- name: Parameter name
- value: Default value
get_parameter(self, name)
ROS 2 Python API Reference (rclpy)
Gets the value of a declared parameter.
get_logger(self)
Returns the logger interface for the node.
rclpy
init(args=None)
Initializes ROS 2 communication.
shutdown()
Shuts down ROS 2.
spin(node)
Keeps the node running and responsive.
spin_until_future_complete(node, future)
Spins the node until a future (e.g., service call) is complete.