ROS2 Client Library

The ROS2ClientLibrary provides comprehensive ROS2 operations for Robot Framework testing.

Overview

The ROS2ClientLibrary is the main library for ROS2 operations. It combines CLI and native operations to provide the best performance and reliability for each task.

Key Features: - Topic operations (publish, subscribe, monitor, discover) - Service operations (call, monitor, discover) - Action operations (send goals, monitor, discover) - Node operations (list, info, monitor) - Parameter operations (get, set, list, monitor) - Launch operations (launch files, packages) - Run operations (execute nodes, manage processes) - Transform operations (tf2 support) - Utility operations (cleanup, info, validation)

Usage

*** Settings ***
Library    ROS2ClientLibrary    timeout=10.0    node_name=test_robot

*** Test Cases ***
Test ROS2 System
    ${topics}=    List Topics
    ${publisher}=    Create Publisher    /chatter    std_msgs/msg/String
    Publish Message    ${publisher}    Hello World

Initialization

ROS2ClientLibrary

The main ROS2 client that combines CLI and native operations for Robot Framework testing.

Keyword: Initialize ROS2 Client

*** Settings ***
Library    ROS2ClientLibrary    timeout=10.0    node_name=test_robot

Topic Operations

Keyword: Create Publisher

Creates a ROS2 publisher for a specific topic and message type.

${publisher}=    Create Publisher    /chatter    std_msgs/msg/String

Keyword: Create Subscriber

Creates a ROS2 subscriber for a specific topic and message type.

${subscriber}=    Create Subscriber    /chatter    std_msgs/msg/String

Keyword: Publish Message

Publishes a message to a topic using a publisher.

Publish Message    ${publisher}    Hello World

Keyword: Wait For Message

Waits for a message on a topic with a timeout.

${message}=    Wait For Message    /chatter    std_msgs/msg/String    timeout=5.0

Keyword: List Topics

Lists all available ROS2 topics.

${topics}=    List Topics

Keyword: Topic Exists

Checks if a topic exists.

${exists}=    Topic Exists    /chatter

Keyword: Get Topic Info

Gets detailed information about a topic.

${info}=    Get Topic Info    /chatter

Service Operations

Keyword: Create Service Client

Creates a service client for a specific service and service type.

${client}=    Create Service Client    /add_two_ints    example_interfaces/srv/AddTwoInts

Keyword: Call Service

Calls a service with request parameters.

${result}=    Call Service    ${client}    a=5    b=3

Keyword: List Services

Lists all available ROS2 services.

${services}=    List Services

Keyword: Service Exists

Checks if a service exists.

${exists}=    Service Exists    /add_two_ints

Keyword: Get Service Info

Gets detailed information about a service.

${info}=    Get Service Info    /add_two_ints

Action Operations

Keyword: Create Action Client

Creates an action client for a specific action and action type.

${client}=    Create Action Client    /navigate_to_pose    nav2_msgs/action/NavigateToPose

Keyword: Send Action Goal

Sends a goal to an action server.

${result}=    Send Action Goal    ${client}    x=1.0    y=2.0    yaw=0.0

Keyword: Wait For Action Result

Waits for an action result with a timeout.

${result}=    Wait For Action Result    ${client}    timeout=30.0

Keyword: List Actions

Lists all available ROS2 actions.

${actions}=    List Actions

Keyword: Action Exists

Checks if an action exists.

${exists}=    Action Exists    /navigate_to_pose

Keyword: Get Action Info

Gets detailed information about an action.

${info}=    Get Action Info    /navigate_to_pose

Node Operations

Keyword: List Nodes

Lists all running ROS2 nodes.

${nodes}=    List Nodes

Keyword: Node Exists

Checks if a node exists.

${exists}=    Node Exists    /talker

Keyword: Get Node Info

Gets detailed information about a node.

${info}=    Get Node Info    /talker

Keyword: Get Node Topics

Gets topics published/subscribed by a node.

${topics}=    Get Node Topics    /talker

Keyword: Get Node Services

Gets services provided by a node.

${services}=    Get Node Services    /talker

Parameter Operations

Keyword: Get Parameter

