Skip to content

Add E-stop status and a teleop interlock (draft: stale, needs porting) - #60

Draft
yassinsolim wants to merge 19 commits into
mainfrom
feature/estop-status-malik
Draft

yassinsolim wants to merge 19 commits into
mainfrom
feature/estop-status-malik

Conversation

@yassinsolim

Copy link
Copy Markdown
Member

Draft, opened so this work stays visible. The branch is from 10 October, by Malik and Yassin. It is 47 commits behind main and merging it conflicts in 20 files, because the teleop, drive and launch files it was built on have been rewritten since (#55, and the start-up guide in #57). It needs porting, not a merge. The diff below (19 files, +711/-23) is exactly its own work.

What it does

The software side of the emergency stop: status, interlock and display. It does not replace the physical emergency stop, which must stay within reach of anyone near the arm.

  • safety_interface.py: the topic, service and row names in one place (/waybionic/safety/emergency_stop, /waybionic/power/motor_supply_voltage, /waybionic/safety/last_report_age), shared by the simulated source and a future carrier-board source.
  • sim_safety_status_node.py: publishes placeholder E-stop, supply-voltage and report-age topics and a DiagnosticArray. The E-stop starts released and is toggled with the /waybionic/safety/emergency_stop/set service. It stands in until the carrier-board node exists.
  • safety_interlock.py: the policy, with no ROS in it. When the status is required, a pressed E-stop or a report that is missing or stale counts as pressed (fail-safe), with the reason and a display state (PRESSED, PRESSED-FAILSAFE, RELEASED, UNKNOWN, STALE).
  • Teleop (xbox_teleop_node.py): an E-stop pressed while enabled disables teleop at once and sends a zero-velocity hold. Start is refused, with a note, while it is pressed, and after release a fresh Start is needed (holding Start through the release does not re-enable). The teleop label and rumble keep running while the E-stop holds the arm, and the self-running demo holds while it is pressed.
  • RViz diagnostics rows for the E-stop and the supply voltage, marked provisional, and the topics and fields for the carrier-board firmware (DIAGNOSTICS_CONTRACT.md).
  • Tests: test_safety_interlock.py (no ROS), test_sim_safety_status_node.py, test_simulated_estop_launch.py (toggles the simulated E-stop in a launch), and cases in test_xbox_teleop_node.py, test_autoplay_node.py and test_ros_diagnostics_source.cpp.

Why it stalled

  • It is provisional until Electrical senses the E-stop circuit and the motor supply. The carrier firmware still has TODO(hardware-TBD) for both (carrier_bridge.ino, BenchTelemetry.h), so only the simulated source exists. The real carrier would have to publish the same topics.
  • It has not run on the real arm.

To revive it

  1. Port it onto main after Add the arm start-up guide, joint switch-off and Mac/Windows launchers for the real arm #57, Add chicken head and demo motion modes with a Motion modes panel #58 and Open the joint limits to where the arm's parts meet #44. The teleop node is the main work: the start-up guide's locked and switched-off joints and the chicken head and demo modes must also stop and hold on an E-stop.
  2. Agree with Electrical what the carrier reports and how long a report may be missing before it counts as pressed.
  3. Re-run the simulated E-stop launch test and the teleop tests, then try it on the arm at the lowest speed with the physical stop in reach.

yassinsolim and others added 19 commits September 26, 2026 13:06
The arm is a base yaw, three parallel pitch joints and a roll through the
tool tip, so kinematics.py solves any tip position and tool tilt in closed
form from the URDF. The new Cartesian group (Y) moves the tip along straight
lines in base_link with the tilt fixed; LB keeps only the strongest axis.
At a joint speed limit or the workspace edge the whole step shrinks, so the
tip stops on the line, and the roll turns against the yaw to keep the tool's
heading.

Each drive now gets the next setpoint one period ahead and the speed that
reaches it in exactly one period, measured from its encoder, so all drives
arrive together. acc is 255 because a gentle drive ramp adds the same rpm/s
to every drive and the one with the largest change falls behind. In
simulation a sideways cut at 30:1 gearing stays within 7-17 um of the line,
compared with up to 186 um with the old 1.5x speed rule. At the 1:1
placeholder gearing it stays within about 0.13 mm, one encoder count at the
tip.
D-pad left/right changes the tool pitch while the tip stays in place, so
the shoulder, elbow and wrist move around a fixed point. The tilt uses the
same closed-form step as straight moves, so a joint limit stops it with the
tip still in place. It runs at up to 30 deg/s, scaled by the speed level.
- Start is refused while a tilt button or A is held, like the sticks.
- Homing clears the Cartesian rates, so releasing A can't resume the last move.
- Cartesian roll ramps with the acceleration limit and scales with the accepted step.
- The drives' setpoint one period ahead stays within the URDF joint limits, which the
  drive node now reads from robot_description.
- If one drive would pass max_rpm, every drive slows by the same factor, so they still
  arrive together.
- The roll compensation is documented as stopping the tool spinning about its own axis;
  that keeps a blade's heading only when the tool points straight down.
- The Cartesian launch test is registered where it won't conflict with #22.
Reviewed in #24, which was merged into its stacked base after #23 had
already been squash-merged into main, so it never reached main. This is
the same change, applied to main.

Drive the five joints with an Xbox controller through placeholder MKS
SERVO42D/57D CAN drives, simulated until the real drives are connected.
On Windows, a Python-only XInput bridge sends the controller state to
the new wslg-teleop Compose service over UDP. The RViz camera follows
the tool so the end of the arm stays in view; follow_camera:=false keeps
a fixed view.

teleop and joy_source use And/Or/Equals substitutions, so teleop:=True
works like IfCondition. The new nodes receive use_sim_time, and the UDP
receiver reads at most 100 packets per poll so a flood cannot starve its
other callbacks.
On a busy CI runner the teleop node could still be loading the robot description when the test pressed Start, so the press was lost and the arm never moved. The test now sends idle packets until teleop reports its group and fresh controller input.
The tests could press Start before the teleop node had loaded the robot description or received controller input, so the press was lost on a busy machine. They now send idle packets until teleop reports its group and fresh input. Same fix as on #28.
A second robot_description replaced an enabled teleop with a disabled one without sending a hold, so the drives kept their last target.
absolute_axis rejected -0x800000, which the manual's 3-byte signed coordinate
encodes. The node also capped the elapsed time it handed the drives at 100 ms,
so a scheduler stall longer than the heartbeat never stopped a moving drive the
way hardware would. The drive splits a long step into 10 ms motion steps and
counts all of it toward the heartbeat.
Advance simulated heartbeat time before accepting new targets. Use MKS F5 zero-speed frames to stop moving drives and stop all drives on invalid targets. Handle ROS shutdown races without accepting failed node exits. Add controller, CAN, and launch regressions.
- `safety_interface.py` defines those topic, service, and row names in one place. The simulated source and future carrier-board source can share these constants.
- `sim_safety_status_node.py` publishes the three topics and a `DiagnosticArray` using the established `name`, `level`, `message`, `value`, and `unit` fields. Its E-stop starts released and can be toggled with `/waybionic/safety/emergency_stop/set` (`std_srvs/SetBool`). The default 24 V reading is placeholder data, not a hardware limit.
- `setup.py` registers the node as the `sim_safety_status` ROS executable; `package.xml` declares its `std_srvs` dependency.
- `ground_station.launch.py` starts the simulator by default when teleop is enabled. `simulated_safety_source:=false` lets a carrier-board publisher take over later; the diagnostics topic follows the existing launch argument.
- `DIAGNOSTICS_CONTRACT.md` records the proposed topics, types, rows, units, and status mapping.
- `test_sim_safety_status_node.py` checks the emitted topic values and diagnostic rows, E-stop press/release behavior, and invalid voltage rejection.

This change adds the simulated source and interface contract; it does **not** add the teleop Start interlock.
Three behaviours implemented:
- E-stop pressed while enabled: the E-stop callback immediately disables teleop, publishes `teleop_enabled: false`, and sends a zero-velocity hold command.
- Start while E-stop remains pressed: blocked, with an “Emergency stop pressed” note.
- After release: it still requires a fresh Start press. Holding Start through the release does not re-enable teleop.
- Treats stale/missing report as pressed.
…and teleop label. Also unit-tests the interlock without ROS and ads a launch test that toggles the simulated e-stop. Changes include:

**Unit-Test Features**
- `safety_interlock.py`: Extracts the E-stop policy into a standard-library-only class. It decides whether status is effectively pressed, reports why teleop is blocked, and provides display states. This allows testing the safety rules without importing or starting ROS.
- `test_safety_interlock.py`: Tests the interlock without ROS: optional versus required missing/stale reports, reported pressed state, and recovery after a fresh release.
- `test_xbox_teleop_node.py`: Adapts node tests to the extracted interlock and tests that its RViz label reports E-stop and voltage as unknown, released, pressed, stale, or provisional.
- `test_simulated_estop_launch.py`: Launches the simulated safety node, calls its service to press and release the E-stop, and checks that both the Bool topic and diagnostics row reflect each state.
- waybionic_teleop/CMakeLists.txt: No change in this diff; the new Python test is collected by the package’s existing pytest setup.
- waybionic_bringup/CMakeLists.txt: Registers the new simulator integration test with `add_launch_test`.
- waybionic_bringup/package.xml: Adds `std_srvs` as a test dependency because the launch test calls the `SetBool` service.

**RViz Features**
- `xbox_teleop_node.py`: Delegates E-stop decisions to the ROS-free interlock, subscribes to the existing supply-voltage topic, and adds both readings to the teleop marker label. Missing/stale required E-stop status is shown as fail-safe pressed. Voltage is labeled provisional; no thresholds are applied.
- `mock_diagnostics_source.cpp`: Adds E-stop and 24.0 V provisional rows to mock Normal and Fault data, so the diagnostics panel shows these signals in its default mock mode as well as when live diagnostics provide them.
- `test_ros_diagnostics_source.cpp`: Adds coverage that both mock modes include the released E-stop row and the provisional voltage row.
- `waybionic_rviz_plugins/CMakeLists.txt`: Adds the mock diagnostics implementation to the existing test target so that the new C++ test can link it.
@coderabbitai

coderabbitai Bot commented Nov 14, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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