Skip to content

Event handling

Peter Corke edited this page Jun 7, 2021 · 3 revisions

This concerns the integration of system dynamics when the input is discontinuous. The integrators from SciPy (default RK45) is a variable step integrator, and it is possible that it can take a step over a change in input, say from a step generator, which will lead to an inaccurate solution.

More sophisticated integrators support the notion of events, specific times when there is a change in the input or the system, and the integrator pays attention to the solution around those points. For example:

For bdsim we use a simple workaround where the integration is performed in segments. From t=0 to t_1, then t_1 to t_2, t_2 to t_3, ... t_N-1 to t_N. Where t_i are event times. The blocks that currently support events are:

  • STEP
  • RAMP
  • PIECEWISE
  • WAVEFORM for square and triangular waveforms

Implementation

At simulation start the start method of these blocks computes all the event times, times of discontinuities in their outputs, upto the maximum integration time and pushes them into a priority queue which is part of the simstate object

sim state.declare_event(block, time)

The block declaring the event is provided for debugging and possible future use.

The same mechanism is used to support integration of hybrid discrete-time systems.

Future

Events can also be a function of state, but this is beyond the current simplistic implementation.