Skip to content

[release/3.0.0] Fix Se3Keyboard constant motion after an unmatched key release - #9031

Open
jack60612 wants to merge 2 commits into
isaac-sim:release/3.0.0from
jack60612:upstream/se3-keyboard-held-keys
Open

jack60612 wants to merge 2 commits into
isaac-sim:release/3.0.0from
jack60612:upstream/se3-keyboard-held-keys

Conversation

@jack60612

Copy link
Copy Markdown

Description

Se3Keyboard (release/3.0.0) adds a key's delta on every KEY_PRESS and subtracts it on every KEY_RELEASE. A release without a matching press therefore leaves a constant motion command until the next reset():

  1. Key held across a reset (deterministic): hold E, press R (the teleop script calls reset(), which zeroes the deltas), release E. The release subtracts E again, and the end effector keeps moving up (+z, 0.05 per step at default sensitivity) until the next reset.
  2. Events Kit does not deliver: with real X11 input, the first key press after clicking the viewport sometimes reached the keyboard state but no carb subscriber, while its release did; the same constant command results.

Fix (Se3Keyboard only):

  • Track the motion keys whose press has been applied. A repeated press adds nothing; a release only removes a delta its key added.
  • reset() forgets held keys.
  • advance() drops held keys that IInput.get_keyboard_value reports as released, so a lost release stops at the next command. Keys are never added from the polled state.

main replaced this device in #8797; its held-key set (_ControlKeyListener) does not have this defect, so this targets release/3.0.0 only.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump package versions — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

New source/isaaclab/test/devices/test_se3_keyboard.py mocks carb/omni (no Kit). On release/3.0.0 (223feed) 6 of 8 cases fail; with the fix 8 pass. Also verified in a Kit GUI session with real X11 key events: before, holding E across R drifted the arm 0.29 m in 100 steps; after, 0 m. Pre-commit hooks were run on the changed files.

Se3Keyboard added a key's delta on every press event and subtracted it on
every release event, so a release without its press, or a press without its
release, left a constant motion command until the next reset. Both happen in
teleoperation: a key still held when R resets the device (reset() zeroes the
deltas, the later release subtracts again), and key events Kit does not
deliver. In Kit, a key press right after a viewport click reached no keyboard
subscriber while the keyboard state recorded it, so "R, click the viewport,
drive" left the arm drifting opposite to the first key.

Track the motion keys whose press was applied: a press of a held key adds
nothing, a release only removes a delta its key added, reset() forgets keys
still held, and advance() drops keys the keyboard reports as released.

Signed-off-by: Jack Nelson <jinelson@andrew.cmu.edu>
@jack60612
jack60612 requested a review from a team November 12, 2026 21:36
@github-actions github-actions Bot added isaac-mimic Related to Isaac Mimic team isaac-lab Related to Isaac Lab team labels Nov 12, 2026
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects robot-arm teleoperation that uses Se3Keyboard.

The fix appears safe to merge, with a non-blocking improvement needed to run the mocked tests without Kit.

Findings

  1. P2 Mocked tests still require Kit ▶

Summary

Se3Keyboard now tracks which motion-key presses contributed to its command.

  • Se3Keyboard stops stale motion when key events are missed.

Reviews (1) · Last reviewed commit: "Keep Se3Keyboard motion consistent with ..." · Reviewed by Greptile

Comment on lines +14 to +15
from isaaclab.devices import Se3Keyboard, Se3KeyboardCfg
from isaaclab.devices.keyboard import se3_keyboard

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Mocked tests still require Kit

These imports load the real carb and omni modules before the fixture installs its mocks. If those modules are unavailable, collection fails before any test runs. Install temporary module stubs before importing Se3Keyboard so contributors can run these mocked tests without Kit.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: missing carb and omni modules are temporarily stubbed during import; the fixture replaces the input interfaces.

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isaac Lab Review Bot

Needs attention: Implementation (1), Style consistency (7), Test quality (2). Other reviewed categories look good.

  • PR description: The title and four-file scope match the diff, and the reported baseline failures and GUI drift comparison address correctness without making a performance claim.
  • Design and architecture: Architecture looks good.
  • Scope and over-engineering: No over-engineering issues.
  • API: API changes look good.
  • Compatibility and deprecation: No breaking changes identified.
  • Implementation: advance() allocates a reconciliation list even with no held keys; guard reconciliation with if self._held_keys to avoid the idle allocation.
  • Style consistency: Added production and test signatures omit required annotations; add concrete parameter types and -> None for functions that return no value.
  • Test quality: Direct private-handler calls couple event tests to implementation and bypass subscription; invoke the registered callback and trim unused mock enum entries while retaining distinct motion and gripper contracts.

