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
85 changes: 85 additions & 0 deletions backend/configs/machines/openuc2-first-cord-30059-mixed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Pi 192.168.0.46: migrated from the selected ImSwitch FRAME.json on 2026-11-03.
# Mixed test setup 2026-11-12: Serial axes/LED plus CAN RGB LED node 20.
# The CAN light uses the firmware LED-array interface; it is a separate USB bus.
# X/Y: 0.396 um/step; Z: 0.3125 um/step. Speeds below are conservative initial settings.
# No automatic homing. A retains the legacy linear calibration in um.
# Camera omitted: installed MVS SDK is incompatible with the pinned camera driver.
newswitch_version: v1.0.2
devices:
serial-master:
type: controller
name: UC2 Serial controller
connection:
protocol: uc2-rest
transport:
type: serial
port: /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0
baudrate: 115200
mapping:
axis-x: {type: serial-motor, id: 1}
axis-y: {type: serial-motor, id: 2}
axis-z: {type: serial-motor, id: 3}
axis-a: {type: serial-motor, id: 0}
illumination-led: {type: serial-laser, id: 1, pwm_max: 1023}
sample-stage:
type: stage
axes: {x: axis-x, y: axis-y, z: axis-z, a: axis-a}
homing_order: [z, x, y, a]
registered_step_sizes: [1, 10, 100]
axis-x:
type: axis
steps_per_um: 2.525252525252525
homing_required: false
homing_direction: -1
homing_speed_steps: 10000
homing_endstop_polarity: 1
homing_timeout_ms: 20000
vel: {value: 1000, min: 1, max: 5940, unit: um/s}
axis-y:
type: axis
steps_per_um: 2.525252525252525
homing_required: false
homing_direction: -1
homing_speed_steps: 10000
homing_endstop_polarity: -1
homing_timeout_ms: 20000
vel: {value: 1000, min: 1, max: 5940, unit: um/s}
axis-z:
type: axis
steps_per_um: 3.2
homing_required: false
homing_direction: 1
homing_speed_steps: 10000
homing_endstop_polarity: -1
homing_timeout_ms: 20000
vel: {value: 500, min: 1, max: 4687.5, unit: um/s}
axis-a:
type: axis
steps_per_um: 2.525252525252525
homing_required: false
homing_direction: -1
homing_speed_steps: 10000
homing_endstop_polarity: 1
homing_timeout_ms: 20000
vel: {value: 1000, min: 1, max: 5940, unit: um/s}
illumination-led:
type: lightsource
name: Illumination LED
coherence: incoherent
can-led-controller:
type: controller
name: USB CAN LED controller
connection:
protocol: canopen
transport:
type: can
interface: waveshare
port: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
bitrate: 500000
mapping:
can-illumination-led: {type: canopen-led-matrix, id: 20}
can-illumination-led:
type: lightsource
name: CAN RGB LED
coherence: incoherent
channels: 3
7 changes: 5 additions & 2 deletions backend/newswitch/managers/uc2/canopen_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
PositionUpdate,
UC2Event,
UC2State,
UC2TransportState,
)

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -86,9 +87,11 @@ class UC2CanBusConfig:
class UC2CanBus:
"""UC2BusManager implementation speaking CANopen via uc2canopen."""

state: UC2State
state: UC2State | UC2TransportState

def __init__(self, state: UC2State, config: Optional[UC2CanBusConfig] = None) -> None:
def __init__(
self, state: UC2State | UC2TransportState, config: Optional[UC2CanBusConfig] = None
) -> None:
"""Initialize the CAN transport with shared bus state (no I/O yet)."""
self.state = state
self.config = config or UC2CanBusConfig()
Expand Down
7 changes: 5 additions & 2 deletions backend/newswitch/managers/uc2/rest_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
PositionUpdate,
UC2Event,
UC2State,
UC2TransportState,
)

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -69,9 +70,11 @@ class UC2RestBusConfig:
class UC2RestBus:
"""UC2BusManager implementation speaking the UC2-REST serial JSON protocol."""

state: UC2State
state: UC2State | UC2TransportState

def __init__(self, state: UC2State, config: Optional[UC2RestBusConfig] = None) -> None:
def __init__(
self, state: UC2State | UC2TransportState, config: Optional[UC2RestBusConfig] = None
) -> None:
"""Initialize the serial transport with shared bus state (no I/O yet)."""
self.state = state
self.config = config or UC2RestBusConfig()
Expand Down
7 changes: 5 additions & 2 deletions backend/newswitch/managers/uc2/yaml_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from rekuest_next.state.lock import acquired_locks
from newswitch.protocols.uc2 import (
UC2State,
UC2TransportState,
UC2Event,
PositionUpdate,
MotionDone,
Expand Down Expand Up @@ -340,7 +341,9 @@ def _bus_for(self, connection: Connection) -> HardwareBus:
raise ValueError(
"UC2 Serial timing uses client defaults; configure movement/homing deadlines per axis"
)
bus = UC2RestBus(UC2State(), UC2RestBusConfig(serialport=t.port, baudrate=t.baudrate))
bus = UC2RestBus(
UC2TransportState(), UC2RestBusConfig(serialport=t.port, baudrate=t.baudrate)
)
else:
if not isinstance(t, CanTransport):
raise ValueError("Direct CANopen requires a CAN transport")
Expand All @@ -349,7 +352,7 @@ def _bus_for(self, connection: Connection) -> HardwareBus:
if t.interface not in ("socketcan", "waveshare"):
raise ValueError(f"UC2 CAN runtime does not support {t.interface}")
bus = UC2CanBus(
UC2State(),
UC2TransportState(),
UC2CanBusConfig(
interface=t.interface,
channel=t.channel,
Expand Down
11 changes: 8 additions & 3 deletions backend/newswitch/protocols/uc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ class BusError:
# ---------------------------------------------------------------------------


@state
@dataclass
class UC2State:
"""Connection, identity, and safety state of the UC2 hardware bus."""
class UC2TransportState:
"""Private connection state of one physical transport; never publishes UI patches."""

connected: bool = False
transport: str = "virtual"
Expand All @@ -119,6 +118,12 @@ class UC2State:
last_error: str = ""


@state
@dataclass
class UC2State(UC2TransportState):
"""Connection, identity, and safety state of the UC2 hardware bus."""


# ---------------------------------------------------------------------------
# Bus protocol
# ---------------------------------------------------------------------------
Expand Down
37 changes: 37 additions & 0 deletions backend/tests/test_yaml_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,40 @@ def test_serial_stable_symlink_resolves_for_uc2_port_lookup(tmp_path: Path) -> N
doc["devices"]["my-standalone-board"]["connection"]["transport"]["port"] = str(stable)
bus = runtime(doc)
assert bus.axes["X"].bus.config.serialport == str(target)


@pytest.mark.asyncio
async def test_private_transport_updates_do_not_publish_false_connected_state() -> None:
"""A connected Serial bus must not overwrite the aggregate when CAN is down."""
from rekuest_next.state.publish import BasePublisher

doc = yaml.safe_load(
(DEMOS.parent / "machines" / "openuc2-first-cord-30059-mixed.yaml").read_text()
)
bus = runtime(doc)
published = []
holder = SimpleNamespace(publish_patch=lambda name, patch: published.append((name, patch)))
with BasePublisher(holder):
serial, can = list(bus.buses.values())
serial.state.connected = True
serial.state.transport = "rest"
can.state.transport = "canopen"
can.state.last_error = "CAN offline"
assert published == []
assert not bus.state.connected
task = asyncio.create_task(bus._mirror_state())
await asyncio.sleep(0)
assert not bus.state.connected
assert bus.state.last_error == "CAN offline"
assert not any(p.path == "/connected" and p.value is True for _, p in published)
can.state.connected = True
can.state.last_error = ""
await asyncio.sleep(0.12)
assert bus.state.connected
assert bus.state.last_error == ""
Comment thread
Copilot marked this conversation as resolved.
Resolved
assert any(
name == "UC2State" and p.path == "/connected" and p.value is True
for name, p in published
)
task.cancel()
await asyncio.gather(task, return_exceptions=True)
Loading