# Model-Based Virtual Components in Event-Based Controls: Linking the FMI and IEC 61499
## 3 Generic Virtual Components
### Predictive Event Mapping  
One major drawback of periodic event mapping is that instant changes in both the FMI model and the automation system cannot be directly communicated, but have to be delayed until the next communication point \(t_{i+1}\). Hence, the event mapping may be well-suited for periodic control and communication schemes, but hinders asynchronous integration of virtual components. In particular, for delay-sensitive applications, a considerable deviation may be introduced, and \(T_{\text{a}}\) needs to be carefully chosen. The predictive approach proposed in [7,8] and illustrated in Figure 3 can be used to dynamically choose the next synchronization point and to reduce nominal delays. For predictive event mapping, FMI events and IEC 61499 events are directly mapped without introducing periodic synchronization events \(e_{i}\). Nevertheless, an FMU or the interface program may choose to trigger intermediate events to communicate altered continuous outputs. To provide adaptive synchronization, the predictive approach solves the included FMU until the next communication need is encountered [7,8]. The prediction is conducted under the assumption that no external event that potentially changes inputs is scheduled. As soon as an external event is scheduled before the upcoming predicted event, the state of the model is reset to the time instant of the external event, the predicted event that was added to the event queue before is invalidated, and the prediction cycle starts anew. In order to aid resetting the FMU, multiple intermediate states that can be quickly recalled without repeating numerical integration are periodically stored. While in non-real-time applications with revocable events, exact synchronization is feasible [7,8], special attention has to be placed on real-time operation. Again, precise real-time operation would be established if all FMI events \(e\) are triggered in time (1). Define \(f_{k}(e)\) as the time when component \(k\) finishes processing the arbitrary event \(e\), and assume that event \(e_{a-1}\) has to be processed just before the FMI event \(e_{a}\). To predict one event fully, including its associated values, and to advance the progress function \(p_{\text{FMU}}(t)\) at the real time instant \(t\) to \(p_{\text{FMU}}(t)=t(e_{a})\), one needs to predict the upcoming event \(e_{a}\), call the FMI event update function, and manage the output calculation and transmission [25]. When assuming that predicting one event takes at most \(W_{\text{pred}}\) and managing the model outputs has a WCET of \(W_{\text{out}}\), \(e_{a}\) can be safely triggered in time if:  
\[f_{\text{FMU}}(e_{a-1})+W_{\text{pred}}+W_{\text{upd}}+W_{\text{out}}<t(e_{a}). \tag{3}\]  
In general, IEC 61499 events \(e\) may be enqueued and processed out of time, i.e., \(f_{\text{FMU}}(e)>t(e)\). Consequently, the time from which on an FMI event \(e_{a}\) is safely permitted depends on the type and time of previous events \(e_{b}\), \(t(e_{b})\leq t(e_{a})\). In order to reduce the event interdependency, one can assert that each event is immediately processed and that \(e_{a-1}\) is triggered in a timely manner, i.e., Equation (1) is satisfied for the event origin \(k\)[25]. First, let \(e_{a-1}\) be an event from the automation system and assume that processing \(e_{a-1}\) takes at most \(W_{\text{a-upd}}\). Consequently, (3) implies:  
Figure 3: Predictive event mapping: Predicted events will be invalidated and updated as soon as events from the automation system arrive. \[t(e_{a-1})+W_{\text{a-upd}}+W_{\text{pred}}+W_{\text{upd}}+W_{\text{out}}<t(e_{a}). \tag{4}\]  
Second, let \(e_{a-1}\) be an FMI event. By definition, processing \(e_{a-1}\) ends as soon as it is fully predicted and (3) implies (5) and (4), as well.