In cyber-physical systems, a controller often has a hard deadline on when the result of a computation needs to be available. This means the design needs to have predictable delays, making FPGAs a natural candidate for controlling these systems.
The Tunneling Ball Device is an appealing device that contains many elements typical of cyber-physical systems. The picture to the right identifies several components. Two sensors (b) and (c) are mounted above a spinning disc (e). Balls (d) are dropped from above the top sensor through a release platform (a). A motor (f) drives a spinning disc containing two holes. In the short time available after the ball passes sensor (c), the disc’s rotary trajectory is adjusted such that the ball will pass through one of the two holes. The device has no control over the balls; its only course of action is to adjust the disc trajectory.
Typical cyber-physical concepts present in the device include observation (disc position, trajectory of the falling balls), prediction (anticipated moment of ball passing through the disc), physical control (motor-driven spinning disc), and feedback (motor / rotary sensor). Correctly adjusting the disc trajectory, and doing so in the short time available as a steel ball drops over a few decimeters, requires high-speed, hard real-time control. It is also a point where computation and physics come together in a fashion typical of cyber-physical systems.
Clash code is an executable Haskell program and can be freely combined with other regular Haskell code, including GUIs. Our approach enables incremental development and refinement, verifying behavior and properties at every step. Design ideas can be easily tested as a program running on the computer, before adding the detail that makes it a functional hardware design. Simultaneously, the language encourages proper structure such that the eventual hardware design is a refinement of the original code rather than a re-implementation.
Thanks to Clash, we were able to verify our design was sound and go from specification to implementation smoothly, while feeling confident every refinement did not unintentionally change behavior. Additionally, Clash allows for advanced forms of parameterization and compile-time computation that enhances code reuse, genericity, and clarity. Reasoning about correctness is not hindered by implementation details, but the final system is as performant as hand specialized functions would have been. The project successfully demonstrated Clash’s suitability for designing control systems in cyber-physical systems.