2. Hello Robot

2.1. Learning Objectives

This tutorial details how to add and move a mobile robot in Omniverse Isaac Sim in an extension application. After this tutorial, you will understand how to add a robot to the simulation and apply actions to its wheels using Python.

10-15 Minute Tutorial

2.2. Getting Started

Prerequisites

Begin with the source code of the Awesome Example developed in the previous tutorial: Hello World.

2.3. Adding a Robot

Begin by adding a NVIDIA Jetbot to the scene, which allows you to access the library of Omniverse Isaac Sim robots, sensors, and environments located on a Omniverse Nucleus Server using Python, as well as navigate through it using the Content window.

Note

The server shown in these steps has been connected to in Isaac Sim First Run. Follow these steps first before proceeding.

  1. Add the assets by simply dragging them to the stage window or the viewport.

  2. Try to do the same thing through Python in the Awesome Example.

  3. Create a new stage: File > new > Don’t Save

  4. Open the extension_examples/user_examples/hello_world.py file by clicking the Open Source Code button in the Awesome Example window.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    from omni.isaac.examples.base_sample import BaseSample
    from omni.isaac.core.utils.nucleus import get_assets_root_path
    from omni.isaac.core.utils.stage import add_reference_to_stage
    from omni.isaac.core.robots import Robot
    import carb
    
    
    class HelloWorld(BaseSample):
        def __init__(self) -> None:
            super().__init__()
            return
    
        def setup_scene(self):
            world = self.get_world()
            world.scene.add_default_ground_plane()
            # Use the find_nucleus_server instead of changing it every time
            # you configure a new server with /Isaac folder in it
            assets_root_path = get_assets_root_path()
            if assets_root_path is None:
                # Use carb to log warnings, errors and infos in your application (shown on terminal)
                carb.log_error("Could not find nucleus server with /Isaac folder")
            asset_path = assets_root_path + "/Isaac/Robots/Jetbot/jetbot.usd"
            # This will create a new XFormPrim and point it to the usd file as a reference
            # Similar to how pointers work in memory
            add_reference_to_stage(usd_path=asset_path, prim_path="/World/Fancy_Robot")
            # Wrap the jetbot prim root under a Robot class and add it to the Scene
            # to use high level api to set/ get attributes as well as initializing
            # physics handles needed..etc.
            # Note: this call doesn't create the Jetbot in the stage window, it was already
            # created with the add_reference_to_stage
            jetbot_robot = world.scene.add(Robot(prim_path="/World/Fancy_Robot", name="fancy_robot"))
            # Note: before a reset is called, we can't access information related to an Articulation
            # because physics handles are not initialized yet. setup_post_load is called after
            # the first reset so we can do so there
            print("Num of degrees of freedom before first reset: " + str(jetbot_robot.num_dof)) # prints None
            return
    
        async def setup_post_load(self):
            self._world = self.get_world()
            self._jetbot = self._world.scene.get_object("fancy_robot")
            # Print info about the jetbot after the first reset is called
            print("Num of degrees of freedom after first reset: " + str(self._jetbot.num_dof)) # prints 2
            print("Joint Positions after first reset: " + str(self._jetbot.get_joint_positions()))
            return
    

Press the PLAY button to start simulating the robot. Although it is being simulated, it is not moving. The next section walks through how to make the robot move.

2.4. Move the Robot

In Omniverse Isaac Sim, Robots are constructed of physically accurate articulated joints. Applying actions to these articulations make them move.

Next, apply random velocities to the Jetbot articulation controller to get it moving.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from omni.isaac.examples.base_sample import BaseSample
from omni.isaac.core.utils.types import ArticulationAction
from omni.isaac.core.utils.nucleus import get_assets_root_path
from omni.isaac.core.utils.stage import add_reference_to_stage
from omni.isaac.core.robots import Robot
import numpy as np
import carb


class HelloWorld(BaseSample):
    def __init__(self) -> None:
        super().__init__()
        return

    def setup_scene(self):
        world = self.get_world()
        world.scene.add_default_ground_plane()
        assets_root_path = get_assets_root_path()
        if assets_root_path is None:
            carb.log_error("Could not find nucleus server with /Isaac folder")
        asset_path = assets_root_path + "/Isaac/Robots/Jetbot/jetbot.usd"
        add_reference_to_stage(usd_path=asset_path, prim_path="/World/Fancy_Robot")
        jetbot_robot = world.scene.add(Robot(prim_path="/World/Fancy_Robot", name="fancy_robot"))
        return

    async def setup_post_load(self):
        self._world = self.get_world()
        self._jetbot = self._world.scene.get_object("fancy_robot")
        # This is an implicit PD controller of the jetbot/ articulation
        # setting PD gains, applying actions, switching control modes..etc.
        # can be done through this controller.
        # Note: should be only called after the first reset happens to the world
        self._jetbot_articulation_controller = self._jetbot.get_articulation_controller()
        # Adding a physics callback to send the actions to apply actions with every
        # physics step executed.
        self._world.add_physics_callback("sending_actions", callback_fn=self.send_robot_actions)
        return

    def send_robot_actions(self, step_size):
        # Every articulation controller has apply_action method
        # which takes in ArticulationAction with joint_positions, joint_efforts and joint_velocities
        # as optional args. It accepts numpy arrays of floats OR lists of floats and None
        # None means that nothing is applied to this dof index in this step
        # ALTERNATIVELY, same method is called from self._jetbot.apply_action(...)
        self._jetbot_articulation_controller.apply_action(ArticulationAction(joint_positions=None,
                                                                            joint_efforts=None,
                                                                            joint_velocities=5 * np.random.rand(2,)))
        return

Press the PLAY button to start simulating the robot.

Note

Pressing STOP, then PLAY in this workflow might not reset the world properly. Use the RESET button instead.

2.4.1. Extra Practice

This example applies random velocities to the Jetbot articulation controller. Try the following exercises:

  1. Make the Jetbot move backwards.

  2. Make the Jetbot turn right.

  3. Make the Jetbot stop after 5 seconds.

2.5. Using the WheeledRobot Class

Omniverse Isaac Sim also has robot-specific extensions that provide further customized functions and access to other controllers and tasks (more on this later). Now you’ll re-write the previous code using the WheeledRobot class to make it simpler.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from omni.isaac.examples.base_sample import BaseSample
from omni.isaac.core.utils.nucleus import get_assets_root_path
from omni.isaac.wheeled_robots.robots import WheeledRobot
from omni.isaac.core.utils.types import ArticulationAction
import numpy as np


class HelloWorld(BaseSample):
    def __init__(self) -> None:
        super().__init__()
        return

    def setup_scene(self):
        world = self.get_world()
        world.scene.add_default_ground_plane()
        assets_root_path = get_assets_root_path()
        jetbot_asset_path = assets_root_path + "/Isaac/Robots/Jetbot/jetbot.usd"
        self._jetbot = world.scene.add(
            WheeledRobot(
                prim_path="/World/Fancy_Robot",
                name="fancy_robot",
                wheel_dof_names=["left_wheel_joint", "right_wheel_joint"],
                create_robot=True,
                usd_path=jetbot_asset_path,
            )
        )
        return

    async def setup_post_load(self):
        self._world = self.get_world()
        self._jetbot = self._world.scene.get_object("fancy_robot")
        self._world.add_physics_callback("sending_actions", callback_fn=self.send_robot_actions)
        return

    def send_robot_actions(self, step_size):
        self._jetbot.apply_wheel_actions(ArticulationAction(joint_positions=None,
                                                            joint_efforts=None,
                                                            joint_velocities=5 * np.random.rand(2,)))
        return

2.6. Summary

This tutorial covered the following topics:

  1. Adding Omniverse Isaac Sim library components from a Nucleus Server

  2. Adding a Robot to the World

  3. Using a joint-level controller to articulate a Robot

  4. Using Robot classes

  5. Using Robot specific extensions

2.6.1. Next Steps

Continue on to the next tutorial in the Essential Tutorials series, Adding A Controller, to learn how to add a controller to Jetbot.

2.6.2. Further Learning

Nucleus Server

Robot Specific Extensions

  • Omniverse Isaac Sim provides several robot extensions such as omni.isaac.franka, omni.isaac.universal_robots, and many more. To learn more, check out the standalone examples located at standalone_examples/api/omni.isaac.franka and standalone_examples/api/omni.isaac.universal_robots/.