From 855bdd6b5742a7811dcf2552665ee92b8c99f59b Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Tue, 10 Sep 2024 02:29:39 +0800 Subject: [PATCH] refactor(aloha_ws): Remove redundant code --- aloha_ws/README.md | 5 +++- .../scripts/create_vx300s_from_urdf.py | 23 ++++----------- .../scripts/create_vx300s_with_omnigraph.py | 28 ++++--------------- 3 files changed, 15 insertions(+), 41 deletions(-) diff --git a/aloha_ws/README.md b/aloha_ws/README.md index 6e34f010..c8de8abb 100644 --- a/aloha_ws/README.md +++ b/aloha_ws/README.md @@ -53,7 +53,10 @@ isaacsim omni.isaac.sim Open pre-configured USD file with OmniGraph: -- `File > Open` and in `File name:` type `/home/ros2-essentials/aloha_ws/isaacsim/assets/vx300s_og.usd` +- `File > Open` and in `File name:` type: + ``` + /home/ros2-essentials/aloha_ws/isaacsim/assets/vx300s_og.usd + ``` - Click `Window > Visual Scripting > Action Graph` - In the `Action Graph` tab, click `Edit Action Graph` and select `/ActionGraph` - Click `Play (SPACE)` diff --git a/aloha_ws/isaacsim/scripts/create_vx300s_from_urdf.py b/aloha_ws/isaacsim/scripts/create_vx300s_from_urdf.py index 4116cfc5..1da2555b 100644 --- a/aloha_ws/isaacsim/scripts/create_vx300s_from_urdf.py +++ b/aloha_ws/isaacsim/scripts/create_vx300s_from_urdf.py @@ -6,33 +6,19 @@ # Ref: https://docs.omniverse.nvidia.com/isaacsim/latest/advanced_tutorials/tutorial_advanced_import_urdf.html#importing-urdf-using-python -import asyncio import logging import os import omni.kit.commands import omni.usd from omni.importer.urdf import _urdf -from omni.kit import ui_test from pxr import UsdPhysics +# Ref: https://docs.omniverse.nvidia.com/kit/docs/kit-manual/latest/guide/logging.html +# `print(...)` outputs to Script Editor, while `logger.info(...)` outputs to console. logger = logging.getLogger(__name__) -def log(msg): - # Print to console - # Ref: https://docs.omniverse.nvidia.com/kit/docs/kit-manual/latest/guide/logging.html - logger.info(msg) - # Print to Script Editor - print(msg) - -async def create_new_stage_with_defaults(): - menu_widget = ui_test.get_menubar() - await menu_widget.find_menu("File").click() - await menu_widget.find_menu("New").click() - log("Done!") - simulation_app.close() - def create_vx300s_from_urdf(urdf_path, usd_path): # Set the settings in the import config import_config = _urdf.ImportConfig() @@ -61,8 +47,9 @@ def create_vx300s_from_urdf(urdf_path, usd_path): omni.usd.get_context().save_stage() if __name__ == '__main__': - print("Creating `vx300s.usd` from urdf...") vx300s_urdf_path = f'{os.path.expanduser("~")}/interbotix_ws/src/interbotix_ros_manipulators/interbotix_ros_xsarms/interbotix_xsarm_descriptions/urdf/vx300s.urdf' vx300s_usd_path = '/home/ros2-essentials/aloha_ws/isaacsim/assets/vx300s_urdf.usd' create_vx300s_from_urdf(vx300s_urdf_path, vx300s_usd_path) - asyncio.ensure_future(create_new_stage_with_defaults()) + print("Done") + logger.info("Done") + simulation_app.close() diff --git a/aloha_ws/isaacsim/scripts/create_vx300s_with_omnigraph.py b/aloha_ws/isaacsim/scripts/create_vx300s_with_omnigraph.py index 66ac4cbe..dc312d21 100644 --- a/aloha_ws/isaacsim/scripts/create_vx300s_with_omnigraph.py +++ b/aloha_ws/isaacsim/scripts/create_vx300s_with_omnigraph.py @@ -9,18 +9,12 @@ import omni.graph.core as og import omni.kit.app import omni.usd -from omni.isaac.core import World +# Ref: https://docs.omniverse.nvidia.com/kit/docs/kit-manual/latest/guide/logging.html +# `print(...)` outputs to Script Editor, while `logger.info(...)` outputs to console. logger = logging.getLogger(__name__) -def log(msg): - # Print to console - # Ref: https://docs.omniverse.nvidia.com/kit/docs/kit-manual/latest/guide/logging.html - logger.info(msg) - # Print to Script Editor - print(msg) - def create_vx300s_with_omnigraph(): # Create vx300s vx300s_prim_path = "/World/vx300s_urdf" @@ -72,22 +66,12 @@ def create_vx300s_with_omnigraph(): if __name__ == '__main__': # Ref: https://docs.omniverse.nvidia.com/dev-guide/latest/programmer_ref/extensions/enable-kit-extension.html manager = omni.kit.app.get_app().get_extension_manager() - # enable immediately manager.set_extension_enabled_immediate("omni.isaac.ros2_bridge", True) - log("ros2_bridge enabled: " + str(manager.is_extension_enabled("omni.isaac.ros2_bridge"))) + print("ros2_bridge enabled: " + str(manager.is_extension_enabled("omni.isaac.ros2_bridge"))) + logger.info("ros2_bridge enabled: " + str(manager.is_extension_enabled("omni.isaac.ros2_bridge"))) create_vx300s_with_omnigraph() vx300s_og_usd_path = '/home/ros2-essentials/aloha_ws/isaacsim/assets/vx300s_og.usd' omni.usd.get_context().save_as_stage(vx300s_og_usd_path) - log("Done!") - # # Ref: `~/.local/share/ov/pkg/isaac-sim-4.1.0/standalone_examples/api/omni.isaac.franka/follow_target_with_rmpflow.py` - # my_world = World(stage_units_in_meters=1.0) - # reset_needed = False - # while simulation_app.is_running(): - # my_world.step(render=True) - # if my_world.is_stopped() and not reset_needed: - # reset_needed = True - # if my_world.is_playing(): - # if reset_needed: - # my_world.reset() - # reset_needed = False + print("Done") + logger.info("Done") simulation_app.close()