Import external python modules to ISAAC python environment

Hi All,
I wanted to implement a standalone python script which launches a SimulationApp and listens to a rostopic while the world is open.
Obviously, the python.sh can’t find any imports associated with rospy. Now my (probably dumb) question: How can I tell my ISAAC python environment where it can find rospy?
Any help appreciated. Thanks.

Hi @cgoelle2

You can take a look at the following standalone examples that include the import and use of rospy:

  • standalone_examples/api/omni.isaac.ros_bridge/carter_stereo.py
  • standalone_examples/api/omni.isaac.ros_bridge/clock.py
  • standalone_examples/api/omni.isaac.ros_bridge/contact.py
  • standalone_examples/api/omni.isaac.ros_bridge/subscriber.py

Basically, the workflow is:

  1. instantiate the SimulationApp class

    Any Omniverse level imports must occur after the class is instantiated. Because APIs are provided by the extension/runtime plugin system, it must be loaded before they will be available to import.

  2. enable the omni.isaac.ros_bridge extension

  3. check for ROS master

  4. import rospy and other packages/modules


For example:

import carb
from omni.isaac.kit import SimulationApp

simulation_app = SimulationApp({"renderer": "RayTracedLighting", "headless": True})
from omni.isaac.core.utils.extensions import enable_extension

# enable ROS bridge extension
enable_extension("omni.isaac.ros_bridge")

simulation_app.update()

# check if rosmaster node is running
# this is to prevent this sample from waiting indefinetly if roscore is not running
# can be removed in regular usage
import rosgraph

if not rosgraph.is_master_online():
    carb.log_error("Please run roscore before executing this script")
    simulation_app.close()
    exit()

# Note that this is not the system level rospy, but one compiled for omniverse
import rospy

# ...
1 Like

Thank you very much. You can’t imagine how much you helped us!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.