# CarTwin--Development of a Digital Twin for a Real-World In-Vehicle CAN Network
## 4 System Level Implementation Based on Simulink Models
**Powertrain Control Module (PCM):** The PCM implements very complex functionalities in order to ensure the efficiency and stability of the engine. In our model, we compute the main functionalities of the PCM, i.e., acceleration, torque, gear, engine speed, engine power, air mass flow, fuel flow, exhaust temperature, efficiency and emission performance. In Figure 8, we depict our implementation of the PCM module. Based on vehicle speed, as outlined in Equation (5), we compute the vehicle acceleration as the derivative of the vehicle speed with respect to time: \[acc=\frac{dv}{dt}\] (5) As part of the equation terms, \(acc\) is the acceleration, \(v\) is the vehicle speed and \(t\) represents the time. In order to eliminate the spike of the acceleration value, we apply two low pass filters with a filtering coefficient of 0.1. The gear is computed using a interpolation table, which has as an input the vehicle speed and uses the flat interpolation method to select the corresponding value of the gear. Based on the  
Figure 6: Simulink model for Power Steering Control Module (PSCM) ECU. engine speed and gear, we estimate the engine torque using a 2-D lookup table. Using the gear of the vehicle, we compute the engine speed as presented in Equation (6):  
\[engineSpeed=shaftVS\times axleRatio\times trRatio \tag{6}\]  
In the equation above, _engineSpeed_ is the engine speed, _shaftVS_ is the shaft vehicle speed, _axleRatio_ is the axle ratio and _trRatio_ is the transmission ratio for each gear. The shaft vehicle speed is computed based on vehicle speed as shown in Equation (7):  
Figure 3:0  
Figure 3:1 Simulink model for Anti-lock Brake System (ABS) ECU. In this case, \(v\) is the vehicle speed and 0.381(m) is the considered wheel radius. To compute other powertrain signals, we used the Mapped SI Engine block from the Simulink library, which implements a spark-ignition engine model based on the torque and engine speed. This model uses several look-up tables to compute the engine air mass flow, normalized engine cylinder air mass, air-fuel ratio (AFR), engine fuel flow, volumetric fuel flow, engine exhaust gas temperature, engine crankshaft absolute angle, engine brake-specific fuel consumption, engine out hydrocarbon emission mass flow, engine out carbon monoxide emission mass flow rate, engine out nitric oxide and nitrogen dioxide emissions mass flow, engine out carbon dioxide emission mass flow, engine out particulate matter emission mass flow, crankshaft power, fuel input power and power loss. 4. **Instrument Panel Cluster (IPC):** The IPC module displays considerable information for the driver that is received from other ECUs or are internally computed. In our work, the IPC module computes the trip distance, average vehicle speed and the buckle alert. In Figure 9i, we show the model for the calculation of the the buckle status (if the car is moving with more than 10 m/s and the seatbelt is not buckled, the buckle alert is shown to the driver). In Figure 9 ii, we show the implementation of the trip distance, which is computed as the integral of vehicle speed as outlined in Equation (8):  
Figure 3:2  
As equation terms in Equation (8), _dist_ is the trip distance, \(v\) is the vehicle speed and \(t\) is the time. Due to the fact that the vehicle speed is computed in m/s in our models, in order to have the trip distance in km, we convert it from meter to kilometer and round it to two decimals. In Figure 9 iii, we depict the calculation on the average vehicle speed. 5. **Restraints Control Module (RCM):** In Figure 10i, we show the Simulink model for the calculation of the airbag status based on vehicle speed and buckle status (if the car is moving with more than 10 m/s and the seatbelt is buckled, the airbag is active). Figure 3:3 Simulink model for Powertrain Control Module (PCM) ECU. 6. **Accessory Protocol Interface Module (APIM):** In Figure 10 ii, we show the Simulink model for the calculation of the rear camera status based on direction. If the car is moving in reverse, the rear camera is turned on.