0% found this document useful (0 votes)
32 views2 pages

ROS 2 Python API (rclpy) Overview

The ROS 2 Python API Reference (rclpy) provides essential functions for creating and managing nodes, publishers, subscribers, services, and clients in ROS 2. Key functionalities include initializing communication, declaring and getting parameters, and maintaining node responsiveness through spinning. The document outlines methods for setting up various components necessary for building ROS 2 applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

ROS 2 Python API (rclpy) Overview

The ROS 2 Python API Reference (rclpy) provides essential functions for creating and managing nodes, publishers, subscribers, services, and clients in ROS 2. Key functionalities include initializing communication, declaring and getting parameters, and maintaining node responsiveness through spinning. The document outlines methods for setting up various components necessary for building ROS 2 applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like