Skip to content

Commit 6a0bc45

Browse files
authored
update isaac demo with pytorch (#694)
Co-authored-by: PeterMitrano [email protected]
1 parent d7c9361 commit 6a0bc45

File tree

7 files changed

+187
-16
lines changed

7 files changed

+187
-16
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ __pycache__
66
**/_templates
77
**/build
88
**/.vscode
9-
**/.docker
109
*.md
1110
*.rst

doc/how_to_guides/isaac_panda/.docker/Dockerfile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ FROM osrf/ros:humble-desktop-jammy
22

33
SHELL ["/bin/bash", "-c", "-o", "pipefail"]
44

5+
ARG CUDA_MAJOR_VERSION=11
6+
ARG CUDA_MINOR_VERSION=7
7+
58
RUN echo "deb [trusted=yes] https://raw.githubusercontent.com/moveit/moveit2_packages/jammy-humble/ ./" \
69
| sudo tee /etc/apt/sources.list.d/moveit_moveit2_packages.list
710
RUN echo "yaml https://raw.githubusercontent.com/moveit/moveit2_packages/jammy-humble/local.yaml humble" \
@@ -12,9 +15,23 @@ RUN echo "yaml https://raw.githubusercontent.com/moveit/moveit2_packages/jammy-h
1215
RUN apt-get update && apt-get upgrade -y && rosdep update
1316

1417
# Install packages required to run the demo
15-
RUN apt-get install -y --no-install-recommends \
18+
RUN apt-get update && apt-get install -y --no-install-recommends \
1619
ros-humble-moveit \
17-
ros-humble-moveit-resources
20+
ros-humble-moveit-resources \
21+
wget \
22+
python3-pip
23+
24+
# Install CUDA
25+
ENV DEBIAN_FRONTEND noninteractive
26+
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb && \
27+
dpkg -i cuda-keyring_1.0-1_all.deb && \
28+
apt-get update && \
29+
apt-get -y install cuda-cudart-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} cuda-compat-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} cuda-toolkit-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION}
30+
ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH
31+
ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:$LD_LIBRARY_PATH
32+
33+
# Install pytorch
34+
RUN pip3 install torch torchvision
1835

1936
# Create Colcon workspace and clone the needed source code to run the demo
2037
RUN mkdir -p /root/isaac_moveit_tutorial_ws/src
@@ -34,6 +51,10 @@ RUN mkdir -p /opt/.ros
3451
COPY ./doc/how_to_guides/isaac_panda/.docker/fastdds.xml /opt/.ros/fastdds.xml
3552
ENV FASTRTPS_DEFAULT_PROFILES_FILE=/opt/.ros/fastdds.xml
3653

54+
ENV NVIDIA_VISIBLE_DEVICES all
55+
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
56+
ENV NVIDIA_REQUIRE_CUDA "cuda>=${CUDA_MAJOR_VERSION}.${CUDA_MINOR_VERSION}"
57+
3758
# Build the Colcon workspace for the user
3859
RUN source /opt/ros/humble/setup.bash && colcon build
3960

doc/how_to_guides/isaac_panda/docker-compose.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,21 @@ services:
3535
# Allows graphical programs in the container
3636
- /tmp/.X11-unix:/tmp/.X11-unix:rw
3737
- ${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority
38-
demo_isaac:
38+
39+
# Use this service if you want to run the moveit container on a computer without a GPU
40+
# You will still be able to use pytorch, but you will not be able to use the GPU.
41+
demo_isaac_no_gpu:
3942
extends: base
4043
command: ros2 launch moveit2_tutorials isaac_demo.launch.py
44+
4145
demo_mock_components:
4246
extends: base
4347
command: ros2 launch moveit2_tutorials isaac_demo.launch.py ros2_control_hardware_type:=mock_components
48+
49+
demo_isaac:
50+
extends: demo_isaac_no_gpu
51+
deploy:
52+
resources:
53+
reservations:
54+
devices:
55+
- capabilities: [gpu]

doc/how_to_guides/isaac_panda/isaac_panda_tutorial.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
How To Command Simulated Isaac Robot
22
====================================
33

4-
This tutorial requires a machine with ``Isaac Sim 2022.2.0`` installed.
4+
This tutorial requires a machine with ``Isaac Sim 2022.2.0`` or ``Isaac Sim 2022.2.1`` installed.
55
For Isaac Sim requirements and installation please see the `Omniverse documentation <https://docs.omniverse.nvidia.com/app_isaacsim/app_isaacsim/overview.html>`_.
66

77
This tutorial has the following assumptions on system configuration:
88

9-
1. NVIDIA Isaac Sim 2022.2.0 is installed on a Ubuntu 20.04 host in the ``$HOME/.local/share/ov/pkg/isaac_sim-2022.2.0`` directory. (this is the default location)
9+
1. NVIDIA Isaac Sim 2022.2.0 or 2022.2.1 is installed on a Ubuntu 20.04 host in the default location.
1010
2. Docker is installed.
11+
If you plan to use your GPU with MoveIt, you will need to install `nvidia-docker <https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#installing-on-ubuntu-and-debian>`_.
1112
3. You clone this repo so that you can build a Ubuntu 22.04 Humble based Docker image that can communicate with Isaac and run this tutorial.
1213

1314
Introduction to ros2_control
@@ -57,6 +58,9 @@ updated to load the ``TopicBasedSystem`` plugin when the flag ``ros2_control_har
5758
In this tutorial we have included a Python script that loads a Panda robot
5859
and builds an `OmniGraph <https://docs.omniverse.nvidia.com/prod_extensions/prod_extensions/ext_omnigraph.html>`_
5960
to publish and subscribe to the ROS topics used to control the robot.
61+
The OmniGraph also contains nodes to publish RGB and Depth images from the camera mounted on the hand of the Panda.
62+
The RGB image is published to the topic ``/rgb``, the camera info to ``/camera_info``, and the depth image to ``/depth``.
63+
The frame ID of the camera frame is ``/sim_camera``.
6064
To learn about configuring your Isaac Sim robot to communicate with ROS 2 please see the
6165
`Joint Control tutorial <https://docs.omniverse.nvidia.com/app_isaacsim/app_isaacsim/tutorial_ros2_manipulation.html>`_
6266
on Omniverse.
@@ -78,15 +82,18 @@ Computer Setup
7882
7983
cd moveit2_tutorials/doc/how_to_guides/isaac_panda
8084
81-
4. Build the Docker image.
85+
4. Build the Docker image. This docker image also contains ``pytorch``.
8286

8387
.. code-block:: bash
8488
85-
docker compose build
89+
docker compose build base
90+
8691
8792
Running the MoveIt Interactive Marker Demo with Mock Components
8893
---------------------------------------------------------------
8994

95+
This section tests out the ``mock_components/GenericSystem`` hardware interface, as opposed to using Isaac Sim.
96+
9097
1. To test out the ``mock_components/GenericSystem`` hardware interface run:
9198

9299
.. code-block:: bash
@@ -111,7 +118,7 @@ Running the MoveIt Interactive Marker Demo with Isaac Sim
111118
112119
2. Then run the following command to load the Panda Robot pre-configured to work with this tutorial.
113120

114-
.. note:: This step assumes Isaac Sim is installed on the host in the ``$HOME/.local/share/ov/pkg/isaac_sim-2022.2.0" directory``.
121+
.. note:: This step assumes Isaac Sim version 2022.2.0 or 2022.2.1 is installed on the host in the ``$HOME/.local/share/ov/pkg/" directory``.
115122
This step also takes a few minutes to download the assets and setup Isaac Sim so please be
116123
patient and don't click the ``Force Quit`` dialog that pops up while the simulator starts.
117124

@@ -130,5 +137,5 @@ This will open up RViz with the Panda robot using the ``TopicBasedSystem`` inter
130137
.. raw:: html
131138

132139
<div style="position: relative; padding-bottom: 5%; height: 0; overflow: hidden; max-width: 100%; height: auto;">
133-
<iframe width="700px" height="400px" src="https://www.youtube.com/embed/af3zkAOWk2Q" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
140+
<iframe width="700px" height="400px" src="https://www.youtube.com/embed/EiLaJ7e4M-4" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
134141
</div>

doc/how_to_guides/isaac_panda/launch/isaac_demo.launch.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,29 @@ def generate_launch_description():
6868
)
6969

7070
# Static TF
71-
static_tf_node = Node(
71+
world2robot_tf_node = Node(
7272
package="tf2_ros",
7373
executable="static_transform_publisher",
7474
name="static_transform_publisher",
7575
output="log",
7676
arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "panda_link0"],
7777
)
78+
hand2camera_tf_node = Node(
79+
package="tf2_ros",
80+
executable="static_transform_publisher",
81+
name="static_transform_publisher",
82+
output="log",
83+
arguments=[
84+
"0.04",
85+
"0.0",
86+
"0.04",
87+
"0.0",
88+
"0.0",
89+
"0.0",
90+
"panda_hand",
91+
"sim_camera",
92+
],
93+
)
7894

7995
# Publish TF
8096
robot_state_publisher = Node(
@@ -124,7 +140,8 @@ def generate_launch_description():
124140
[
125141
ros2_control_hardware_type,
126142
rviz_node,
127-
static_tf_node,
143+
world2robot_tf_node,
144+
hand2camera_tf_node,
128145
robot_state_publisher,
129146
move_group_node,
130147
ros2_control_node,

doc/how_to_guides/isaac_panda/launch/isaac_moveit.py

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,32 @@
88
# license agreement from NVIDIA CORPORATION is strictly prohibited.
99

1010
import sys
11+
import re
12+
import os
1113

1214
import carb
1315
import numpy as np
16+
from pathlib import Path
1417
from omni.isaac.kit import SimulationApp
1518

1619
FRANKA_STAGE_PATH = "/Franka"
1720
FRANKA_USD_PATH = "/Isaac/Robots/Franka/franka_alt_fingers.usd"
21+
CAMERA_PRIM_PATH = f"{FRANKA_STAGE_PATH}/panda_hand/geometry/realsense/realsense_camera"
1822
BACKGROUND_STAGE_PATH = "/background"
1923
BACKGROUND_USD_PATH = "/Isaac/Environments/Simple_Room/simple_room.usd"
24+
GRAPH_PATH = "/ActionGraph"
25+
REALSENSE_VIEWPORT_NAME = "realsense_viewport"
2026

2127
CONFIG = {"renderer": "RayTracedLighting", "headless": False}
2228

2329
# Example ROS2 bridge sample demonstrating the manual loading of stages
2430
# and creation of ROS components
2531
simulation_app = SimulationApp(CONFIG)
26-
import omni.graph.core as og # noqa E402
32+
33+
34+
# More imports that need to compare after we create the app
2735
from omni.isaac.core import SimulationContext # noqa E402
36+
from omni.isaac.core.utils.prims import set_targets
2837
from omni.isaac.core.utils import ( # noqa E402
2938
extensions,
3039
nucleus,
@@ -34,7 +43,9 @@
3443
viewports,
3544
)
3645
from omni.isaac.core_nodes.scripts.utils import set_target_prims # noqa E402
37-
from pxr import Gf # noqa E402
46+
from pxr import Gf, UsdGeom # noqa E402
47+
import omni.graph.core as og # noqa E402
48+
import omni
3849

3950
# enable ROS2 bridge extension
4051
extensions.enable_extension("omni.isaac.ros2_bridge")
@@ -65,12 +76,47 @@
6576
usd_path=assets_root_path + FRANKA_USD_PATH,
6677
)
6778

79+
# add some objects, spread evenly along the X axis
80+
# with a fixed offset from the robot in the Y and Z
81+
prims.create_prim(
82+
"/cracker_box",
83+
"Xform",
84+
position=np.array([-0.2, -0.25, 0.15]),
85+
orientation=rotations.gf_rotation_to_np_array(Gf.Rotation(Gf.Vec3d(1, 0, 0), -90)),
86+
usd_path=assets_root_path
87+
+ "/Isaac/Props/YCB/Axis_Aligned_Physics/003_cracker_box.usd",
88+
)
89+
prims.create_prim(
90+
"/sugar_box",
91+
"Xform",
92+
position=np.array([-0.07, -0.25, 0.1]),
93+
orientation=rotations.gf_rotation_to_np_array(Gf.Rotation(Gf.Vec3d(0, 1, 0), -90)),
94+
usd_path=assets_root_path
95+
+ "/Isaac/Props/YCB/Axis_Aligned_Physics/004_sugar_box.usd",
96+
)
97+
prims.create_prim(
98+
"/soup_can",
99+
"Xform",
100+
position=np.array([0.1, -0.25, 0.10]),
101+
orientation=rotations.gf_rotation_to_np_array(Gf.Rotation(Gf.Vec3d(1, 0, 0), -90)),
102+
usd_path=assets_root_path
103+
+ "/Isaac/Props/YCB/Axis_Aligned_Physics/005_tomato_soup_can.usd",
104+
)
105+
prims.create_prim(
106+
"/mustard_bottle",
107+
"Xform",
108+
position=np.array([0.0, 0.15, 0.12]),
109+
orientation=rotations.gf_rotation_to_np_array(Gf.Rotation(Gf.Vec3d(1, 0, 0), -90)),
110+
usd_path=assets_root_path
111+
+ "/Isaac/Props/YCB/Axis_Aligned_Physics/006_mustard_bottle.usd",
112+
)
113+
68114
simulation_app.update()
69115

70116
# Creating a action graph with ROS component nodes
71117
try:
72118
og.Controller.edit(
73-
{"graph_path": "/ActionGraph", "evaluator_name": "execution"},
119+
{"graph_path": GRAPH_PATH, "evaluator_name": "execution"},
74120
{
75121
og.Controller.Keys.CREATE_NODES: [
76122
("OnImpulseEvent", "omni.graph.action.OnImpulseEvent"),
@@ -86,6 +132,16 @@
86132
"omni.isaac.core_nodes.IsaacArticulationController",
87133
),
88134
("PublishClock", "omni.isaac.ros2_bridge.ROS2PublishClock"),
135+
("OnTick", "omni.graph.action.OnTick"),
136+
("createViewport", "omni.isaac.core_nodes.IsaacCreateViewport"),
137+
(
138+
"getRenderProduct",
139+
"omni.isaac.core_nodes.IsaacGetViewportRenderProduct",
140+
),
141+
("setCamera", "omni.isaac.core_nodes.IsaacSetCameraOnRenderProduct"),
142+
("cameraHelperRgb", "omni.isaac.ros2_bridge.ROS2CameraHelper"),
143+
("cameraHelperInfo", "omni.isaac.ros2_bridge.ROS2CameraHelper"),
144+
("cameraHelperDepth", "omni.isaac.ros2_bridge.ROS2CameraHelper"),
89145
],
90146
og.Controller.Keys.CONNECT: [
91147
("OnImpulseEvent.outputs:execOut", "PublishJointState.inputs:execIn"),
@@ -119,14 +175,51 @@
119175
"SubscribeJointState.outputs:effortCommand",
120176
"ArticulationController.inputs:effortCommand",
121177
),
178+
("OnTick.outputs:tick", "createViewport.inputs:execIn"),
179+
("createViewport.outputs:execOut", "getRenderProduct.inputs:execIn"),
180+
("createViewport.outputs:viewport", "getRenderProduct.inputs:viewport"),
181+
("getRenderProduct.outputs:execOut", "setCamera.inputs:execIn"),
182+
(
183+
"getRenderProduct.outputs:renderProductPath",
184+
"setCamera.inputs:renderProductPath",
185+
),
186+
("setCamera.outputs:execOut", "cameraHelperRgb.inputs:execIn"),
187+
("setCamera.outputs:execOut", "cameraHelperInfo.inputs:execIn"),
188+
("setCamera.outputs:execOut", "cameraHelperDepth.inputs:execIn"),
189+
("Context.outputs:context", "cameraHelperRgb.inputs:context"),
190+
("Context.outputs:context", "cameraHelperInfo.inputs:context"),
191+
("Context.outputs:context", "cameraHelperDepth.inputs:context"),
192+
(
193+
"getRenderProduct.outputs:renderProductPath",
194+
"cameraHelperRgb.inputs:renderProductPath",
195+
),
196+
(
197+
"getRenderProduct.outputs:renderProductPath",
198+
"cameraHelperInfo.inputs:renderProductPath",
199+
),
200+
(
201+
"getRenderProduct.outputs:renderProductPath",
202+
"cameraHelperDepth.inputs:renderProductPath",
203+
),
122204
],
123205
og.Controller.Keys.SET_VALUES: [
124-
("Context.inputs:useDomainIDEnvVar", 1),
206+
("Context.inputs:domain_id", int(os.environ["ROS_DOMAIN_ID"])),
125207
# Setting the /Franka target prim to Articulation Controller node
126208
("ArticulationController.inputs:usePath", True),
127209
("ArticulationController.inputs:robotPath", FRANKA_STAGE_PATH),
128210
("PublishJointState.inputs:topicName", "isaac_joint_states"),
129211
("SubscribeJointState.inputs:topicName", "isaac_joint_commands"),
212+
("createViewport.inputs:name", REALSENSE_VIEWPORT_NAME),
213+
("createViewport.inputs:viewportId", 1),
214+
("cameraHelperRgb.inputs:frameId", "sim_camera"),
215+
("cameraHelperRgb.inputs:topicName", "rgb"),
216+
("cameraHelperRgb.inputs:type", "rgb"),
217+
("cameraHelperInfo.inputs:frameId", "sim_camera"),
218+
("cameraHelperInfo.inputs:topicName", "camera_info"),
219+
("cameraHelperInfo.inputs:type", "camera_info"),
220+
("cameraHelperDepth.inputs:frameId", "sim_camera"),
221+
("cameraHelperDepth.inputs:topicName", "depth"),
222+
("cameraHelperDepth.inputs:type", "depth"),
130223
],
131224
},
132225
)
@@ -139,13 +232,34 @@
139232
primPath="/ActionGraph/PublishJointState", targetPrimPaths=[FRANKA_STAGE_PATH]
140233
)
141234

235+
# Fix camera settings since the defaults in the realsense model are inaccurate
236+
realsense_prim = camera_prim = UsdGeom.Camera(
237+
stage.get_current_stage().GetPrimAtPath(CAMERA_PRIM_PATH)
238+
)
239+
realsense_prim.GetHorizontalApertureAttr().Set(20.955)
240+
realsense_prim.GetVerticalApertureAttr().Set(15.7)
241+
realsense_prim.GetFocalLengthAttr().Set(18.8)
242+
realsense_prim.GetFocusDistanceAttr().Set(400)
243+
244+
set_targets(
245+
prim=stage.get_current_stage().GetPrimAtPath(GRAPH_PATH + "/setCamera"),
246+
attribute="inputs:cameraPrim",
247+
target_prim_paths=[CAMERA_PRIM_PATH],
248+
)
249+
142250
simulation_app.update()
143251

144252
# need to initialize physics getting any articulation..etc
145253
simulation_context.initialize_physics()
146254

147255
simulation_context.play()
148256

257+
# Dock the second camera window
258+
viewport = omni.ui.Workspace.get_window("Viewport")
259+
rs_viewport = omni.ui.Workspace.get_window(REALSENSE_VIEWPORT_NAME)
260+
rs_viewport.dock_in(viewport, omni.ui.DockPosition.RIGHT)
261+
262+
149263
while simulation_app.is_running():
150264

151265
# Run with a fixed step size

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<exec_depend>xacro</exec_depend>
6262

6363
<test_depend>ament_cmake_gtest</test_depend>
64+
<test_depend>ros_testing</test_depend>
6465

6566
<export>
6667
<build_type>ament_cmake</build_type>

0 commit comments

Comments
 (0)