9. Joint Control: Extension Python Scripting

9.1. Learning Objectives

In this tutorial, we will interact with a manipulator, the Franka Emika Panda Robot. We will

  • Add a ROS Joint State publisher and subscriber via UI

  • Add a ROS Joint State publisher and subscriber using the OmniGraph python API using the script editor.

Prerequisite

  • Completed Isaac Sim Workflows to understand the Extension Workflow.

  • ros_workspace was sourced.

9.2. Add Joint States in UI

  1. Go to Content tab below the viewport, and open Isaac/Robots/Franka/franka_alt_fingers.usd.

  2. Go to Create -> Visual Scripting -> Action Graph to create an Action graph.

  3. Add the following OmniGraph nodes into the Action graph:

  • On Playback Tick node to execute other graph nodes every simulation frame.

  • Isaac Read Simulation Time node to retrieve current simulation time.

  • ROS1 Publish Joint State node to publish ROS Joint States to the /joint_states topic.

  • ROS1 Subscribe Joint State node to subscribe to ROS Joint States from the /joint_command topic.

  • Articulation Controller node to move the robot articulation according to commands received from the subscriber node.

  1. Select ROS1 Publish Joint State node and add the /panda robot articulation to the targetPrim.

  2. Select Articulation Controller node and add the /panda robot articulation to the targetPrim. Additionally make sure to uncheck usePath.

  3. Connect the Tick output of the On Playback Tick node to the Execution input of the ROS1 Publish Joint State, ROS1 Subscribe JointState and Articulation Controller nodes.

  4. Connect the Simulation Time output of the Isaac Read Simulation Time node to the Timestamp input of the ROS1 Publish Joint State node. Setup other connections between nodes as shown in the image below:

    ROS1 Joint State Action Graph
  5. Make sure roscore is running, press Play to start publishing joint states to the /joint_states topic and subscribing commands on the /joint_command topic.

  6. To test out the ROS bridge, use the provided python script to publish joint commands to the robot. In a ROS-sourced terminal:

    rosrun isaac_tutorials ros_publisher.py
    
  7. While the robot is moving, open a ROS-sourced terminal and check the joint state rostopic by rostopic echo /joint_states. You’ll see that the position of the joints are changing following the robot.

9.3. Add Joint States in Extension

The same action done via UI can also be done using python script. More details regarding the different workflow of using Omniverse Isaac Sim can be found Isaac Sim Workflows.

  1. Go to Content tab below the viewport, and open Isaac/Robots/Franka/franka_alt_fingers.usd.

  2. Open Script Editor in Window -> Script Editor and copy paste the following code into it. This is the equivalent to Steps 2-7 of the previous section.

    import omni.graph.core as og
    from omni.isaac.core_nodes.scripts.utils import set_target_prims
    
    og.Controller.edit(
        {"graph_path": "/panda/ActionGraph", "evaluator_name": "execution"},
        {
            og.Controller.Keys.CREATE_NODES: [
                ("OnPlaybackTick", "omni.graph.action.OnPlaybackTick"),
                ("PublishJointState", "omni.isaac.ros_bridge.ROS1PublishJointState"),
                ("SubscribeJointState", "omni.isaac.ros_bridge.ROS1SubscribeJointState"),
                ("ArticulationController", "omni.isaac.core_nodes.IsaacArticulationController"),
                ("ReadSimTime", "omni.isaac.core_nodes.IsaacReadSimulationTime"),
            ],
            og.Controller.Keys.CONNECT: [
                ("OnPlaybackTick.outputs:tick", "PublishJointState.inputs:execIn"),
                ("OnPlaybackTick.outputs:tick", "SubscribeJointState.inputs:execIn"),
                ("OnPlaybackTick.outputs:tick", "ArticulationController.inputs:execIn"),
    
                ("ReadSimTime.outputs:simulationTime", "PublishJointState.inputs:timeStamp"),
    
                ("SubscribeJointState.outputs:jointNames", "ArticulationController.inputs:jointNames"),
                ("SubscribeJointState.outputs:positionCommand", "ArticulationController.inputs:positionCommand"),
                ("SubscribeJointState.outputs:velocityCommand", "ArticulationController.inputs:velocityCommand"),
                ("SubscribeJointState.outputs:effortCommand", "ArticulationController.inputs:effortCommand"),
            ],
            og.Controller.Keys.SET_VALUES: [
                # Providing path to /panda robot to Articulation Controller node
                # Providing the robot path is equivalent to setting the targetPrim in Articulation Controller node
                ("ArticulationController.inputs:usePath", True),
                ("ArticulationController.inputs:robotPath", "/panda"),
            ],
        },
    )
    
    # Setting the /panda target prim to Publish JointState node
    set_target_prims(primPath="/panda/ActionGraph/PublishJointState", targetPrimPaths=["/panda"])
    
  3. Make sure roscore is running, press Run in the Script Editor and the Action Graph with all required nodes should be added. You can find the corresponding ActionGraph in the Stage Tree.

  4. Same as the previous section, test out the ROS bridge using the provide python script to publish joint commands to the robot.

    rosrun isaac_tutorials ros_publisher.py
    
  5. Check the joint state with rostopic echo /joint_states while it’s moving.

9.4. Position and Velocity Control Modes

The joint state subscriber currently supports position and velocity control. Each joint can only be controlled by a single mode at a time, but different joints on the same articulation tree can be controlled by different modes.

The snippet below demonstrates how to command a robot using both position and velocity controls by grouping joints that use the same mode into one message, and create two different messages for position control joints and velocity controlled joints.

import rospy
from sensor_msgs.msg import JointState

rospy.init_node('position_velocity_publisher')
pub = rospy.Publisher('joint_command', JointState, queue_size=10)

joint_state_position = JointState()
joint_state_velocity = JointState()

joint_state_position.name = ["joint1", "joint2","joint3"]
joint_state_velocity.name = ["wheel_left_joint", "wheel_right_joint"]
joint_state_position.position = [0.2,0.2,0.2]
joint_state_velocity.velocity = [20, -20]

rate = rospy.Rate(10)
while not rospy.is_shutdown():
    pub.publish(joint_state_position)
    pub.publish(joint_state_velocity)
    rate.sleep()

9.5. Summary

This tutorial covered adding a ROS Joint State publisher and subscriber via both UI and Extension scripting.

9.5.1. Next Steps