How to use keyboard control a robot in a python standalong application

The example here:
https://docs.omniverse.nvidia.com/app_isaacsim/app_isaacsim/tutorial_advanced_keyboard_control.html
shows how to control a robot by keyboard in Extension.
But how to do this in a python standalong application?

Hi @user93379

You can control a robot by keyboard in a standalone application in the same way you control it in an extension.

The following code shows an example. It is a simple adaptation of the jetbot_move.py standalone application example (at PATH_TO_ISAAC_SIM/standalone_examples/api/omni.isaac.jetbot/jetbot_move.py) to support keyboard control using the same code that you mentioned in your post…


from omni.isaac.kit import SimulationApp

simulation_app = SimulationApp({"headless": False})

import omni
import carb

from omni.isaac.jetbot import Jetbot
from omni.isaac.core import World
from omni.isaac.jetbot.controllers import DifferentialController
import numpy as np


_command = [0.0, 0.0]

def _sub_keyboard_event(event, *args, **kwargs):
    global _command
    if (event.type == carb.input.KeyboardEventType.KEY_PRESS
        or event.type == carb.input.KeyboardEventType.KEY_REPEAT):
        if event.input == carb.input.KeyboardInput.W:
            _command = [20, 0.0]
        if event.input == carb.input.KeyboardInput.S:
            _command = [-20, 0.0]
        if event.input == carb.input.KeyboardInput.A:
            _command = [0.0, np.pi / 5]
        if event.input == carb.input.KeyboardInput.D:
            _command = [0.0, -np.pi / 5]
    if event.type == carb.input.KeyboardEventType.KEY_RELEASE:
        _command = [0.0, 0.0]

# subscribe to keyboard events
appwindow = omni.appwindow.get_default_app_window()
input = carb.input.acquire_input_interface()
input.subscribe_to_keyboard_events(appwindow.get_keyboard(), _sub_keyboard_event)

my_world = World(stage_units_in_meters=0.01)
my_jetbot = my_world.scene.add(Jetbot(prim_path="/World/Jetbot", name="my_jetbot", position=np.array([0, 0.0, 2.0])))
my_world.scene.add_default_ground_plane()
my_controller = DifferentialController(name="simple_control")
my_world.reset()


while simulation_app.is_running():
    my_world.step(render=True)
    if my_world.is_playing():
        if my_world.current_time_step_index == 0:
            my_world.reset()
            my_controller.reset()

        my_jetbot.apply_wheel_actions(my_controller.forward(command=_command))

simulation_app.close()
1 Like

Thanks very much for your reply. I have done this sccessfully.