## 3 Digital Twin and Physical Twin Integration
### Virtual Prosthesis Dynamic Model and Trackers Interface
The second subassembly is composed of 20 rigid bodies that schematise the various phalanges of the fingers (four bodies for each of the fingers). In this case, we connected the various segments using spherical joints. The second subassembly is a group of rigid bodies that, despite having an anatomical conformation, are not present in reality due to the presence of the amputated limb. Therefore, in this case, it is not included in the inverse dynamics problem. It is only used to simulate the movement of the prosthesis fingers and their interactions with objects in grasping and manipulation exercises. The movement of these rigid bodies is not controlled by trackers or other physical devices but is imposed by the interpretation of the myoelectric signals using a neural network classifier. From a practical point of view, for each of the classifiable gestures, a series of time laws of the relative angles between the adjacent anatomical segments of the fingers is provided. They are imposed by means of driving constraints when the classifier recognises a pose with a sufficient degree of confidence. The speed at which these movements take place is calibrated according to the performance of the actual prosthesis in order to increase the sense of realism and proper delay. If the classifier does not return any posture update, the second subassembly actually behaves as a single rigid body because all the relative driving constraints enforce a stationary motion (zero relative velocities). The two subassemblies are then connected to each other by a fixed constraint between the distal end of the forearm and the proximal end of the palm. Overall, the whole dynamic virtual arm system has  
* 24 rigid bodies (4 in the first subassembly and 20 in the second subassembly);
* 17 kinematic constraints with 54 scalar equations (1 spherical joint between the arm and the forearm, 1 fixed constraint between the forearm and the palm, and 15 spherical joints between adjacent phalanges of the hand);
* 57 motion constraints (6 scalar equations for each of the trackers and 3 scalar equations to control the relative rotation for each of the spherical constraints between adjacent phalanges);
* 2 bushing elements (one for each of the trackers). The dynamic model is built and solved according to the rigid multibody dynamics method, not using the global formulation [29] but adapting the sequential impulse formulation [30; 31]. Studies in the literature have shown that this formulation is particularly suitable for solving dynamics problems in real-time and with interactivity requirements such as virtual and augmented reality environments [32]. The sequential impulse formulation is based on a two-step algorithm:  
* At the beginning, the equations of motion are solved by neglecting the kinematic constraints (free-body equations, considering only the external and internal forces applied to the bodies);
* Subsequently, a series of impulses is applied to all the bodies, one at a time, sequentially and iteratively, to update their motion kinematics, fulfilling the constraint equations within a specific tolerance. Considering a dynamic system where \([M]\) is the mass matrix, \(\{q\}\) is the vector of the generalised coordinates, \(\{\psi\}\) is the vector of the constraint equations, and \(\{F_{e}\}\) is the vector of the external forces and torques, in the first step of the formulation, the equations are solved neglecting the constraints:  
\[[M]\{\dot{q}\}_{approx}=\{F_{e}\} \tag{2}\]  
where \(\{\dot{q}\}_{approx}\) is the vector of the approximated accelerations. Approximated velocities and positions can be calculated as linear approximations from accelerations:  
\[ \begin{array}{c}\{\dot{q}\}_{approx}=h\cdot\{\ddot{q}\}_{approx}\\ \{q\}_{approx}=h\cdot\{\dot{q}\}_{approx}\end{array}  \tag{3}\]  
where \(h\) is the integration time step, assumed as fixed.