Gets a parameter value from a node.

${value}=    Get Parameter    /talker    my_param

Keyword: Set Parameter

Sets a parameter value on a node.

Set Parameter    /talker    my_param    new_value

Keyword: List Parameters

Lists all parameters of a node.

${params}=    List Parameters    /talker

Keyword: Parameter Exists

Checks if a parameter exists.

${exists}=    Parameter Exists    /talker    my_param

Launch Operations

Keyword: Launch File

Launches a ROS2 launch file.

${process}=    Launch File    my_launch_file.launch.py

Keyword: Launch Package

Launches a ROS2 package.

${process}=    Launch Package    my_package    my_launch_file.launch.py

Keyword: List Launch Files

Lists available launch files in a package.

${files}=    List Launch Files    my_package

Keyword: List Packages

Lists all available ROS2 packages.

${packages}=    List Packages

Run Operations

Keyword: Run Node

Runs a ROS2 node.

${process}=    Run Node    my_package    my_node

Keyword: Stop Node

Stops a running ROS2 node.

Stop Node    ${process}

Keyword: Is Node Running

Checks if a node is running.

${running}=    Is Node Running    /talker

Transform Operations

Keyword: Get Transform

Gets a transform between two frames.

${transform}=    Get Transform    base_link    map

Keyword: Transform Exists

Checks if a transform exists.

${exists}=    Transform Exists    base_link    map

Keyword: Wait For Transform

Waits for a transform to become available.

${transform}=    Wait For Transform    base_link    map    timeout=5.0

Utility Operations

Keyword: ROS Doctor

Runs ROS2 doctor to check system health.

${output}=    ROS Doctor

Keyword: Cleanup

Cleans up resources and connections.

Cleanup

Keyword: Get System Info

Gets system information.

${info}=    Get System Info

Data Classes

Pose

Data class representing a 2D pose with position and orientation.

${pose}=    Create Pose    x=1.0    y=2.0    yaw=0.0

Message Types

The ROS2 client library works with standard ROS2 message types:

  • std_msgs/msg/String - String messages

  • std_msgs/msg/Int32 - Integer messages

  • geometry_msgs/msg/Twist - Velocity commands

  • sensor_msgs/msg/LaserScan - Laser scan data

  • nav_msgs/msg/Odometry - Odometry data

Service Types

Common service types used with the library:

  • std_srvs/srv/Empty - Empty service requests

  • std_srvs/srv/SetBool - Boolean service requests

  • example_interfaces/srv/AddTwoInts - Example service for testing

Action Types

Common action types for navigation and control:

  • nav2_msgs/action/NavigateToPose - Navigation actions

  • control_msgs/action/FollowJointTrajectory - Joint trajectory control

Example Usage

Basic ROS2 Test

*** Settings ***
Library    ROS2ClientLibrary    timeout=10.0    node_name=test_robot

*** Test Cases ***
Test Topic Communication
    ${publisher}=    Create Publisher    /chatter    std_msgs/msg/String
    Publish Message    ${publisher}    Hello World
    ${message}=    Wait For Message    /chatter    std_msgs/msg/String
    Should Be Equal    ${message}    Hello World

Test Service Call
    ${client}=    Create Service Client    /add_two_ints    example_interfaces/srv/AddTwoInts
    ${result}=    Call Service    ${client}    a=5    b=3
    Should Be Equal    ${result.sum}    8

Test Node Operations
    ${nodes}=    List Nodes
    Should Not Be Empty    ${nodes}
    ${exists}=    Node Exists    /talker
    Should Be True    ${exists}

Advanced Usage

*** Test Cases ***
Test Action Goal
    ${client}=    Create Action Client    /navigate_to_pose    nav2_msgs/action/NavigateToPose
    ${result}=    Send Action Goal    ${client}    x=1.0    y=2.0    yaw=0.0
    Should Be True    ${result.success}

Test Parameter Operations
    Set Parameter    /talker    my_param    test_value
    ${value}=    Get Parameter    /talker    my_param
    Should Be Equal    ${value}    test_value

Test Transform Operations
    ${transform}=    Get Transform    base_link    map
    Should Not Be Empty    ${transform}