Skip to content

Auto-fixes for cc/openarm-rust-adapter#2426

Merged
TomCC7 merged 13 commits into
cc/openarm-rust-adapterfrom
cc/openarm-rust-adapter-autofixes
Jun 8, 2026
Merged

Auto-fixes for cc/openarm-rust-adapter#2426
TomCC7 merged 13 commits into
cc/openarm-rust-adapterfrom
cc/openarm-rust-adapter-autofixes

Conversation

@paul-nechifor

Copy link
Copy Markdown
Contributor

These are automated fixes. Each fix is a separate commit. Use git rebase -i to drop any you disagree with.

The FloatArray alias and its numpy.typing.NDArray import were never
referenced. Remove both.
The OpenArmRSMotorSpecConfig alias for DamiaoMotorSpec was only
referenced by its own __all__ entry; nothing imports it. Remove both.
Move 'import time' out of FakeState.__init__ to the module top, per the
imports-at-top convention. FakeState.timestamp is still read by the
adapter's staleness check, so it stays.
gravity_comp=True and canfd=True are already the OpenArmRSAdapter
defaults. The blueprint should only specify what differs, so keep just
gravity_model_path.
Per the imports convention, a lazy import of a heavy optional dep needs
a comment saying why. Add it to both gravity-model import sites.
tick_deadline_us=1_000 and state_cache_ttl_s=0.002 were unnamed magic
numbers duplicated as defaults in both the base and the openarm_rs
subclass. Hoist them to _DEFAULT_TICK_DEADLINE_US and
_DEFAULT_STATE_CACHE_TTL_S so the two can't drift.
The 'can0' interface name was hard-coded three times: the base
constructor default, the base None-coalesce, and the openarm_rs
subclass default. Collapse them onto one _DEFAULT_ADDRESS constant so
the literal lives in exactly one place. The None-coalesce stays to
handle a config that leaves address unset (the factory then passes
address=None).
- refresh_state: build the position/velocity/torque lists with
  ndarray.tolist() instead of per-element float() loops.
- write_mit_commands: assemble the MIT matrix with np.column_stack
  instead of a Python comprehension over zipped rows; this removes the
  now-redundant _mit_command_rows helper (validation moves to a direct
  _validate_command_lengths call).
- read_state: look the control-mode index up in a precomputed
  _CONTROL_MODE_INDEX map instead of rebuilding list(ControlMode) every
  call.