Minor fixes needed. Posted 10 inline findings.

Automated review; human maintainers own approval decisions.

self._close_gripper = False
self._delta_pos = np.zeros(3) # (x, y, z)
self._delta_rot = np.zeros(3) # (roll, pitch, yaw)
# Forget keys that are still physically held (e.g. a pull key held while the reset key is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Name the reset key consistently

The comment calls a held motion key a “pull key,” which the bindings never define. Use “motion key” to make the reset constraint identifiable.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: the reset comment now says motion keys and explains the cleared-delta invariant.

"""
# A release that never reached this device (Kit can consume key events, e.g. in the frame of a
# viewport click) would keep its key's motion forever: drop keys the keyboard reports as up.
for key in [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Implementation — Avoid idle command allocations

The list comprehension allocates on every advance(), including when no motion key is held. Guard reconciliation with if self._held_keys so idle commands avoid that per-step allocation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: reconciliation is guarded when no keys are held.

https://docs.omniverse.nvidia.com/dev-guide/latest/programmer_ref/input-devices/keyboard.html
"""
# apply the command when pressed
# apply the command when pressed (once per press: a key already held adds nothing)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Remove narrated press condition

This comment repeats the KEY_PRESS branch and held-key guard without explaining a further constraint. Remove it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: removed the redundant held-key narration.

self._delta_pos -= self._INPUT_KEY_MAPPING[event.input.name]
elif event.input.name in ["Z", "X", "T", "G", "C", "V"]:
self._delta_rot -= self._INPUT_KEY_MAPPING[event.input.name]
# remove the command when un-pressed. A release whose press was not applied (the key was

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Shorten the release rationale

Three lines narrate the release branch and repeat the drift outcome. Keep only the non-obvious invariant: never subtract a delta whose press was not applied.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: the release comment states the unmatched-press invariant concisely.

# since no error, we are fine :)
return True

def _release(self, key: str):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Annotate the release helper

_release has no return annotation, contrary to the signature guidance for no-value methods. Add -> None.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: _release now returns None in its annotation.


