Auto-fixes for cc/openarm-rust-adapter#2426
Conversation
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 SummaryThis 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 (
Confidence Score: 4/5The 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 All logic changes are well-motivated cleanups (structured logging, constant deduplication, dead-code removal). The coordinated removal of dimos/hardware/manipulators/openarm_rs/adapter.py — Important Files Changed
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]
|
| from dimos.hardware.manipulators.damiao.base_adapter import ( | ||
| _DEFAULT_ADDRESS, | ||
| _DEFAULT_STATE_CACHE_TTL_S, | ||
| _DEFAULT_TICK_DEADLINE_US, |
There was a problem hiding this comment.
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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
These are automated fixes. Each fix is a separate commit. Use
git rebase -ito drop any you disagree with.