Driving TurtleBot via ROS messages

Objective

ROS bridge comes with a few popular rostopics that are packaged for ease of use
More details are in the ROS & ROS2 Bridge
Here we will focus on the procedures in using them

Learning Objectives

Example: Enable a Turtlebot3 to drive around and subscribe to a twist message through the ROS network
-Add controllers to Turtlebot3
-Introduce the ROS bridge and ROS OmniGraph (OG) nodes
-Setup the robot to be driven by a ROS2 Twist message

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
Driving_TurtleBot_via_ROS2_messages1
Prerequisite
Having a rigged Turtlebot, or completed URDF Import: Turtlebot
=> Already Done
Completed ROS & ROS 2 Installation so that the necessary environment variables are set and sourced before launching Omniverse Isaac Sim, and ROS2 extension is enabled
=> Already Done

Main Concepts

Driving the Robot

First want to add the appropriate controllers
In the case of Turtlebot3, a wheeled-robot with two wheels, the nodes needed are Differential Controller and Articulation Controller
Differential Controller node: Convert vehicle speed to wheel speed
Artciulation Controller node: Send the commands to the joint drives
Detailed instructions on how to connect these nodes can be found in OmniGraph for a similar robot (NVIDIA Jetbot)
Setting up the Stage
=> Already Done

Omnigraph Tutorial
(1)Select Window -> Visual Scripting -> Action Graph from the dropdown menu at the top of the editor
Graph Editor will appear in the same pane as the Content browser
Driving_TurtleBot_via_ROS2_messages2
(2)Click New Action Graph to open an empty graph
Driving_TurtleBot_via_ROS2_messages3
Driving_TurtleBot_via_ROS2_messages4
(3)Type controller in the search bar of the graph editor, and drag an Articulation Controller and a Differential Controller onto the graph
Driving_TurtleBot_via_ROS2_messages5
Driving_TurtleBot_via_ROS2_messages6
(4)Articulation Controller Function & Use Controller
Articulation Controller:
Applies driver commands (in the form of force, position, or velocity) to the specified joints of any prim with an articulation root
Tell the controller which robot it’s going to control
Driving_TurtleBot_via_ROS2_messages7
Select the Articulation Controller node in the graph > Open up the property pane
Driving_TurtleBot_via_ROS2_messages8
Driving_TurtleBot_via_ROS2_messages9
Uncheck usePath and then click Add Targets near the top of the pane for input:targetPrim > Select turtlebot3_burger in the pop up window
(5)Differential Controller Function & Use Controller
Differential Controller:
Computes drive commands for a two wheeled robot given some target linear and angular velocity
Like the Articulation Controller, it also needs to be configured
Driving_TurtleBot_via_ROS2_messages10
Select the Differential Controller node in the graph and then in the properties pane, set the wheelDistance to 0.1125, the wheelRadius to 0.03, and maxAngularSpeed to 0.2
(6)Select joints articulate
The Articulation Controller also needs to know which joints to articulate
Expects this information in the form of a list of tokens or index values
Each joint in a robot has a name and the turtlebot3_burger has exactly two joints that are needed to articulate, because they are the revolute joints associated with the wheels that make the robot move
Driving_TurtleBot_via_ROS2_messages11
Verify this by examining the jetbot in the stage context tree. Within /World/turtlebot3_burger/base_link are two revolute physics joints named wheel_left_joint and wheel_right_joint
(7)Add two Constant Token nodes
Driving_TurtleBot_via_ROS2_messages12
Driving_TurtleBot_via_ROS2_messages13
Type token into the search bar of the graph editor and add two Constant Token nodes to the graph
Driving_TurtleBot_via_ROS2_messages14
Driving_TurtleBot_via_ROS2_messages15
Select one, and set it’s value to wheel_left_joint in the properties pane. Repeat this for the other constant token node, but set the value to wheel_right_joint
Driving_TurtleBot_via_ROS2_messages16
Driving_TurtleBot_via_ROS2_messages17
Type make array into the search bar of the graph editor and add a Make Array node to the graph
Driving_TurtleBot_via_ROS2_messages18
Select the Make Array node and click on the + icon in the inputs section of the property pane menu to add a second input
Driving_TurtleBot_via_ROS2_messages19
Set the arraySize to 2 as well, and then set the input type to token[] from the dropdown menu in the same pane
Driving_TurtleBot_via_ROS2_messages20
Finally, connect the constant token nodes to A and B of the Make Array node, and then the output of that node to the Joint Names input of the Articulation Controller node (7)Event Node
The last node is the event node
Driving_TurtleBot_via_ROS2_messages21
Driving_TurtleBot_via_ROS2_messages22
Search for playback in the search bar of the graph editor and add an On Playback Tick node to the graph
This node will emit an execution event for every frame, but only while the simulation is playing
Driving_TurtleBot_via_ROS2_messages23
Connect the Tick output of the On Playback Tick node to the Exec In input of both controller nodes
Driving_TurtleBot_via_ROS2_messages24
Connect the Velocity Command output of the differential controller to the Velocity Command input of the articulation controller. When completed, the graph should look similar to this
Completed
Driving_TurtleBot_via_ROS2_messages24
(8)Play
Press the play button and select the Differential Controller Node in the graph
Click and drag on either the angular or linear velocity values in the properties pane to change it’s value (or just click and type in the desired value)

Putting it Together

