Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/can_drives.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ jobs:
waybionic-can-drives python3 -m pytest -v -p no:cacheprovider
src/waybionic_ground_station/waybionic_teleop/test/test_can_drives.py

# --gtest_fail_if_skipped turns a missing vcan0 into a red job instead of 11 silent skips.
# The binary skips its cases when vcan0 is missing, so a skip, or no passed tests at all,
# fails the job. This googletest has no --gtest_fail_if_skipped: an unknown flag prints
# the help and exits 0 without running anything.
- name: Run the four-node vcan integration test
run: >
docker run --rm --network host waybionic-can-drives
/waybionic_ws/build/waybionic_can/test_vcan_four_node
--gtest_fail_if_skipped
run: |
set -o pipefail
docker run --rm --network host waybionic-can-drives \
/waybionic_ws/build/waybionic_can/test_vcan_four_node | tee four_node.txt
grep -Eq '^\[ PASSED \] [1-9][0-9]* tests?\.' four_node.txt
! grep -q 'SKIPPED' four_node.txt
160 changes: 129 additions & 31 deletions BuildInstructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ can report exit code `-2`, indicating the requested SIGINT interruption.

`teleop:=true` drives the arm with a controller through simulated CAN drives;
nothing is sent to hardware unless you choose a drive bus, as described in
[Real MKS drives over CAN](#real-mks-drives-over-can). The controller mapping is in
`waybionic_teleop/config/xbox_teleop.yaml`, and the placeholder joint-to-drive map
(MKS SERVO42D/57D CAN IDs, gear ratios and the wrist differential) is in
[Real arm](#real-arm-mks-drives-over-can). The controller mapping is in
`waybionic_teleop/config/xbox_teleop.yaml`, and the joint-to-drive map (MKS
SERVO42D/57D CAN IDs, the 26:1 and 3:1 gear ratios and the wrist differential) is in
`waybionic_teleop/config/arm_drives.yaml`.

**Windows (Docker):** connect the controller, then start the teleop version of the
Expand Down Expand Up @@ -443,7 +443,7 @@ zero, including any cable or gear stop.
In simulation, a zero-velocity joint command (including B and controller timeout)
sends an MKS F5 frame with zero speed and zero acceleration to each moving drive.
An out-of-range encoder target stops all drives instead of updating only part of
the arm. The placeholder drive speed is capped at 300 RPM; the MKS manual warns
the arm. The drive speed is capped at 600 RPM (`max_rpm`); the MKS manual warns
against immediate software stops above 1000 RPM. Each drive also runs no faster
than 1.5 times its commanded speed plus 1 RPM, and teleop never advances its
targets by more than two updates at once, so after a pause the drives do not catch
Expand Down Expand Up @@ -504,34 +504,111 @@ Press **Ctrl+C** in its window to stop.

**Linux:** `ros2 launch waybionic_bringup ground_station.launch.py teleop:=true autoplay:=true`.

## Real MKS Drives over CAN
## Real Arm (MKS Drives over CAN)

`drive_interface` sends the same frames to real MKS SERVO42D/57D drives through a
[python-can](https://python-can.readthedocs.io/) interface. The drive map in
`waybionic_teleop/config/arm_drives.yaml` is still a placeholder: check each CAN ID,
gear ratio and direction before the first powered test, and start with the motors
unloaded. Set every drive to the bitrate in that file (1 Mbit/s; the MKS default is
500 kbit/s). On a real bus every drive joint needs a URDF limit before the host holds or
moves anything (`unmodeled_joints` applies to simulation only), so remove the placeholder
`tool` drive from the map, or give its joint a limit in the URDF.
The controller plugs into the computer, not the Arduino. The computer runs the teleop,
the Cartesian moves (inverse kinematics), the joint limits and collision checks, the
RViz twin and the monitor, then sends MKS frames through the carrier: a UNO R4 WiFi with
a TJA1051T transceiver running `waybionic_can/arduino/carrier_bridge`. The carrier only
passes frames between USB and the CAN bus, and reports its own status.

The computer running ROS needs the USB CAN adapter. Docker Desktop on Windows and
macOS cannot reach USB devices, so use native ROS on Linux or macOS (RoboStack), or
Docker on Linux with `--network host`.
```text
controller -> Mac (ROS 2) -> USB, 1 Mbaud -> carrier -> CAN, 1 Mbit/s -> 5 MKS drives
```

Linux, SocketCAN adapter (candleLight firmware):
`waybionic_teleop/config/arm_drives.yaml` maps the joints to the drives: CAN IDs 1-5
(base yaw, shoulder, elbow, wrist left, wrist right), 26:1 cycloidal reducers on the
first three joints and 3:1 belts on the two wrist motors. Its `tool` drive (CAN ID 6) is
a placeholder with no hardware behind it. On a real bus every drive joint needs a URDF
limit before the host holds or moves anything (`unmodeled_joints` applies to simulation
only), and the host waits for every drive in the list, so remove `tool` from `drives`
before driving the real arm. Start with the motors unloaded, and keep the physical E-stop
within reach.

```bash
sudo ip link set can0 up type can bitrate 1000000
ros2 launch waybionic_bringup ground_station.launch.py teleop:=true drive_interface:=socketcan drive_channel:=can0
Before the drives are first powered, Mechanical confirms each joint's signed travel from
the zero pose against the URDF limits, including any cable or gear stop, and someone
shows that the E-stop cuts power to the drives.

The computer running ROS needs the carrier or USB CAN adapter. Docker Desktop on Windows
and macOS cannot reach USB devices, so use native ROS on macOS (RoboStack, below) or
Linux, or Docker on Linux with `--network host` for a SocketCAN adapter.

### On a Mac

Do the [macOS setup](#macos-apple-silicon) first. Then, from the repository root:

1. Flash the carrier once (and after carrier firmware changes). The firmware comes with
PR #40 (`waybionic_can`); until that is merged, `flash` stops and says so. Plug in
only the carrier, so its port is the only `/dev/cu.usbmodem*`; otherwise set
`WAYBIONIC_CARRIER=/dev/cu.usbmodem...`.

```bash
brew install arduino-cli
./scripts/macos.sh flash
```

2. Set up each drive once, alone on the bus: give it its CAN ID (they all ship as 1),
then switch it to 1 Mbit/s. The carrier keeps its first bit rate until it resets, so
replug it, connect every drive, and check they all answer.

```bash
./scripts/macos.sh drives set-id 1 3 # for example the elbow
./scripts/macos.sh drives set-bitrate 3 1000000
# after every drive is switched: replug the carrier
./scripts/macos.sh drives --bitrate 1000000 scan
```

3. With `tool` removed from `drives` in `arm_drives.yaml`, put the arm in the zero pose
(upright, as RViz shows it before anything moves) and start the ground station. A
controller plugged into the Mac (USB or Bluetooth) drives the arm and its twin
together:

```bash
./scripts/macos.sh arm
```

4. In a second Terminal, zero the drives with teleop still disabled, then press Start on
the controller:

```bash
./scripts/macos.sh run ros2 service call /sim_arm_drives/zero std_srvs/srv/Trigger
```

5. Check each joint's direction at the slowest speed in the `upper` group. If a drive
turns the wrong way, negate its `factors` in `arm_drives.yaml` and rebuild. Then move
each joint a known angle, such as 10 degrees in RViz, and measure it on the arm; a
different angle means its `gear_ratio` in `arm_drives.yaml` is wrong.

**Remote operator.** The controller can stay with an operator on another computer. On
the operator's Windows computer, run the controller bridge pointed at the Mac's address:

```powershell
cd waybionic_teleop
python -m waybionic_teleop.xinput_bridge --host 192.168.1.20
```

macOS or Linux, serial-line (slcan) adapter:
On the Mac, listen on the network:

```bash
ros2 launch waybionic_bringup ground_station.launch.py teleop:=true drive_interface:=slcan drive_channel:=/dev/tty.usbmodem1101
./scripts/macos.sh arm joy_source:=udp joy_udp_bind:=0.0.0.0
```

The receiver takes controller packets from any computer that can reach its port, so do
this only on a private network.

### The engineering monitor

With `teleop:=true` the monitor shows live rows:

| Row | Shows |
| --- | --- |
| `controller.link` | Remote controller only: packet rate, loss, jitter, longest gap and network round trip; warns past 2% loss, a 100 ms gap or a 50 ms round trip |
| `teleop.input` | Whether controller input is arriving; teleop disables itself after 0.5 s without it |
| `arm.command_gate` | Whether the drives take teleop's commands, or why they stopped |
| `can.carrier` | The carrier's USB link (reopened every second if unplugged), E-stop and supply (once wired), CAN controller errors, and frames the carrier refused |
| `can.bus` | Frames per second and bus load |
| `drive.*`, `arm.*` | Each drive's reply state and encoder, each joint against its target, and whether the arm is zeroed |

**Zeroing.** The encoders count from where the drives were powered on, so the host
publishes no joint states and moves nothing until the arm is zeroed. Put the arm in
the zero pose (the pose RViz shows before anything moves), leave teleop disabled, and
Expand All @@ -542,16 +619,37 @@ ros2 service call /sim_arm_drives/zero std_srvs/srv/Trigger
```

Then press Start. Real drives take commands through the same gate as the simulated ones.
If a drive stops answering, for example because the E-stop cut its power, or its encoder
count jumps further than `max_rpm` allows between two readings, as after a brief power
loss, every drive stops and the arm must be zeroed again. The same happens when a drive
reports a failed move (as when its stall protection releases the motor) or an end-limit
stop, or stays more than `following_error_counts` from its target for
`following_error_ticks` ticks; both are provisional values in `arm_drives.yaml`. If the
joint commands stop for 0.5 s, every drive stops where it is, and if the host stops, the
If a drive stops answering, for example because the E-stop cut its power or the carrier
was unplugged, or its encoder count jumps further than `max_rpm` allows between two
readings, as after a brief power loss, every drive stops and the arm must be zeroed
again. The same happens when a drive reports a failed move (as when its stall protection
releases the motor) or an end-limit stop, or stays more than `following_error_counts` from
its target for `following_error_ticks` ticks; both are provisional values in
`arm_drives.yaml`. Once Electrical wires the carrier's E-stop sense, pressing the E-stop
also stops every drive at once, and Start is refused until it is released. If the joint
commands stop for 0.5 s, every drive stops where it is, and if the host stops, the
drives' heartbeat stops them. A stop frame the adapter refuses is sent again on every
tick, and Start is refused until it has gone out. After any stop, disable teleop and press
Start again.
tick, and Start is refused until it has gone out. The carrier answers a frame it cannot
pass on yet with BELL; the host sends a refused move, stop or setup frame again on the
next tick, and a refused zero while the zero service waits. After any stop, disable
teleop and press Start again.

### On Linux

With the carrier, set up the drives with `mks_setup` (the commands in step 2 above), then
launch:

```bash
ros2 run waybionic_teleop mks_setup --channel /dev/ttyACM0 scan
ros2 launch waybionic_bringup ground_station.launch.py teleop:=true drive_interface:=slcan drive_channel:=/dev/ttyACM0
```

A SocketCAN adapter (candleLight firmware):

```bash
sudo ip link set can0 up type can bitrate 1000000
ros2 launch waybionic_bringup ground_station.launch.py teleop:=true drive_interface:=socketcan drive_channel:=can0
```

**Without hardware.** `mks_drive_sim` answers on a CAN interface the way the drives
do, so the host can be tested end to end over a virtual CAN interface on Linux:
Expand Down
4 changes: 4 additions & 0 deletions robostack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dependencies:
- ros-jazzy-rviz-imu-plugin
- ros-jazzy-xacro
- ros-jazzy-joint-state-publisher-gui
# A controller plugged into the Mac (joy_source:=device).
- ros-jazzy-joy
- colcon-common-extensions
- compilers
- cmake
Expand All @@ -20,6 +22,8 @@ dependencies:
- ninja
- pytest <9
- python-can
# The carrier's USB serial link to the real arm.
- pyserial
# colcon still relies on the legacy `develop` and `test` commands removed by
# newer setuptools. Keep Python ROS packages editable and testable on macOS.
- setuptools <72
58 changes: 58 additions & 0 deletions scripts/macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ Commands:
setup Create/update the RoboStack environment and build the workspace
build Build the workspace
launch Launch the ground station visualization
flash Compile and upload carrier_bridge to the UNO R4 WiFi (needs arduino-cli)
drives Set up the MKS drives through the carrier, e.g. drives scan (see mks_setup)
arm Drive the real arm: controller on this Mac, carrier on USB
run Run any command inside the ROS workspace

The carrier is found as the only /dev/cu.usbmodem* port; set WAYBIONIC_CARRIER to choose.
EOF
}

Expand Down Expand Up @@ -133,6 +138,41 @@ run_workspace() {
' _ "$ROOT" "$@"
}

find_carrier() {
local ports

if [[ -n "${WAYBIONIC_CARRIER:-}" ]]; then
[[ -e "$WAYBIONIC_CARRIER" ]] || fail "WAYBIONIC_CARRIER=$WAYBIONIC_CARRIER does not exist"
CARRIER="$WAYBIONIC_CARRIER"
return
fi
shopt -s nullglob
ports=(/dev/cu.usbmodem*)
shopt -u nullglob
case "${#ports[@]}" in
0) fail "no /dev/cu.usbmodem* port: plug in the carrier (UNO R4 WiFi)" ;;
1) CARRIER="${ports[0]}" ;;
*) fail "several ports (${ports[*]}); set WAYBIONIC_CARRIER to the carrier's" ;;
esac
}

flash_carrier() {
local fqbn="arduino:renesas_uno:unor4wifi"
local sketch="$ROOT/waybionic_can/arduino/carrier_bridge"
local library="$ROOT/waybionic_can/arduino/libraries/WaybionicCan"

[[ -f "$sketch/carrier_bridge.ino" ]] \
|| fail "carrier_bridge is not in this checkout yet: it comes with PR #40 (waybionic_can)"
command -v arduino-cli >/dev/null 2>&1 \
|| fail "install arduino-cli first: brew install arduino-cli"
find_carrier
arduino-cli core update-index
arduino-cli core install arduino:renesas_uno
arduino-cli compile --fqbn "$fqbn" --library "$library" "$sketch"
arduino-cli upload --fqbn "$fqbn" --port "$CARRIER" "$sketch"
echo "Flashed carrier_bridge to $CARRIER"
}

command_name="${1:-help}"
if [[ $# -gt 0 ]]; then
shift
Expand All @@ -158,6 +198,24 @@ case "$command_name" in
run_workspace env RMW_IMPLEMENTATION="${RMW_IMPLEMENTATION:-rmw_cyclonedds_cpp}" \
ros2 launch waybionic_bringup ground_station.launch.py "$@"
;;
flash)
check_host
flash_carrier
;;
drives)
[[ $# -gt 0 ]] || fail "drives needs an mks_setup command, such as scan"
prepare
find_carrier
run_workspace ros2 run waybionic_teleop mks_setup --channel "$CARRIER" "$@"
;;
arm)
prepare
find_carrier
echo "Carrier: $CARRIER"
run_workspace env RMW_IMPLEMENTATION="${RMW_IMPLEMENTATION:-rmw_cyclonedds_cpp}" \
ros2 launch waybionic_bringup ground_station.launch.py teleop:=true \
joy_source:=device drive_interface:=slcan drive_channel:="$CARRIER" "$@"
;;
run)
[[ $# -gt 0 ]] || fail "run requires a command"
prepare
Expand Down
7 changes: 4 additions & 3 deletions waybionic_bringup/launch/ground_station.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ def generate_launch_description():

drive_interface_arg = DeclareLaunchArgument(
'drive_interface', default_value='sim',
description='Drive bus: sim for simulated drives, or a python-can interface such as '
'socketcan or slcan for the real MKS drives')
description='Drive bus: sim for simulated drives, slcan for the WayBionic carrier on '
'a USB serial port, or a python-can interface such as socketcan')

drive_channel_arg = DeclareLaunchArgument(
'drive_channel', default_value='',
description='CAN channel for a real drive bus, such as can0 or /dev/ttyACM0')
description='The carrier serial port or CAN channel, such as /dev/cu.usbmodem1101, '
'/dev/ttyACM0 or can0')

