Skip to main content
Version: 0.2.7

synapsys.hw — Hardware Abstraction

Hardware abstraction layer for connecting Synapsys agents to physical devices (FPGAs, microcontrollers, PLCs) or in-process stubs for testing.

HardwareInterface (Abstract Base Class)​

Pluggable interface for bridging real hardware into the transport layer. All concrete implementations must subclass HardwareInterface and implement the four abstract methods below.

from synapsys.hw import HardwareInterface
Property / MethodDescription
n_inputs (property)Number of actuator channels (columns of u)
n_outputs (property)Number of sensor channels (rows of y)
connect() -> NoneOpens the hardware connection
disconnect() -> NoneCloses the hardware connection
read_outputs(timeout_ms=100) -> np.ndarrayReads sensor data from hardware
write_inputs(u, timeout_ms=100) -> NoneSends actuator command to hardware

HardwareInterface also implements the context manager protocol (__enter__ / __exit__), so with hw: automatically calls connect() and disconnect().

MockHardwareInterface​

In-process hardware stub for unit-testing and HIL demos without physical devices.

from synapsys.hw import MockHardwareInterface
MockHardwareInterface(
n_inputs: int,
n_outputs: int,
plant_fn: Callable[[np.ndarray], np.ndarray] | None = None,
latency_ms: float = 0.0,
)
ParameterDescription
n_inputsNumber of actuator channels
n_outputsNumber of sensor channels
plant_fnf(u) -> y called on every write_inputs. Defaults to y = u when dimensions match, otherwise zeros
latency_msArtificial round-trip delay for jitter-tolerance testing

Example — first-order discrete plant:

from synapsys.hw import MockHardwareInterface
import numpy as np

state = [0.0]
def plant_fn(u):
state[0] = 0.9 * state[0] + 0.1 * u[0]
return np.array([state[0]])

hw = MockHardwareInterface(n_inputs=1, n_outputs=1, plant_fn=plant_fn)
with hw:
hw.write_inputs(np.array([1.0]))
y = hw.read_outputs() # → approx [0.1]

Planned implementations (v0.5)​

ClassHardware
SerialHardwareInterfaceESP32, STM32 via UART
OPCUAHardwareInterfacePLCs, industrial SCADA (OPC-UA)
FPGAHardwareInterfaceFPGA/FPAA low-latency co-simulation
ROSTransportROS 2 robotics bridge

Source​

See synapsys/hw/ on GitHub.