API Documentation¶
Message Flow¶
The Python ROS Engine follows a message flow pattern similar to ROS2:
graph LR A[Node] -- create_publisher --> B[Publisher] A -- create_subscription --> C[Subscriber] A -- create_service --> D[Service] A -- create_client --> E[Client] B -- publish --> F[(Topic)] F -- subscribe --> C E -- call --> G[(Service)] G -- handle --> D
Here's a sequence diagram showing the complete message flow from publisher to subscriber:
sequenceDiagram participant Node1 participant Publisher participant Topic participant Subscriber participant Node2 Node1->>Publisher: create_publisher() Node2->>Subscriber: create_subscription() Publisher->>Topic: publish(message) Topic->>Subscriber: deliver(message) Subscriber->>Node2: callback(message)
And here's a sequence diagram for the service/client request-response flow:
sequenceDiagram participant ClientNode participant Client participant Service participant ServiceNode ClientNode->>Client: create_client() ServiceNode->>Service: create_service() Client->>Service: call(request) Service->>ServiceNode: callback(request) ServiceNode->>Service: return(response) Service->>Client: return(response) Client->>ClientNode: return(response)
Node Class¶
The Node
class is the base class for all ROS nodes.
Constructor¶
node_name
: Name of the nodenamespace
: Namespace for the node (default: "/")
Methods¶
create_publisher¶
Create a publisher for a topic.msg_type
: The message type class for this publishertopic_name
: The name of the topic to publish toqos_profile
: Quality of Service profile (optional)
create_subscription¶
create_subscription(msg_type: type, topic_name: str, callback: Callable, qos_profile: QoSProfile = None)
msg_type
: The message type class for this subscriptiontopic_name
: The name of the topic to subscribe tocallback
: Function to call when a message is receivedqos_profile
: Quality of Service profile (optional)
create_service¶
create_service(srv_type: type, service_name: str, callback: Callable, qos_profile: QoSProfile = None)
srv_type
: The service type classservice_name
: The name of the servicecallback
: Function to call when a service request is receivedqos_profile
: Quality of Service profile (optional)
create_client¶
Create a service client.srv_type
: The service type classservice_name
: The name of the service to callqos_profile
: Quality of Service profile (optional)
create_timer¶
Create a timer that calls the callback function periodically.timer_period_sec
: Timer period in secondscallback
: Function to call when timer expires
declare_parameter¶
Declare a parameter with a name and default value.name
: Parameter namedefault_value
: Default value for the parameter (optional)parameter_type
: Type of the parameter (optional)
get_parameter¶
Get a parameter by name.name
: Parameter name- Returns: Parameter object
set_parameter¶
Set a parameter value.name
: Parameter namevalue
: New value for the parameter- Returns: True if successful, False otherwise
add_on_set_parameters_callback¶
Add a callback to be called when parameters are set.callback
: Function to call when parameters are set
get_topic_names_and_types¶
Get list of topics and their types.- Returns: List of (topic_name, topic_types) tuples
get_service_names_and_types¶
Get list of services and their types.- Returns: List of (service_name, service_types) tuples
get_publishers_info_by_topic¶
Get information about publishers for a topic.topic_name
: Name of the topic- Returns: List of dictionaries with publisher information
get_subscriptions_info_by_topic¶
Get information about subscriptions for a topic.topic_name
: Name of the topic- Returns: List of dictionaries with subscription information
spin¶
Spin the node to process callbacks.This function blocks until the node is destroyed.
spin_once¶
Process one callback and return.timeout_sec
: Time to wait for a callback (default: 0.1)
destroy_node¶
Destroy the node and clean up resources.Message Classes¶
Message¶
Base class for all ROS messages.
serialize¶
Serialize the message to bytes.- Returns: Serialized message as bytes
deserialize¶
Deserialize bytes to a message instance.data
: Serialized message data as bytes
String¶
String message type.
Fields¶
data
: str - String data
Int8¶
8-bit signed integer message type.
Fields¶
data
: int - Integer data (range: -128 to 127)
Int16¶
16-bit signed integer message type.
Fields¶
data
: int - Integer data (range: -32,768 to 32,767)
Int32¶
32-bit signed integer message type.
Fields¶
data
: int - Integer data (range: -2,147,483,648 to 2,147,483,647)
Int64¶
64-bit signed integer message type.
Fields¶
data
: int - Integer data (range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
UInt8¶
8-bit unsigned integer message type.
Fields¶
data
: int - Integer data (range: 0 to 255)
UInt16¶
16-bit unsigned integer message type.
Fields¶
data
: int - Integer data (range: 0 to 65,535)
UInt32¶
32-bit unsigned integer message type.
Fields¶
data
: int - Integer data (range: 0 to 4,294,967,295)
UInt64¶
64-bit unsigned integer message type.
Fields¶
data
: int - Integer data (range: 0 to 18,446,744,073,709,551,615)
Float32¶
32-bit floating point message type.
Fields¶
data
: float - Floating point data
Float64¶
64-bit floating point message type.
Fields¶
data
: float - Floating point data
Bool¶
Boolean message type.
Fields¶
data
: bool - Boolean data (True or False)
Empty¶
Empty message type.
Fields¶
- None
Time¶
Time message type.
Fields¶
secs
: int - Secondsnsecs
: int - Nanoseconds
Duration¶
Duration message type.
Fields¶
secs
: int - Secondsnsecs
: int - Nanoseconds
MultiArrayDimension¶
Dimension description for multi-dimensional arrays.
Fields¶
label
: str - Label for the dimensionsize
: int - Size of the dimensionstride
: int - Stride of the dimension
MultiArrayLayout¶
Layout description for multi-dimensional arrays.
Fields¶
dim
: List[MultiArrayDimension] - Array of dimension propertiesdata_offset
: int - Offset to first data point in the array
ByteMultiArray¶
Multi-array of bytes.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[int] - Array of bytes
Int8MultiArray¶
Multi-array of Int8 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[int] - Array of Int8 values
Int16MultiArray¶
Multi-array of Int16 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[int] - Array of Int16 values
Int32MultiArray¶
Multi-array of Int32 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[int] - Array of Int32 values
Int64MultiArray¶
Multi-array of Int64 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[int] - Array of Int64 values
UInt8MultiArray¶
Multi-array of UInt8 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[int] - Array of UInt8 values
UInt16MultiArray¶
Multi-array of UInt16 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[int] - Array of UInt16 values
UInt32MultiArray¶
Multi-array of UInt32 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[int] - Array of UInt32 values
UInt64MultiArray¶
Multi-array of UInt64 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[int] - Array of UInt64 values
Float32MultiArray¶
Multi-array of Float32 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[float] - Array of Float32 values
Float64MultiArray¶
Multi-array of Float64 values.
Fields¶
layout
: MultiArrayLayout - Message layoutdata
: List[float] - Array of Float64 values
QoS Classes¶
ReliabilityPolicy¶
Reliability policy for message delivery.
RELIABLE
: Guaranteed deliveryBEST_EFFORT
: No guarantee of delivery
DurabilityPolicy¶
Durability policy for message persistence.
TRANSIENT_LOCAL
: Replays last message for late subscribersVOLATILE
: No message replay
QoSProfile¶
Quality of Service profile defining communication policies.
Constructor¶
QoSProfile(reliability: ReliabilityPolicy = ReliabilityPolicy.RELIABLE,
durability: DurabilityPolicy = DurabilityPolicy.VOLATILE,
depth: int = 10)
Fields¶
reliability
: ReliabilityPolicy - Message delivery reliabilitydurability
: DurabilityPolicy - Message persistence policydepth
: int - Queue depth for messages
Publisher Class¶
Constructor¶
node
: Node - Parent nodemsg_type
: type - Message type for this publishertopic_name
: str - Topic name to publish toqos_profile
: QoSProfile - Quality of Service profile
Methods¶
publish¶
Publish a message to the topic.message
: Message - Message to publish
Subscriber Class¶
Constructor¶
Subscriber(node: Node, msg_type: type, topic_name: str, callback: Callable, qos_profile: QoSProfile)
node
: Node - Parent nodemsg_type
: type - Message type for this subscriptiontopic_name
: str - Topic name to subscribe tocallback
: Callable - Callback function for received messagesqos_profile
: QoSProfile - Quality of Service profile
Service Class¶
Constructor¶
node
: Node - Parent nodesrv_type
: type - Service typeservice_name
: str - Service namecallback
: Callable - Callback function for service requestsqos_profile
: QoSProfile - Quality of Service profile
Client Class¶
Constructor¶
node
: Node - Parent nodesrv_type
: type - Service typeservice_name
: str - Service name to callqos_profile
: QoSProfile - Quality of Service profile
Methods¶
call¶
Call a service synchronously.request
: Service request object- Returns: Service response object
call_async¶
Call a service asynchronously.request
: Service request object- Returns: Future object for the service response
Discovery Class¶
Methods¶
get_all_topics¶
Get all available topics.- Returns: List of topic names
get_all_services¶
Get all available services.- Returns: List of service names
get_topic_types¶
Get the types of a topic.topic_name
: Name of the topic- Returns: List of topic types
get_service_types¶
Get the types of a service.service_name
: Name of the service- Returns: List of service types
get_nodes¶
Get all available nodes.- Returns: List of node names
Bridge Class¶
The bridge class provides functionality to interact with native ROS systems.
Constructor¶
host
: str - ROS master host (default: "localhost")port
: int - ROS master port (default: 11311)
Methods¶
connect¶
Connect to the ROS master.Raises BridgeConnectionError if connection fails.
discover_ros_nodes¶
Discover all native ROS nodes.- Returns: List of node names
discover_ros_topics¶
Discover all native ROS topics.- Returns: List of dictionaries with topic information
discover_ros_services¶
Discover all native ROS services.- Returns: List of dictionaries with service information
MessageTranslator Class¶
Handles translation between Python ROS engine messages and native ROS messages.
Methods¶
pyros_to_ros¶
Translate a Python ROS engine message to a native ROS message format.message
: Python ROS engine messageros_message_type
: Native ROS message type (e.g., "std_msgs/String")- Returns: Dict - Native ROS message in dictionary format
ros_to_pyros¶
Translate a native ROS message to a Python ROS engine message.ros_message
: Native ROS message in dictionary formatpyros_message_type
: Python ROS engine message type- Returns: Message - Python ROS engine message
get_pyros_type¶
Get the corresponding Python ROS engine message type for a native ROS message type.ros_message_type
: Native ROS message type (e.g., "std_msgs/String")- Returns: Type[Message] - Corresponding Python ROS engine message type
get_ros_type¶
Get the corresponding native ROS message type for a Python ROS engine message type.pyros_message_type
: Python ROS engine message type- Returns: str - Corresponding native ROS message type
LaunchSystem Class¶
The launch system for managing multiple nodes and providing system status information.
Constructor¶
Methods¶
add_node¶
Add a node to the launch system.node_name
: Name to register the node undernode_class
: The node class to instantiate*args
: Positional arguments for node initialization**kwargs
: Keyword arguments for node initialization
add_node_from_file¶
Add a node to the launch system from a Python file.node_name
: Name to register the node underfile_path
: Path to the Python file containing the node classclass_name
: Name of the node class in the file*args
: Positional arguments for node initialization**kwargs
: Keyword arguments for node initialization
remove_node¶
Remove a node from the launch system.node_name
: Name of the node to remove
start¶
Start all nodes in the launch system.shutdown¶
Shutdown all nodes in the launch system.get_system_status¶
Get the status of the entire system.- Returns: Dict containing system status information
print_system_status¶
Print the status of the entire system in a human-readable format.LaunchDescription Class¶
Description of a launch system configuration.
Constructor¶
Initialize a launch description.launch_system
: Optional LaunchSystem to use
Methods¶
add_node¶
Add a node action to the launch description.node_class
: The node class to instantiate*args
: Positional arguments for node initialization**kwargs
: Keyword arguments for node initialization
add_node_from_file¶
Add a node action from a Python file to the launch description.file_path
: Path to the Python file containing the node classclass_name
: Name of the node class in the file*args
: Positional arguments for node initialization**kwargs
: Keyword arguments for node initialization