## 2 Design and Modelling of a 3D Printer with five Degrees of Freedom
### Dynamic Analysis
#### 2.3.2 Dynamic Modeling of Stepper Motors Used in a 3D Printer  
To achieve a certain path with the intended five-axis 3D printer, the actuators in the system need to be accurately controlled to move at a specific velocity and angle. A total of five hybrid stepper motors were used in the system's construction. There is no precise theoretical electromechanical equivalent model available to mathematically analyze these motors. To unveil the dynamic model of these motors, the magnetic equivalent circuit model was used instead of the electromechanical equivalent circuit [42; 43; 44]. The electrical equations for the phases of a stepper motor can be expressed using the magnetic equivalent circuit model, as shown in Equations (37) and (38).  
\[U_{a}=Ri_{a}+L\frac{d}{dt}i_{a}-K_{m}\omega sin(p\theta), \tag{37}\]  
\[U_{b}=Ri_{b}+L\frac{d}{dt}i_{b}-K_{m}\omega cos(p\theta), \tag{38}\]  
The variables \(i_{a},U_{a},i_{b}\) and \(U_{b}\) in the above equation represent the control currents supplied to the A and B phases, as well as the corresponding phase voltages. However, the variables R and L represent the resistance and inductance values of the motor phases, while \(K_{m}\) represents the motor torque constant, \(\omega\) and and \(\theta\) represent the angular speed and position of the motor, and p represents the number of rotor teeth of the stepper motor. The mechanical structure of the system establishes a direct relationship between the angular position (denoted as \(\theta\)) of the motor and its linear position (denoted as \(d_{i}^{T}\) in Equation (35)). The motor's output torque, which is influenced by the control current, can be mathematically represented as follows:  
\[K_{m}\{-i_{a}sin(p\theta)+i_{b}cos(p\theta)\}-T_{L}=J\frac{d\omega}{dt},+K_{v}\omega \tag{39}\]  
In the above equation, \(J\), \(K_{v}\), and \(T_{L}\) indicate the motor shaft's inertia, the coefficient of viscous damping, and the torque exerted on the motor shaft by the load, respectively. By using the Park transformation on the voltage and torque equations stated in Equations (36)-(39), we obtained the voltage and torque expressions specified on the \(d-q\) axis, as shown in Equation (40).  
\[\begin{split} U_{d}=R_{id}+L\frac{d}{dt}i_{d}-Lp\omega i_{q},\\ U_{q}=Ri_{d}+L\frac{d}{dt}i_{q}-Lp\omega i_{d}+K_{m}\omega,\\ T_{motor}=K_{m}i_{q}-J\frac{d\omega}{dt}-K_{v}\omega,\end{split} \tag{40}\]  
By equating Equation (40), which represents the motor output torque expression, with the inverse dynamic equation of the mechanical system, Equation (41) is obtained. This provides the dynamic equation for the whole system.  
\[M(q)\ddot{q}+C\big{(}q,\dot{q}\big{)}\dot{q}+G(q)=K_{m}i_{q}-J\ddot{q}-K_{v} \dot{q}, \tag{41}\]  
Equation (41) can be restated as Equation (42) via the execution of mathematical procedures.  
\[(M(q)-J)\ddot{q}+\big{(}C\big{(}q,\dot{q}\big{)}+K_{v}\big{)}\dot{q}+G(q)=K_{m }i_{q}, \tag{42}\]  
Equation (42) can be simplified to Equation (43);  
\[M(q)\ddot{q}+N\big{(}q,\dot{q}\big{)}=K_{m}i_{q}=\tau(t), \tag{43}\]  
Here, \(N\big{(}q,\dot{q}\big{)}=\big{(}C\big{(}q,\dot{q}\big{)}+K_{v}\big{)}\dot{q}+G (q)\).