This paper presents a digital twin of a mechatronic drive based on a brushless DC (BLDC) motor model based on a nonlinear discrete optimal control model. Some parameters of a BLDC motor, such as resistance and inductance of windings, magnetic flux, viscous friction coefficient in bearings, angular velocity and electromagnetic moment, can change due to both degradation of structural elements and external forces. Simulation by a complete enumeration of the values of the parameters of the mechatronic device with a certain step will make it possible to adapt the program of the control device to changing operating conditions according to the criterion of minimizing the control energy by changing the parameters of the state matrices and control of the digital twin. As a result, the accuracy of the movement of the mechatronic device along the given trajectory will increase due to the greater correspondence of the control parameters to the real object.