feat: new openarm adapter - #2382
Conversation
❌ 2 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Greptile SummaryThis PR introduces a new
Confidence Score: 4/5The adapter core and registry refactor are solid, but the two new RS blueprints will crash at import time before any hardware is touched. The base adapter, specs, registry, and adapter-side code are well-structured and backed by tests. The only broken path is in the new blueprints file, where JointState and LCMTransport are used at module level without being imported — any attempt to load coordinator-openarm-rs or openarm-rs-planner-coordinator raises NameError immediately, making both blueprints completely unusable as shipped. dimos/robot/manipulators/openarm/blueprints.py needs the two missing imports before the RS blueprints can be used. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["adapter_registry.discover()"] --> B["Scan manipulators subpackages"]
B --> C{"__registry__.py exists?"}
C -->|No| D["Skip subpackage"]
C -->|Yes| E["import __registry__.py (lightweight manifest)"]
E --> F["Read ADAPTER_FACTORIES {name → module:Class}"]
F --> G["register_path(name, factory_path) (lazy — no adapter import yet)"]
G --> H["adapter_registry.available() returns sorted keys"]
H --> I["adapter_registry.create('openarm_rs', ...)"]
I --> J["_resolve_adapter('openarm_rs')"]
J --> K["importlib.import_module('openarm_rs.adapter')"]
K --> L["OpenArmRSAdapter(**kwargs)"]
L --> M["DamiaoArmAdapterBase.__init__ builds DamiaoArmSpec (side-specific limits)"]
M --> N["adapter.connect()"]
N --> O["_build_robot() SocketCanBus + DamiaoCodec"]
O --> P["robot.connect()"]
P --> Q["refresh_state(force=True)"]
Q --> R["write_enable(True)"]
R --> S["robot.enable()"]
S --> T["write_joint_positions (hold current pose)"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["adapter_registry.discover()"] --> B["Scan manipulators subpackages"]
B --> C{"__registry__.py exists?"}
C -->|No| D["Skip subpackage"]
C -->|Yes| E["import __registry__.py (lightweight manifest)"]
E --> F["Read ADAPTER_FACTORIES {name → module:Class}"]
F --> G["register_path(name, factory_path) (lazy — no adapter import yet)"]
G --> H["adapter_registry.available() returns sorted keys"]
H --> I["adapter_registry.create('openarm_rs', ...)"]
I --> J["_resolve_adapter('openarm_rs')"]
J --> K["importlib.import_module('openarm_rs.adapter')"]
K --> L["OpenArmRSAdapter(**kwargs)"]
L --> M["DamiaoArmAdapterBase.__init__ builds DamiaoArmSpec (side-specific limits)"]
M --> N["adapter.connect()"]
N --> O["_build_robot() SocketCanBus + DamiaoCodec"]
O --> P["robot.connect()"]
P --> Q["refresh_state(force=True)"]
Q --> R["write_enable(True)"]
R --> S["robot.enable()"]
S --> T["write_joint_positions (hold current pose)"]
Reviews (8): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile |
| def write_clear_errors(self) -> bool: | ||
| if self._robot is None: | ||
| return False | ||
| try: | ||
| self._robot.disable() | ||
| self._robot.enable() | ||
| except Exception as exc: | ||
| logger.error(f"{type(self).__name__} {self._hardware_id} clear errors failed: {exc}") | ||
| return False | ||
| self._enabled = True | ||
| return True |
There was a problem hiding this comment.
write_clear_errors() re-enables the motors but does not issue a hold command for the current position, unlike write_enable(True) which calls write_joint_positions(positions) after enabling. On a gravity-loaded arm this means clearing errors leaves the arm unpowered at its last position for one control cycle before the caller sends the next command, which could cause uncontrolled droop or jerk.
| def write_clear_errors(self) -> bool: | |
| if self._robot is None: | |
| return False | |
| try: | |
| self._robot.disable() | |
| self._robot.enable() | |
| except Exception as exc: | |
| logger.error(f"{type(self).__name__} {self._hardware_id} clear errors failed: {exc}") | |
| return False | |
| self._enabled = True | |
| return True | |
| def write_clear_errors(self) -> bool: | |
| if self._robot is None: | |
| return False | |
| try: | |
| self._robot.disable() | |
| self._robot.enable() | |
| except Exception as exc: | |
| logger.error(f"{type(self).__name__} {self._hardware_id} clear errors failed: {exc}") | |
| return False | |
| self._enabled = True | |
| positions = self.read_joint_positions() | |
| if not self.write_joint_positions(positions): | |
| logger.error(f"{type(self).__name__} {self._hardware_id} clear errors hold failed") | |
| return False | |
| return True |
| def disconnect(self) -> None: | ||
| if self._robot is not None: | ||
| try: | ||
| self._robot.disable() | ||
| except Exception as exc: | ||
| logger.warning( | ||
| f"{type(self).__name__} {self._hardware_id} disable on disconnect failed: {exc}" | ||
| ) | ||
| self._enabled = False | ||
| self._connected = False | ||
| self._robot = None | ||
| self._arm = None | ||
| self._state_cache = None | ||
|
|
There was a problem hiding this comment.
disconnect() only disables motors, no connection teardown
connect() calls robot.connect() but disconnect() only calls robot.disable(). If the can_motor_control binding keeps sockets, threads, or file descriptors open until an explicit disconnect is called, resources will leak on every reconnect or clean shutdown. The original OpenArmAdapter.disconnect() closes the bus (bus.closed is True in its test). Consider calling self._robot.disconnect() (or equivalent) if the binding exposes one, before nulling out self._robot.
| import dimos.hardware.manipulators as pkg | ||
|
|
||
| for root in pkg.__path__: | ||
| for child in sorted(Path(root).iterdir()): | ||
| if not child.is_dir() or child.name.startswith(("_", ".")): | ||
| continue | ||
| if not (child / "__registry__.py").exists(): | ||
| continue | ||
|
|
||
| module_name = f"dimos.hardware.manipulators.{child.name}.__registry__" | ||
| module = importlib.import_module(module_name) | ||
| adapter_factories_obj = getattr(module, "ADAPTER_FACTORIES", None) | ||
| if not isinstance(adapter_factories_obj, Mapping): | ||
| raise TypeError(f"{module_name} must define ADAPTER_FACTORIES") | ||
| adapter_factories = cast("Mapping[object, object]", adapter_factories_obj) | ||
| for name, factory_path in adapter_factories.items(): | ||
| if not isinstance(name, str) or not isinstance(factory_path, str): | ||
| raise TypeError( | ||
| f"{module_name}.ADAPTER_FACTORIES must map strings to strings" | ||
| ) | ||
| self.register_path(name, factory_path) |
There was a problem hiding this comment.
discover() no longer silences import errors from __registry__.py files
The old discover() wrapped each adapter import in except ImportError and logged a debug message, so a broken adapter never blocked discovery of others. The new implementation calls importlib.import_module(module_name) for each __registry__.py with no error handling. A SyntaxError, missing transitive dependency, or any other exception in a __registry__.py (even a third-party plugin) will now abort discovery entirely and make all adapters unavailable. Adding a narrow except Exception around each importlib.import_module call with a warning log would restore the resilience property.
b675674 to
b5a0e2c
Compare
| adapter.connect() | ||
|
|
||
|
|
||
| def test_lifecycle_read_write_disable() -> None: |
There was a problem hiding this comment.
There are many low value tests in this file. Tests should check functionality.
A good test is structured like this:
- setup the test
- execute the functionality
- check that the desired result was achieved
But a test like this one just constructs one object and asserts every minor aspect. It's not clear what behavior is even desired given that so much is asserted.
Tests that over-assert make the system hard to change and introduce uncertainty.
| @@ -0,0 +1,102 @@ | |||
| # OpenSpec Workflow | |||
|
|
|||
| DimOS uses OpenSpec as the checked-in planning layer for behavior changes. OpenSpec artifacts live under `openspec/` and should describe what the system is supposed to do, why it is changing, and how contributors or agents should validate the work. | |||
There was a problem hiding this comment.
If we want to use OpenSpec, that should be a separate PR, it shouldn't be coupled to this openarm stuff.
There was a problem hiding this comment.
Sorry for the confusion added here. I based all my branches on an openspec initialization commit. I cleaned that out and created this pr: #2428. will remove openspec stuff in this branch
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.
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).
|
@TomCC7 My auto fixer created this PR: https://github.com/dimensionalOS/dimos/pull/2426/changes Do you agree with the changes? If so, please merge them into this PR. |
…utofixes Auto-fixes for cc/openarm-rust-adapter
| def write_stop(self) -> bool: | ||
| if self._arm is None or self._robot is None: | ||
| return False | ||
| if self._gravity_comp and self._enabled: | ||
| try: | ||
| q_now = self.read_joint_positions() | ||
| except RuntimeError: | ||
| return False | ||
| return self.write_mit_commands( | ||
| q=q_now, | ||
| dq=self._zero_vector(), | ||
| kp=list(self._kp), | ||
| kd=list(self._kd), | ||
| tau=self.compute_gravity_torques(q_now), | ||
| ) | ||
| try: | ||
| self._robot.disable() | ||
| except Exception: | ||
| logger.warning( | ||
| "damiao adapter stop disable failed", | ||
| adapter=type(self).__name__, | ||
| hardware_id=self._hardware_id, | ||
| exc_info=True, | ||
| ) | ||
| return False | ||
| self._enabled = False | ||
| return True |
There was a problem hiding this comment.
write_stop() leaves motors powered on gravity-comp state-read failure
When gravity_comp=True and _enabled=True, a RuntimeError from read_joint_positions() (e.g., a CAN bus fault) causes the method to return False without ever calling _robot.disable(). The motors remain hardware-powered with no position hold issued — the opposite of a stop. The fallthrough _robot.disable() path at the bottom of the method is never reached because the gravity-comp branch returns early. A safe fallback would be to attempt _robot.disable() before returning False in the except RuntimeError block.
| def write_enable(self, enable: bool) -> bool: | ||
| if self._robot is None: | ||
| return False | ||
| try: | ||
| self._robot.enable() if enable else self._robot.disable() | ||
| except Exception: | ||
| logger.exception( | ||
| "damiao adapter enable failed", | ||
| adapter=type(self).__name__, | ||
| hardware_id=self._hardware_id, | ||
| enable=enable, | ||
| ) | ||
| return False | ||
| self._enabled = enable | ||
| if enable: | ||
| positions = self.read_joint_positions() | ||
| if not self.write_joint_positions(positions): | ||
| logger.error( | ||
| "damiao adapter startup hold failed", | ||
| adapter=type(self).__name__, | ||
| hardware_id=self._hardware_id, | ||
| ) | ||
| return False | ||
| return True |
There was a problem hiding this comment.
_enabled=True persists after a failed startup hold position write
_enabled = enable is set unconditionally at line 493 once _robot.enable() succeeds. If the subsequent write_joint_positions(positions) call returns False (for example, a transient CAN error during the MIT write), the method returns False to the caller but _enabled remains True. The hardware motors are enabled (from _robot.enable()) but no hold position was written, so the arm is powered with no reference. Any subsequent method call that guards on self._enabled (such as write_joint_positions, write_joint_torques, write_mit_commands) will proceed against an arm in an undefined state. Consider setting _enabled = False and calling _robot.disable() before returning False from the startup hold failure path.
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
6f77783 to
2125808
Compare
| ("joint_state", JointState): LCMTransport("/coordinator/joint_state", JointState), | ||
| } | ||
| ) | ||
|
|
||
| openarm_rs_planner_coordinator = autoconnect( | ||
| ManipulationModule.blueprint( | ||
| robots=[_openarm_rs_hw.to_robot_model_config()], | ||
| planning_timeout=10.0, | ||
| enable_viz=True, | ||
| ), | ||
| ControlCoordinator.blueprint( | ||
| hardware=[_openarm_rs_hw.to_hardware_component()], | ||
| tasks=[_openarm_rs_hw.to_task_config()], | ||
| ), | ||
| ).transports( | ||
| { | ||
| ("joint_state", JointState): LCMTransport("/coordinator/joint_state", JointState), | ||
| } |
There was a problem hiding this comment.
Missing imports cause NameError at module load
JointState and LCMTransport are referenced at module level in both coordinator_openarm_rs and openarm_rs_planner_coordinator, but neither is imported anywhere in this file. Because the .transports({...}) call is evaluated when the module is imported, loading the module — which happens as soon as any blueprint from this file is selected — will raise NameError: name 'JointState' is not defined. Both blueprints are registered in all_blueprints.py, so dimos run coordinator-openarm-rs will fail immediately.
Add the two missing imports:
from dimos.core.transport import LCMTransportfrom dimos.msgs.sensor_msgs.JointState import JointState
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. |
|
This pull request has been automatically closed because it has been stale for 30 days with no activity. Feel free to reopen it if you plan to continue working on it. |
|
close in lieu of #3388 |
Solution
Adds an opt-in
openarm_rsmanipulator adapter for OpenArm hardware using the Rust-backedcan-motor-controlPython binding. (https://github.com/TomCC7/can-motor-control)The existing
openarmadapter remains the default production path.openarm_rsis selected explicitly through hardware config or the new OpenArm RS blueprints, and is intended for binding-backed bring-up, state monitoring, MIT command validation, gravity compensation, and trajectory-control validation.This also updates manipulator adapter discovery to use lightweight
__registry__.pymanifests, so listing available adapters does not import unselected hardware SDKs or optional bindings.User-facing behavior
adapter_type="openarm"continues to use the existing in-tree SocketCAN OpenArm adapter.adapter_type="openarm_rs"selects the Rust-backed OpenArm adapter.can_motor_controlnow fails only whenopenarm_rsis selected/connected, with a clear install hint.How to Test