Building the graph
(1)Open Visual Scripting:
Window > Visual Scripting > Action Graph
An Action Graph window will appear on the bottom, you can dock it wherever that’s convenient
(2)Click on the New Action Graph Icon in middle of the Action Graph Window
(3)Inside the Action Graph window, there is a panel on the left hand side with all the OmniGraph Nodes (or OG nodes)
All ROS2 related OG nodes are listed under Isaac Ros2. You can also search for nodes by name
To place node into the graph, simply drag it from the node list into the graph window. If all the ROS related nodes are labeled Ros1 not Ros2, it means you have ROS bridge enabled and not ROS2
Go to Windows > Extensions to disable ROS bridge and enabled ROS2 bridge
(4)Build a graph that matches the one below
Driving_TurtleBot_via_ROS2_messages25
Error:

2024-03-20 10:44:29 [2,687,913ms] [Warning] [omni.isaac.dynamic_control.plugin] Failed to find articulation at '/World/turtlebot3_burger'
2024-03-20 10:44:29 [2,687,913ms] [Error] [omni.isaac.dynamic_control.plugin] DcGetArticulationRootBody: Invalid or expired articulation handle
2024-03-20 10:44:29 [2,687,913ms] [Warning] [omni.physx.tensors.plugin] Failed to find articulation at '/World/turtlebot3_burger'
2024-03-20 10:44:29 [2,687,913ms] [Error] [omni.physx.tensors.plugin] Pattern '/World/turtlebot3_burger' did not match any articulations

Looking for solutions
https://forums.developer.nvidia.com/t/errors-following-turtlebot-ros-messages-tutorial-seeking-solutions/287152
Solution:
Changed the target prim to turtlebot3_burger to base_footprint
Made sure the Articulation is enabled and Self Collisions Enabled is unchecked

Files:
https://drive.google.com/file/d/1Y7THmT2JAQXQJPnKsUVfTFfKUMOAgRbu/view?usp=sharing

Verifying ROS connections

(1)Press Play to start ticking the graph and the physics simulation
(2)In a separate ROS-sourced terminal, check that the associated rostopics exist with ros2 topic list

cd ${ISAAC_ROS_WS}/src
cd ${ISAAC_ROS_WS}/src/isaac_ros_common && \
>   ./scripts/run_dev.sh ${ISAAC_ROS_WS}

Driving_TurtleBot_via_ROS2_messages29
Launch the Docker container using the run_dev.sh script

ros2 topic list

Driving_TurtleBot_via_ROS2_messages30
/cmd_vel should be listed in addition to /rosout and /parameter_events
(3)Now that a differential base topic is setup, a twist message can be published to /cmd_vel topic to control the robot. Let’s drive it forward with the command:

ros2 topic pub /cmd_vel geometry_msgs/Twist '{linear:  {x: 0.2, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'

Driving_TurtleBot_via_ROS2_messages31
Recorded the messages
Record the cmd_vel topic

ros2 bag record -o turtlemes1 /cmd_vel

Driving_TurtleBot_via_ROS2_messages32

ros2 bag info turtlemes1

Driving_TurtleBot_via_ROS2_messages33

ros2 bag play turtlemes1

Driving_TurtleBot_via_ROS2_messages36

ros2 topic echo /cmd_vel

Driving_TurtleBot_via_ROS2_messages34
(4)To make it easier for us to move the Turtlebot around, install the teleop_twist_keyboard by running the following command:

#sudo apt-get install ros-$ROS_DISTRO-teleop-twist-keyboard
sudo apt-get install ros-humble-teleop-twist-keyboard

(5)Enable driving using the keyboard by running:

ros2 run teleop_twist_keyboard teleop_twist_keyboard

Driving_TurtleBot_via_ROS2_messages38
Press u
The robot’s rotation is determined by the operation of its left wheel
https://drive.google.com/file/d/1mwYZYNEXNR78N1aG7tpMPVh5un0y5ZwQ/view?usp=sharing
Press i
The robot moves forward in a straight line forward
https://drive.google.com/file/d/1-NrVl6NHmIm-o1Tb8Wg2VrB-6dsZUhzU/view?usp=sharing
Press o
The robot’s rotation is determined by the operation of its right wheel
https://drive.google.com/file/d/19rTTIyPp4cjbbjCbbAI4aHNwmDuuox2m/view?usp=sharing
Press j
The robot advances by rotating its right wheel forward and its left wheel backward
https://drive.google.com/file/d/1KDD_cz72DUGiFyX0RWL6CBxko19Rs2ha/view?usp=sharing
Press k:
The robot stops
Driving_TurtleBot_via_ROS2_messages39
Press l:
The robot advances by rotating its right wheel backward and its left wheel forward
https://drive.google.com/file/d/1KjldLRkOp-HibtflhtqBiG0J7Wdf7qhL/view?usp=sharing
Press m:
The robot advances by rotating both wheels backward
https://drive.google.com/file/d/1rS9d7ghp8n86t6GQm4xuRs2Zaw2EJKEm/view?usp=sharing
Press ,:
The robot moves forward in a straight line backward
https://drive.google.com/file/d/10vn9PA-tTplpFWx8_jUQafpAnu9U0SPC/view?usp=sharing
Press .:
The robot advances by rotating both wheels forward
Overall Process
https://drive.google.com/file/d/1Y_aVK0UkcXx1ehwCajKPudiyxQedBDgI/view?usp=sharing
Press i -> Press ,
Press q by increasing maximum speed

Reference:
https://docs.omniverse.nvidia.com/isaacsim/latest/ros2_tutorials/tutorial_ros2_drive_turtlebot.html