PRESS, RELEASE = "KEY_PRESS", "KEY_RELEASE"
STEP = 0.05
KEYS = ["W", "S", "A", "D", "Q", "E", "Z", "X", "T", "G", "C", "V", "K", "R", "L"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Test Quality — Trim unused mock key entries

Only W, A, Z, E, Q, and X reach keyboard-value polling. The other enum assignments maintain an unused key inventory; initialize only entries queried by these tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: only the six polled test keys are configured.

KEYS = ["W", "S", "A", "D", "Q", "E", "Z", "X", "T", "G", "C", "V", "K", "R", "L"]


class Keyboard:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Keep test support private

Keyboard is file-local fixture support but has a public name and precedes public test functions. Rename it _Keyboard and place the private class after the functions.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: renamed _Keyboard and moved it after the tests.

deliver the event, ``drop_*`` change it without delivering the event (an event Kit consumed).
"""

def __init__(self, monkeypatch):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Annotate new test signatures

The fixture, tests, and most Keyboard methods omit parameter or return annotations required by the type-hint guidance. Add concrete annotations, including -> None for no-value functions.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: fixture, test, and helper signatures have concrete annotations.

monkeypatch.setattr(se3_keyboard, "omni", mock.MagicMock())
self.device = Se3Keyboard(Se3KeyboardCfg(pos_sensitivity=STEP, rot_sensitivity=STEP, sim_device="cpu"))

def _send(self, kind: str, key: str):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Order private methods last

_send precedes the fixture's public press and release methods, contrary to the prescribed class-member order. Move it below the public methods.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: _send follows the public helper methods.

self.device = Se3Keyboard(Se3KeyboardCfg(pos_sensitivity=STEP, rot_sensitivity=STEP, sim_device="cpu"))

def _send(self, kind: str, key: str):
self.device._on_keyboard_event(SimpleNamespace(type=kind, input=SimpleNamespace(name=key)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Test Quality — Exercise the subscribed callback

Calling _on_keyboard_event directly bypasses the callback registered at construction, so subscription regressions pass and a behavior-preserving handler rename breaks every event test. Capture and invoke the registered callback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: the fixture captures and invokes the subscribed callback.

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isaac Lab Review Bot

Needs attention: Style consistency (6), Test quality (3). Other reviewed categories look good.

  • PR description: The title and release-branch scope match the diff, and reported baseline failures and GUI drift checks support correctness; bounded keyboard polling introduces no material scaling change requiring performance measurements.
  • Design and architecture: Architecture looks good.
  • Scope and over-engineering: No over-engineering issues.
  • API: API changes look good.
  • Compatibility and deprecation: No breaking changes identified.
  • Implementation: Implementation looks good.
  • Style consistency: Added narration repeats nearby guards and assertions, increasing maintenance noise; shorten the changelog and comments, correct binding vocabulary, and apply private naming and concrete signature annotations.
  • Test quality: Direct private-handler invocation couples regressions to implementation rather than registered input delivery; use the subscribed callback and remove unused key inventory and unobservable dropped-press setup.

Minor fixes needed. Posted 9 inline findings.

Automated review; human maintainers own approval decisions.

@@ -0,0 +1,5 @@
* Fixed :class:`~isaaclab.devices.keyboard.se3_keyboard.Se3Keyboard` leaving a constant motion command when a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Condense the changelog entry

Five lines replay event examples and internal bookkeeping for one user-visible fix. State that unmatched key events no longer leave persistent motion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: the fragment now states the user-visible fix concisely.

self._close_gripper = False
self._delta_pos = np.zeros(3) # (x, y, z)
self._delta_rot = np.zeros(3) # (roll, pitch, yaw)
# Forget keys that are still physically held (e.g. a pull key held while the reset key is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Name the reset key accurately

“Pull key” is not this device's binding vocabulary and obscures which deltas reset clears. Say “motion key” and keep the reset invariant concise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: the reset comment uses motion-key terminology.

https://docs.omniverse.nvidia.com/dev-guide/latest/programmer_ref/input-devices/keyboard.html
"""
# apply the command when pressed
# apply the command when pressed (once per press: a key already held adds nothing)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Remove press-branch narration

The parenthetical repeats the held-key guard immediately below and adds no constraint. Remove it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: removed the redundant held-key narration.


PRESS, RELEASE = "KEY_PRESS", "KEY_RELEASE"
STEP = 0.05
KEYS = ["W", "S", "A", "D", "Q", "E", "Z", "X", "T", "G", "C", "V", "K", "R", "L"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Test Quality — Trim the fixture key inventory

Several listed bindings are never sent or polled. This copied inventory adds maintenance without testing them; configure only keys exercised by the cases.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: only the six keys exercised by polling are configured.

KEYS = ["W", "S", "A", "D", "Q", "E", "Z", "X", "T", "G", "C", "V", "K", "R", "L"]


class Keyboard:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Keep the fixture class private

Keyboard is test-only support, but its public name conflicts with the repository's private-class convention. Rename it _Keyboard and place it with private declarations.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: renamed _Keyboard and moved it below the tests.

deliver the event, ``drop_*`` change it without delivering the event (an event Kit consumed).
"""

def __init__(self, monkeypatch):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Annotate new function signatures

The fixture, test functions, and event helpers omit available parameter or return types; the new Se3Keyboard._release also lacks -> None. Add concrete annotations as required by the guide.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: added annotations to the test helpers and _release.

self.device = Se3Keyboard(Se3KeyboardCfg(pos_sensitivity=STEP, rot_sensitivity=STEP, sim_device="cpu"))

def _send(self, kind: str, key: str):
self.device._on_keyboard_event(SimpleNamespace(type=kind, input=SimpleNamespace(name=key)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Test Quality — Use the subscribed callback

Directly calling the private handler bypasses the event subscription used by real input. Capture the callback registered during construction and send test events through it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: events are delivered through the captured subscription callback.

np.testing.assert_array_equal(keyboard.motion(), np.zeros(6))
keyboard.release("R", "E")
np.testing.assert_array_equal(keyboard.motion(), np.zeros(6))
# the next episode drives normally

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Remove episode narration

The test has no episode boundary, and the comment only narrates the following press and assertions. Remove it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: removed the episode narration.

@pytest.mark.parametrize("key", ["Q", "X"])
def test_release_of_undelivered_press_is_ignored(keyboard, key):
"""A release whose press never reached the device must not leave a constant motion command."""
keyboard.drop_press(key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Test Quality — Remove unobservable dropped-press setup

drop_press() changes fake state that release() clears before the device reads it. It cannot affect the assertion; send the unmatched release directly and remove the helper.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0abbc34: the test sends an unmatched release directly and the unobservable helper is gone.

Skip reconciliation when no motion key is held, tighten comments, annotate
_release, and condense the changelog fragment. Drive the tests through the
subscribed callback, stub carb/omni for import so they collect without Kit,
trim the mocked key inventory, and make the fixture class private.

Signed-off-by: Jack Nelson <jack@jackn.org>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team isaac-mimic Related to Isaac Mimic team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant