ROS 2 Service for Manipulating Prims Attributes

Learning Objectives

In this tutorial, we will

  • Have a brief discussion on the Isaac Sim ROS 2 service messages types for manipulating prims attributes.

  • Create ROS 2 services to list prims and their attributes, as well as to read and write a specific prim attribute.

Getting Started

Important

Make sure to source your ROS 2 installation from the terminal before running Isaac Sim. If sourcing ROS 2 is a part of your .bashrc then Isaac Sim can be run directly.

Prerequisite

  • Complete ROS and ROS 2 Installation.

  • Set the FASTRTPS_DEFAULT_PROFILES_FILE environment variable per instructions in ROS and ROS 2 Installation before launching Isaac Sim, as well as any terminal where ROS messages will be sent or received, and ROS 2 Extension is enabled.

  • The Isaac Sim ROS 2 Workspace (with the isaac_ros2_messages ROS 2 package) built and sourced in the terminal where Isaac Sim is to be launched, as well as in any terminal where the service will be called. See Setting Up Workspaces for more details.

Service message types

The ROS2 Service Prim node provides four service with the following message types:

  • Get all prim path (and types) under a specific path

    isaac_ros2_messages/srv/GetPrims

    string path             # get prims at path
    ---
    string[] paths          # list of prim paths
    string[] types          # prim type names
    bool success            # indicate a successful execution of the service
    string message          # informational, e.g. for error messages
    
  • Get all attribute names and types for a specific prim

    isaac_ros2_messages/srv/GetPrimAttributes

    string path             # prim path
    ---
    string[] names          # list of attribute base names (name used to Get or Set an attribute)
    string[] displays       # list of attribute display names (name displayed in Property tab)
    string[] types          # list of attribute data types
    bool success            # indicate a successful execution of the service
    string message          # informational, e.g. for error messages
    
  • Get a prim attribute type and values

    isaac_ros2_messages/srv/GetPrimAttribute

    string path             # prim path
    string attribute        # attribute name
    ---
    string value            # attribute value (as JSON)
    string type             # attribute type
    bool success            # indicate a successful execution of the service
    string message          # informational, e.g. for error messages
    
  • Set a prim attribute value

    isaac_ros2_messages/srv/SetPrimAttribute

    string path             # prim path
    string attribute        # attribute name
    string value            # attribute value (as JSON)
    ---
    bool success            # indicate a successful execution of the service
    string message          # informational, e.g. for error messages
    

Note

Prim attributes are read and write as JSON (applied directly to the data, without keys). Arrays, vectors, matrixes and other numeric containers (e.g.: pxr.Gf.Vec3f, pxr.Gf.Matrix4d, pxr.Gf.Quatd, etc.) are interpreted as a list of numbers (row first).

Manipulating Prims Attributes

The following example shows how to list the prims and attributes, as well as read and write the pose of an object in the stage using the ROS2 Service Prim node.

Note

Make sure the Isaac Sim ROS 2 Workspace (with the isaac_ros2_messages ROS 2 package) is built and sourced in the terminal where Isaac Sim is to be launched, as well as in any terminal where the service will be called. See Setting Up Workspaces for more details.

  1. In a new stage, create an object (Cube) using the Create > Shape > Cube menu.

  2. Go to Create > Visual Scripting > Action Graph to create an Action Graph and add, connect and configure the following OmniGraph nodes into the Action Graph:

    Prim service
  3. Play the simulation to start the services.

  4. Use the following command in a new ROS2-sourced terminal to:

    • List the available services:

      ros2 service list
      
    • Get all child prim paths and types under the prim /World:

      ros2 service call /get_prims isaac_ros2_messages/srv/GetPrims "{path: /World}"
      
    • Get all the attribute names and types for the Cube (/World/Cube) prim:

      ros2 service call /get_prim_attributes isaac_ros2_messages/srv/GetPrimAttributes "{path: /World/Cube}"
      
    • Get the pose (position and orientation) of the Cube (/World/Cube) prim:

      # get position
      ros2 service call /get_prim_attribute isaac_ros2_messages/srv/GetPrimAttribute "{path: /World/Cube, attribute: xformOp:translate}"
      # get orientation (quaternion: wxyz)
      ros2 service call /get_prim_attribute isaac_ros2_messages/srv/GetPrimAttribute "{path: /World/Cube, attribute: xformOp:orient}"
      
    • Set the new pose (position and orientation) of the Cube (/World/Cube) prim:

      # set position
      ros2 service call /set_prim_attribute isaac_ros2_messages/srv/SetPrimAttribute "{path: /World/Cube, attribute: xformOp:translate, value: [1, 2, 3]}"
      # set orientation (quaternion: wxyz)
      ros2 service call /set_prim_attribute isaac_ros2_messages/srv/SetPrimAttribute "{path: /World/Cube, attribute: xformOp:orient, value: [0.7325378, 0.4619398, 0.1913417, 0.4619398]}"
      

Summary

In this tutorial we learned how to create ROS 2 services to list prims and their attributes, as well as to read and write a specific prim attribute.

Next Steps

Continue on to the next tutorial in our ROS 2 Tutorials series, ROS 2 Bridge in Standalone Workflow to learn how to run the ROS 2 Bridge in the standalone workflow.