# CarTwin--Development of a Digital Twin for a Real-World In-Vehicle CAN Network
## 1 Introduction and Motivation  
During the last two decades, vehicles evolved towards software-driven objects, requiring a large number of Electronic Control Units (ECUs) that communicate over intricate in-vehicle networks. This evolution is based on the industry's need to develop new automotive functions, e.g., adaptive cruise control, or to digitize existing functions, e.g., steer-by-wire. As confirmed by recent studies related to automotive trends [1], the near future will bring even more hardware and software updates to reach a new milestone for autonomous and connected cars. Thus, the number of threats and the magnitude of risks will increase as well. This calls for the study of automotive systems that implement specific functions at the vehicle level using simulations [2], models [3] or digital twins [4]. The digital twin concept defines a virtual counterpart realized as a prototype of a real product or process. The idea originates from the Florida Institute of Technology in the early 2000s [5]. The interpretation from the International Council on Systems Engineering (INCOSE) organization defines a digital twin as a high-fidelity model of the system [6]. There can be various levels of digital twins, starting from pre-digital twins to adaptive or intelligent digital twins that exchange more or less data with their physical twins or make use of reinforced learning [7]. Initially proposed and used in manufacturing processes [8], recent studies also evaluated the development of digital twins for physical automotive systems. One such study verified outputs of MATLAB models, i.e., the digital twin of a vehicle function, compared to real data extracted from the Controller Area Network (CAN) bus of the Toyota Prius test vehicle in the context of vehicle dynamics [9]. This work integrated several types of vehicle models in MATLAB in order to create the digital twin, i.e., single-track model, two track model, multi-body vehicle model and tire models. In the light of such works, given the trend of using digital twins for automotive systems or functions, our goal here is to explore the digital twin of a real vehicle CAN bus. For defining our digital twin, we will use several embedded boards that implement specific models, connected to a Controller Area Network (CAN) bus from a real vehicle as shown in Figure 1. On each embedded board, we integrate a specific MATLAB model that receives input signals from the CAN bus and provides outputs that are computed based on those inputs (according to the system model). We analyze the wiring diagram handbook of the real car to determine the ECUs that communicate on the CAN bus and the vehicle functions realized by these ECUs. We give more details regarding the real CAN network in the forthcoming sections. One specific use case of the digital twin is in analyzing the effects of cyberattacks as we argue at the end of the experimental section. From a security standpoint, there are many CAN vulnerabilities shown by research works [10,11] as well as more recent attacks on real vehicles [12]. Thus, designing security countermeasures is a prime demand, and a digital twin can be immediately used to test new proposals. The contributions of our work, i.e., CarTwin--the digital twin of a real car, can be summarized as follows:  
1. We use fine-grained details of a real vehicle CAN network, such as wire lengths, stub lengths, the number of nodes communicating on the bus and the real-world information that is sent on the network;
2. We use MATLAB models to implement ECU functionalities related to braking (Anti-lock Brake System), seat-belt status and seat position checks for airbag deployment (Restraints Control Module), remote keyless actions (Remote Function Actuator), entertainment and multimedia (Accessory Protocol Interface Module), wheel steering (Power Steering Control Module), engine and transmission controls (Powertrain Control Module) and the information presented to the driver (Instrument Panel Cluster);
3.