Abstract
Hybrid simulations of cyber-physical systems often suffer from "untrapped" errors—silent failures that produce physically impossible results without alerting the user. This paper introduces the Limbo State framework, a conceptual model for simulators to detect and resolve such errors. By distinguishing between safe, limbo, and unsafe states, we propose methods for safety-augmented zero-crossing detection and deterministic event handling. Implementations in Modelica and Ptolemy II demonstrate how this approach prevents common artifacts like object tunneling and accidental determinism in simultaneous events.
Introduction
The reliability of a simulation is typically measured by its fidelity to the physical world. However, for safety-critical Cyber-Physical Systems (CPS), fidelity alone is insufficient; the simulation environment itself must be "safe." Borrowing from programming language theory, a safe simulation is one where all errors are "trapped" (detected and reported) rather than "untrapped" (silent failures). This paper addresses two major untrapped errors: unsafe zero-crossing detection and accidental determinism.
The Problem: Untrapped Errors in Hybrid Systems
Hybrid simulators use zero-crossing detection to trigger discrete events. Numerical imprecision can lead to Unsafe Zero-Crossing Detection, where an event is missed because the signal magnitude falls below the simulator's tolerance. As shown in Figure 1, this causes a bouncing ball to "tunnel" through the ground.
Another issue is Accidental Determinism, which occurs when simultaneous events are resolved in an arbitrary order by the simulator. This produces repeatable but physically inconsistent results, masking the underlying ambiguity of the model.
Methods: The Limbo State Framework
We propose modeling the simulator as a finite state machine with a Limbo State. This state represents a "gray area" where the simulator detects a potential error or ambiguity before it leads to an invalid result.
Three-Level Zero-Crossing
Instead of a single zero-crossing line, we implement a three-level system: Safe, Limbo, and Unsafe. If the system enters the Limbo region (e.g., a very low bounce height), the modeler can define a safe exit, such as transitioning the ball to a resting state. Crossing into the Unsafe region triggers an immediate trapped error.
Deterministic Event Handling
When multiple events occur within a numerical tolerance of each other, the simulator enters Limbo. The modeler must explicitly define how to handle these simultaneous cases (e.g., using an elsewhen construct). If no logic is provided, the simulator throws an error rather than making an arbitrary choice.
Results and Discussion
The framework was evaluated using the Three-Ball Elastic Collision model. As illustrated in Figure 3, different event orderings in simultaneous collisions can lead to wildly divergent trajectories. By requiring explicit resolution, the Limbo State framework ensures that simulation outcomes are physically grounded and intentional.
Successful implementations were demonstrated in Modelica and Ptolemy II. In Modelica, safety-augmented models correctly transitioned to stable states or terminated with errors instead of tunneling. In Ptolemy II, a custom "Safe Level-Crossing Detector" actor enabled robust mode changes upon detecting potential failures.
Conclusion and Future Work
The Limbo State framework transforms silent simulation failures into manageable, trapped errors. Future work should explore automating these safety checks within modeling languages via language extensions or static analysis to detect missing event handlers before simulation starts.
Summary updated