Main Content

Model a DC Motor in Stateflow

This example shows the model of a permanent magnet DC motor. The mode logic and dynamics of the DC motor are both modeled using Stateflow®.

The DC motor state chart consists of two superstates: powerOn and powerOff. If the motor is powered on, it can be in one of two substates: up or down, signifying the direction of movement.

Note: This is a simplistic model of a DC motor. You can build more sophisticated DC motor models using Simscape™, which extends Simulink® with tools for modeling and simulating multidomain physical systems, such as those with mechanical, hydraulic, and electrical components.

The dynamics of the motor are defined directly in the state chart using graphical functions and change depending on the state of the motor. For example, when the motor is in the powerOff state, the voltage applied is equal to zero. When the motor is in the powerOn state, the voltage applied is either positive or negative, depending on the direction of the motor.

To review, the differential equations defining a permanent magnet DC motor are as follows:

$$ \frac{di}{dt} = \frac{v_{app}(t) - R \cdot i(t) - K_b \cdot \omega(t)}{L} $$

$$ \frac{d\omega}{dt} = \frac{K_m \cdot i(t) - K_f \cdot \omega(t)}{J} $$

where

$$i = \mbox{current}$$

$$R = \mbox{resistance}$$

$$L = \mbox{inductance}$$

$$K_b = \mbox{EMF constant}$$

$$\omega = \mbox{rotational speed of motor}$$

$$v_{app} = \mbox{applied voltage}$$

$$K_f = \mbox{damping constant}$$

$$K_m = \mbox{torque constant}$$

Related Topics