6. Debugging With Visual Studio Code

6.1. Learning Objectives

In this tutorial, we will go over

  • Debugging a standalone python script

  • Attaching to the omni.kit.debug.vscode_debugger extension to debug a running instance of Isaac Sim

6.2. Standalone Python Scripts

  1. From the Isaac Sim App Selector click the “Open in Terminal” button, then execute the following command: code . This launches a new VS Code window and opens the current folder. You can also launch VS Code and open the folder.

  2. Let’s try debugging a a simple script, open standalone_examples/api/omni.isaac.kit/hello_world.py and place a breakpoint.

  3. Select the “Run” icon from the toolbar on the left, and ensure “Current File” is selected from the configuration dropdown menu.

  4. Click “Start Debugging” or press F5 to launch the debugger. Pressing F10 will step line by line. You can mouse over to examine variable values.

    ../_images/isaac_vscode_standalone_debug.png
  5. Let’s try passing a command line argument to our code, in the “args” field of the .vscode/launch.json file. For example here we change the default nucleus server

        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "env": {
                "EXP_PATH": "${workspaceFolder}/apps",
                "RESOURCE_NAME": "IsaacSim"
            },
            "python": "${workspaceFolder}/kit/python/bin/python3",
            "envFile": "${workspaceFolder}/.vscode/.standalone_examples.env",
            "preLaunchTask": "setup_python_env",
            "args": ["--/isaac/nucleus/default=\"omniverse://my_server\""]
        }
    
  6. Add the following lines to hello_world.py and place a breakpoint on the print(server_check) line.

        # The most basic usage for creating a simulation app
        kit = SimulationApp()
    
        import carb
        server_check = carb.settings.get_settings().get_as_string("/isaac/nucleus/default")
        print(server_check)
    
        for i in range(100):
            kit.update()
    
        kit.close()  # Cleanup application
    
  7. After modifying and saving the launch.json, press F5 to launch the debugger.

  8. Verify that the variable contains the server set in the args in launch.json

    ../_images/isaac_vscode_standalone_inspect.png

6.3. Attaching the Debugger to a Running App

To debug a script that you are already running, use the VS Code Debugger extension.

  1. From the top toolbar select Window > Extensions. Then search for “vscode” and click the Enable button for the omni.kit.debug.vscode extension. By default, the status will show “VS Code Debugger Unattached”, in red text.

    ../_images/isaac_vscode_debug_extension.png
  2. Then launch VS Code, and select the “Run” icon from the toolbar on the left.

  3. From the configuration menu, select “Python: Attach (windows-x86_64/linux-x86_64) and click the green arrow to start debugging.

  4. Notice that the status in Isaac Sim changes to “VS Code Debugger Attached” in blue text.

    ../_images/isaac_vscode_debug_attach.png
  5. You can now return to your python file in VS Code and add breakpoints to debug, as described above.

Note

To configure the host and port used for debugging the following command line arguments can be provided

--/exts/omni.kit.debug.python/host="127.0.0.1"
--/exts/omni.kit.debug.python/port=3000

These should match the configuration in your vscode launch.json

    {
        "name": "Python: Attach (windows-x86_64/linux-x86_64)",
        "type": "python",
        "request": "attach",
        "port": 3000,
        "host": "127.0.0.1"
    },

6.4. Summary

In this tutorial, we covered

  1. How to debug a standalone python script

  2. How to attach the vscode debugger to a running instance of Isaac Sim

6.4.1. Further Learning

For a more details about how the vscode integration works see Visual Studio Code (VSCode) Support