rclcpy – Robot Operating System (ROS2) connectivity through micro-ROS
The rclcpy module contains basic classes and connectivity options for
communicating with a ROS network running on a linux machine, using the
eProsima’s micro-ROS client API.
The underlying micro-ROS system uses a resource-constrained middleware layer
(XRCE-DDS) that must be connected to an agent running within ROS2 on a host
Linux computer. The API exposed by Circuitpython aims to be close to the
standard Python API for ROS2, rclpy with minor additions to support
connecting to this agent.
Wifi must be connected before calling any rclcpy functions. As with
rclpy, the rclcpy.init() function must be run before creating any ROS
objects. Child objects, such as publishers, must be created by their parent
objects. For example:
import os, wifi, time
import rclcpy
wifi.radio.connect(ssid=os.getenv('CIRCUITPY_WIFI_SSID'),
password=os.getenv('CIRCUITPY_WIFI_PASSWORD'))
rclcpy.init("192.168.10.111","8888")
mynode = rclcpy.Node("foo")
mypub = mynode.create_publisher("bar")
mypub.publish_int32(42)
- rclcpy.init(agent_ip: str, agent_port: str, *, domain_id: int = 0) None
Initialize micro-ROS and connect to a micro-ROS agent.
This function starts ROS communications and connects to the micro-ROS agent on a linux computer. It must be called before creating ROS objects.
- rclcpy.create_node(node_name: str, *, namespace: str | None = None) Node
Create a Node.
Creates an instance of a ROS2 Node. Nodes can be used to create other ROS entities like publishers or subscribers. Nodes must have a unique name, and may also be constructed from their class.
- class rclcpy.Node(node_name: str, *, namespace: str | None = None)
A ROS2 Node
Create a Node.
Creates an instance of a ROS2 Node. Nodes can be used to create other ROS entities like publishers or subscribers. Nodes must have a unique name, and may also be constructed from their class.
- Parameters:
- deinit() None
Deinitializes the node and frees any hardware or remote agent resources used by it. Deinitialized nodes cannot be used again.
- class rclcpy.Publisher
A ROS2 publisher
Publishers cannot be created directly.
Use
Node.create_publisher()to create a publisher from a node.- Raises:
NotImplementedError – Always, as direct instantiation is not supported
- deinit() None
Deinitializes the publisher and frees any hardware or remote agent resources used by it. Deinitialized publishers cannot be used again.