joy_source_arg = DeclareLaunchArgument(
'joy_source', default_value='device',
Expand Down
17 changes: 13 additions & 4 deletions waybionic_bringup/test/test_teleop_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,17 @@ def hold(seconds, *pressed, **axes):
sequence += 1
sender.sendto(gamepad.pack(sequence, packet_axes, buttons), ('127.0.0.1', PORT))
rclpy.spin_once(node, timeout_sec=0.02)
try:
rumbles.append(gamepad.unpack_rumble(sender.recv(64)))
except BlockingIOError:
pass
while True:
try:
data, station = sender.recvfrom(64)
except BlockingIOError:
break
# Answer the station's pings as the bridges do.
answer = gamepad.pong(data)
if answer is not None:
sender.sendto(answer, station)
else:
rumbles.append(gamepad.unpack_rumble(data))

def group():
# Only a report sent after the last press counts.
Expand Down Expand Up @@ -174,6 +181,8 @@ def group():
self.assertTrue(rumbles, 'the controller never rumbled')
self.assertGreater(rumbles[0], 0.0)
self.assertEqual(rumbles[-1], 0.0)
link = {value.key: value.value for value in diagnostics['controller.link'].values}
self.assertNotEqual(link['round_trip_ms'], '', 'the link was never timed')
finally:
hold(0.2, 'b')
sender.close()
Expand Down
4 changes: 2 additions & 2 deletions waybionic_can/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ if(BUILD_TESTING)
endif()
endforeach()

# Skips itself when the vcan interface is missing. The privileged can_drives.yml job
# runs this binary with --gtest_fail_if_skipped so a missing vcan0 cannot pass CI.
# Skips itself when the vcan interface is missing. The can_drives.yml job runs this binary
# with vcan0 and fails if any case skips, so a missing vcan0 cannot pass CI.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
ament_add_gtest(test_vcan_four_node tests/integration/test_vcan_four_node.cpp TIMEOUT 240)
if(TARGET test_vcan_four_node)
Expand Down
7 changes: 3 additions & 4 deletions waybionic_can/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ Here is what an exchange looks like. Receivers 1 and 3 log `ignored (addressed t

## Hardware status and TODOs

- **Set CAN ID and bitrate:** 8Bh and 8Ah are not implemented in the shared C++ subset. F7h
emergency stop is implemented from MKS manual section 9.2.3. The Python `EMERGENCY_STOP`
helper matches [PR #45](https://github.com/Waybionic/waybionic_ground_station/pull/45); if
that PR lands first, keep main's copy of `emergency_stop()` and the F7h `sim_drives.py` branch.
- **Set CAN ID and bitrate:** 8Bh and 8Ah are not implemented in the shared C++ subset; the
Python `mks_can.py` has them for `mks_setup`. F7h emergency stop is implemented from MKS
manual section 9.2.3.
- **Broadcast ID 0 and other MKS commands:** not implemented in the C++ bench subset.
- **Physical receiver actuator:** the bench receivers use `SoftwareActuator`. A hobby-servo `IActuator` would need a defined mapping from MKS axis counts to angles and of what READ_ENCODER reports.
- **Carrier telemetry hardware:** status ID `0x7F0` reports unknown E-stop/supply plus CAN error
Expand Down
Loading
Loading