FMU ME: Bouncing Ball
This example demonstrates Model Exchange FMU integration with PathSim. Unlike co-simulation FMUs, Model Exchange FMUs provide only the differential equations. PathSim's solvers perform the numerical integration and event detection.
You can also find the FMU integration tests in the GitHub repository.
The bouncing ball combines continuous dynamics with discrete events:
MATHDISPLAY0ENDMATH MATHDISPLAY1ENDMATH
where MATHINLINE2ENDMATH is height, MATHINLINE3ENDMATH is velocity, and MATHINLINE4ENDMATH. At impact (MATHINLINE5ENDMATH), velocity reverses with energy loss: MATHINLINE6ENDMATH where MATHINLINE7ENDMATH is the restitution coefficient.
This example demonstrates the ModelExchangeFMU block, which provides PathSim with continuous states and derivatives from an FMU. PathSim's solvers handle integration, event detection, and error control.
Import and Setup
Note that FMPy must be installed to use FMU blocks:
pip install fmpy
FMU Path
The FMU contains binaries for multiple platforms (Windows, Linux, macOS):
System Definition
The ModelExchangeFMU block exposes continuous states $(h, v)$ and provides derivatives $(\dot{h}, \dot{v})$ to PathSim's solvers. Event indicators signal zero-crossings for accurate bounce detection.
Display FMU metadata:
Simulation Setup
PathSim integrates the FMU using an adaptive Runge-Kutta solver (RKBS32) with error control. The solver automatically adjusts timesteps for accurate event detection.
Results
Plot the trajectory:
Event Visualization
Mark the detected bounce events: