irsim.gui.keyboard_control#
Attributes#
Classes#
Keyboard input handler for IR-SIM with dual backends. |
Module Contents#
- irsim.gui.keyboard_control.keyboard: Any | None = None#
- irsim.gui.keyboard_control.keyboard#
- class irsim.gui.keyboard_control.KeyboardControl(env_ref: Any | None = None, **keyboard_kwargs: Any)[source]#
Keyboard input handler for IR-SIM with dual backends.
- Overview:
Provides manual control of robots and environment using keyboard keys.
- Supports two backends:
“mpl” (default): Matplotlib figure key events (no extra dependency).
“pynput”: Global keyboard hook (requires the
pynputpackage).
If the requested backend is unavailable, it automatically falls back to “mpl”.
- Control mode gating:
Robot control keys (w/s/a/d, q/e, z/c, alt+number) only take effect when
world_param.control_mode == "keyboard".Environment keys (space to pause/resume, r to reset, esc to quit) are always active.
- Key mappings (both backends):
w/s: Increase/decrease linear velocity (forward/backward)
a/d: Increase/decrease angular velocity (turn left/right)
q/e: Decrease/increase maximum linear velocity (key_lv_max)
z/c: Decrease/increase maximum angular velocity (key_ang_max)
alt + number: Change current controlled robot id
r: Reset the environment (if
env_refprovided)space: Toggle pause/resume
esc: Quit the environment immediately (closes figure and raises
SystemExit(0))x: Switch between keyboard and auto control modes
l: Reload the environment
F5: Debug the environment
Notes
The “mpl” backend requires the Matplotlib figure window to have focus to receive key events.
In keyboard control mode, behavior planners are ignored; robot motion follows key input.
Initialize keyboard control for the environment.
- Parameters:
env_ref – Reference to the environment instance. Used for pause/resume and reset.
keyboard_kwargs (dict) –
Optional settings for keyboard control.
key_lv_max (float): Maximum linear velocity. Default is 3.0.
key_ang_max (float): Maximum angular velocity. Default is 1.0.
key_lv (float): Initial linear velocity. Default is 0.0.
key_ang (float): Initial angular velocity. Default is 0.0.
key_id (int): Initial robot control ID. Default is 0.
backend (str): Keyboard backend.
"mpl"(default) uses Matplotlib figure key events;"pynput"uses a global keyboard hook if thepynputpackage is available.
- Keyboard mappings (both backends):
w: Move forward
s: Move backward
a: Turn left
d: Turn right
q/e: Decrease/Increase linear velocity
z/c: Decrease/Increase angular velocity
alt + number: Change current control robot id
r: Reset the environment (if
env_refprovided)space: Pause/Resume the environment
esc: Quit the environment
x: Switch between keyboard and auto control modes
l: Reload the environment
F5: Debug the environment
- env_ref = None#
- key_lv_max#
- key_ang_max#
- key_lv#
- key_ang#
- key_id#
- alt_flag = 0#
- backend#
- key_vel#