The connect/disconnect/write_enable/write_clear_errors/write_stop paths
stuffed context into f-string log lines and dropped the traceback on
real failures. Switch to structlog key/value fields and use
logger.exception (or warning with exc_info) so the traceback survives
instead of being downgraded to an f-string error message.
When the pre-command state read fails, the adapter substitutes
zero feed-forward torque. Log a warning (with traceback) so the dropped
gravity term is visible instead of being silently swallowed.
The try wrapped both refresh_state and compute_gravity_torques under a
broad except Exception, masking a real gravity-model error as 'invalid
state'. Scope the try to refresh_state (the call that raises RuntimeError
on a bad read) and let a genuine compute error propagate. Also switch
the log line to structured fields with a traceback.
The **_: object catch-all silently dropped misspelled adapter kwargs.
The registry factory only passes declared parameters (dof, address,
hardware_id plus the blueprint adapter_kwargs), so drop the catch-all
to turn config typos into a clear TypeError.
The OpenArm integration guide inlined the kp/kd preset numbers, which
drift from the adapter code. Replace them with a pointer to
OpenArmRSAdapter._DEFAULT_KP/_DEFAULT_KD (and the openarm adapter's
own constants).
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This automated cleanup PR refactors the Damiao/OpenArm RS adapter layer: it consolidates shared default constants into the base module, migrates f-string log calls to structured keyword-argument logging, removes dead code (_mit_command_rows, OpenArmRSMotorSpecConfig), and simplifies array construction with np.column_stack.

  • Logging overhaul — all logger.error/warning(f\"…\") calls replaced with logger.exception/logger.warning using structured keyword args and exc_info=True; the gravity feed-forward failure that was previously silent now logs a warning.
  • Constant deduplication_DEFAULT_ADDRESS, _DEFAULT_TICK_DEADLINE_US, _DEFAULT_STATE_CACHE_TTL_S, and a pre-computed _CONTROL_MODE_INDEX dict are defined once in the base and imported by the subclass, preventing drift.
  • API surface tightening**_: object removed from OpenArmRSAdapter.__init__ (coordinated with dropping now-redundant keys from _OPENARM_RS_ADAPTER_KWARGS in the blueprint).

Confidence Score: 4/5

The changes are clean and internally consistent — the constants, blueprint, and adapter constructor changes all land together as a coherent set. The only runtime concern is external callers that relied on **_: object absorbing extra kwargs; within the repo that path is accounted for.

All logic changes are well-motivated cleanups (structured logging, constant deduplication, dead-code removal). The coordinated removal of **_: object and the corresponding blueprint kwarg cleanup is sound for in-repo callers. The exception narrowing in write_gravity_compensation is intentionally stricter and is fine given no callers in the production code path expect that method to raise.

dimos/hardware/manipulators/openarm_rs/adapter.py — **_: object removal and underscore-constant imports; dimos/hardware/manipulators/damiao/base_adapter.py — exception narrowing in write_gravity_compensation.

Important Files Changed

Filename Overview
dimos/hardware/manipulators/damiao/base_adapter.py Core refactor: structured logging, constant extraction, dead-code removal, and np.column_stack simplification. The MIT command array construction is functionally equivalent; the exception narrowing in write_gravity_compensation (from Exception to RuntimeError) intentionally lets non-RuntimeError faults propagate rather than silently returning False.
dimos/hardware/manipulators/openarm_rs/adapter.py Imports shared constants from base module, removes OpenArmRSMotorSpecConfig alias (unused per codebase search), and drops **_: object catch-all. Coordinated with blueprint change that no longer passes extra kwargs.
dimos/robot/manipulators/openarm/blueprints.py Removes gravity_comp=True and canfd=True from _OPENARM_RS_ADAPTER_KWARGS — both are already the defaults in OpenArmRSAdapter.__init__, so behavior is unchanged.
dimos/hardware/manipulators/damiao/test_base_adapter.py Test updated to call _validate_command_lengths directly (replacing removed _mit_command_rows). Test still correctly verifies the length validation behavior.
dimos/hardware/manipulators/openarm/test_adapter.py Moves import time to module level from inside FakeState.__init__; purely a style fix with no behavioral change.
docs/capabilities/manipulation/openarm_integration.md Replaces hardcoded gain constants with links to source files, preventing docs from drifting from code.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[write_gravity_compensation] --> B{refresh_state force=True}
    B -- RuntimeError --> C[log warning / return False]
    B -- success --> D[compute_gravity_torques q]
    D -- raises --> E[propagates to caller - new behavior]
    D -- success --> F[write_mit_commands q, dq, kp=0, kd=damping, tau]
    F --> G[return bool]
    H[write_mit_commands] --> I{arm/robot enabled?}
    I -- No --> J[return False]
    I -- Yes --> K[_validate_command_lengths]
    K --> L[np.column_stack kp kd q dq tau shape n x5]
    L --> M[arm.mit_control row i = kp_i kd_i q_i dq_i tau_i]
    M --> N[robot.tick / clear state cache]
Loading

Comments Outside Diff (1)

  1. dimos/hardware/manipulators/openarm_rs/adapter.py, line 81-84 (link)

    P2 Removal of **_: object is a silent runtime-breaking change for external callers

    The **_: object catch-all previously allowed any extra keyword arguments to be passed without error. Its removal is correct given that the in-repo blueprint was updated at the same time, but any downstream code that supplies unknown keys in adapter_kwargs for openarm_rs will now get TypeError at the point the coordinator constructs the adapter — which is a runtime failure, not a startup check. If there is any chance of external consumers passing extra kwargs (e.g. from YAML configs loaded by the registry), a guard or a documented migration note would help surface the breakage earlier. Is there any external YAML/config-driven path that could still be passing unknown keys to openarm_rs adapter construction, or is the in-repo blueprint the only call site?

Reviews (1): Last reviewed commit: "docs: point to kp/kd source constants in..." | Re-trigger Greptile

Comment on lines 20 to +23
from dimos.hardware.manipulators.damiao.base_adapter import (
_DEFAULT_ADDRESS,
_DEFAULT_STATE_CACHE_TTL_S,
_DEFAULT_TICK_DEADLINE_US,

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 Importing module-private constants across package boundary

_DEFAULT_ADDRESS, _DEFAULT_TICK_DEADLINE_US, and _DEFAULT_STATE_CACHE_TTL_S carry the single-underscore "module-private" convention, yet they are explicitly imported by a sibling package. This works at runtime but conflicts with the convention and means tools like pylint or flake8 will flag the import. If the intent is for these to be shared across the package, exporting them without a leading underscore (or collecting them in a _constants.py sub-module) would make the intent explicit without relying on the convention-override.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.83333% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
dimos/hardware/manipulators/damiao/base_adapter.py 38.09% 13 Missing ⚠️

📢 Thoughts on this report? Let us know!

@TomCC7 TomCC7 merged commit b558cfe into cc/openarm-rust-adapter Jun 8, 2026
19 of 20 checks passed
@TomCC7 TomCC7 deleted the cc/openarm-rust-adapter-autofixes branch June 8, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants