|
8 | 8 | # license agreement from NVIDIA CORPORATION is strictly prohibited.
|
9 | 9 |
|
10 | 10 | import sys
|
| 11 | +import re |
| 12 | +import os |
11 | 13 |
|
12 | 14 | import carb
|
13 | 15 | import numpy as np
|
| 16 | +from pathlib import Path |
14 | 17 | from omni.isaac.kit import SimulationApp
|
15 | 18 |
|
16 | 19 | FRANKA_STAGE_PATH = "/Franka"
|
17 | 20 | FRANKA_USD_PATH = "/Isaac/Robots/Franka/franka_alt_fingers.usd"
|
| 21 | +CAMERA_PRIM_PATH = f"{FRANKA_STAGE_PATH}/panda_hand/geometry/realsense/realsense_camera" |
18 | 22 | BACKGROUND_STAGE_PATH = "/background"
|
19 | 23 | BACKGROUND_USD_PATH = "/Isaac/Environments/Simple_Room/simple_room.usd"
|
| 24 | +GRAPH_PATH = "/ActionGraph" |
| 25 | +REALSENSE_VIEWPORT_NAME = "realsense_viewport" |
20 | 26 |
|
21 | 27 | CONFIG = {"renderer": "RayTracedLighting", "headless": False}
|
22 | 28 |
|
23 | 29 | # Example ROS2 bridge sample demonstrating the manual loading of stages
|
24 | 30 | # and creation of ROS components
|
25 | 31 | 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 |
27 | 35 | from omni.isaac.core import SimulationContext # noqa E402
|
| 36 | +from omni.isaac.core.utils.prims import set_targets |
28 | 37 | from omni.isaac.core.utils import ( # noqa E402
|
29 | 38 | extensions,
|
30 | 39 | nucleus,
|
|
34 | 43 | viewports,
|
35 | 44 | )
|
36 | 45 | 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 |
38 | 49 |
|
39 | 50 | # enable ROS2 bridge extension
|
40 | 51 | extensions.enable_extension("omni.isaac.ros2_bridge")
|
|
65 | 76 | usd_path=assets_root_path + FRANKA_USD_PATH,
|
66 | 77 | )
|
67 | 78 |
|
| 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 | + |
68 | 114 | simulation_app.update()
|
69 | 115 |
|
70 | 116 | # Creating a action graph with ROS component nodes
|
71 | 117 | try:
|
72 | 118 | og.Controller.edit(
|
73 |
| - {"graph_path": "/ActionGraph", "evaluator_name": "execution"}, |
| 119 | + {"graph_path": GRAPH_PATH, "evaluator_name": "execution"}, |
74 | 120 | {
|
75 | 121 | og.Controller.Keys.CREATE_NODES: [
|
76 | 122 | ("OnImpulseEvent", "omni.graph.action.OnImpulseEvent"),
|
|
86 | 132 | "omni.isaac.core_nodes.IsaacArticulationController",
|
87 | 133 | ),
|
88 | 134 | ("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"), |
89 | 145 | ],
|
90 | 146 | og.Controller.Keys.CONNECT: [
|
91 | 147 | ("OnImpulseEvent.outputs:execOut", "PublishJointState.inputs:execIn"),
|
|
119 | 175 | "SubscribeJointState.outputs:effortCommand",
|
120 | 176 | "ArticulationController.inputs:effortCommand",
|
121 | 177 | ),
|
| 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 | + ), |
122 | 204 | ],
|
123 | 205 | og.Controller.Keys.SET_VALUES: [
|
124 |
| - ("Context.inputs:useDomainIDEnvVar", 1), |
| 206 | + ("Context.inputs:domain_id", int(os.environ["ROS_DOMAIN_ID"])), |
125 | 207 | # Setting the /Franka target prim to Articulation Controller node
|
126 | 208 | ("ArticulationController.inputs:usePath", True),
|
127 | 209 | ("ArticulationController.inputs:robotPath", FRANKA_STAGE_PATH),
|
128 | 210 | ("PublishJointState.inputs:topicName", "isaac_joint_states"),
|
129 | 211 | ("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"), |
130 | 223 | ],
|
131 | 224 | },
|
132 | 225 | )
|
|
139 | 232 | primPath="/ActionGraph/PublishJointState", targetPrimPaths=[FRANKA_STAGE_PATH]
|
140 | 233 | )
|
141 | 234 |
|
| 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 | + |
142 | 250 | simulation_app.update()
|
143 | 251 |
|
144 | 252 | # need to initialize physics getting any articulation..etc
|
145 | 253 | simulation_context.initialize_physics()
|
146 | 254 |
|
147 | 255 | simulation_context.play()
|
148 | 256 |
|
| 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 | + |
149 | 263 | while simulation_app.is_running():
|
150 | 264 |
|
151 | 265 | # Run with a fixed step size
|
|
0 commit comments