Engee documentation
Notebook

Model of operation of a DC motor drive

In this article we will consider a model of a drive based on a DC motor. The peculiarity of this example is the use of basic blocks and physical modelling blocks.


Model composition

The ee_dc_motor_ctl model consists of a number of subsystems.

  • The Controller speed control subsystem is designed using basic blocks. This makes it easy to set the control algorithm;
  • The control object is a DC motor DC Motor. It is represented in the form of physical modelling blocks of the Electricity library;
  • The Driver subsystem is used to set the motor speed;
  • To determine the speed of the motor shaft you need a sensor, which is implemented in the Sensor subsystem.

Speed controller subsystem

The Controller subsystem implements a PI controller with a low pass filter. The schematic of the controller is shown below.

ee_dc_motor_ctl_1_1719570364109.png

The principle of operation of the controller is simple. The desired speed value and the current motor shaft speed are input to the controller. However, the motor is controlled via voltage, so all speeds must be converted. In the diagram, this is realised as a multiplication by a factor of 0.00125. In the next step, the mismatch is calculated in the Add block. After that, the corrected value is formed, which will be fed to the driver input. Since the driver is implemented as physical blocks, the Controlled Voltage Source is used to generate the output voltage.

Motor Driver Subsystem

The Driver subsystem provides a model of the driver circuitry in the form of physical blocks. The Controlled PWM Voltage block generates a PWM signal based on the voltages on its ref+ and ref- ports. The H-Bridge block is an H-bridge circuit that allows the polarity of the applied voltage to be reversed.

ee_dc_motor_ctl2_27_06_24.png

The voltage generated at the driver output goes to the motor input. For more details on the unit parameters, please refer to the documentation in DC Motor.

Sensor subsystem

The Sensor subsystem contains the basic blocks and the physical block Ideal Rotational Motion Sensor. This block allows the motor shaft speed to be detected.

ee_dc_motor_ctl_1_1719569515454.png

After reading the speed, it is necessary to convert its value into volts for further control in the Controller block.

Obtaining system data

Let's run the model and see how the controller works at a given speed in this model.

In [ ]:
# Подключение вспомогательной функции запуска модели.
function run_model( name_model, path_to_folder )
    
    Path = path_to_folder * "/" * name_model * ".engee"
    
    if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
        model = engee.open( name_model ) # Открыть модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
    else
        model = engee.load( Path, force=true ) # Загрузить модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
        engee.close( name_model, force=true ); # Закрыть модель
    end

    return model_output
end
Out[0]:
run_model (generic function with 1 method)
In [ ]:
run_model("ee_dc_motor_ctl",@__DIR__) # Запуск модели.
Building...
Progress 8%
Progress 33%
Progress 58%
Progress 83%
Progress 100%
Progress 100%
Out[0]:
Dict{String, DataFrames.DataFrame} with 2 entries:
  "Wref"      => 7×2 DataFrame…
  "SensedRPM" => 60001×2 DataFrame
In [ ]:
# Считывание из simout залогированных сигналов
Wref = simout["ee_dc_motor_ctl/Wref"];
Wref = collect(Wref);

SensedRPM = simout["ee_dc_motor_ctl/Sensor/SensedRPM"];
SensedRPM = collect(SensedRPM);

Plot the set speed and the speed received from the sensor.

In [ ]:
using Plots

plot(Wref.time, Wref.value, label = "Wref")
plot!(SensedRPM.time, SensedRPM.value, label = "SensedRPM")
Out[0]:

Conclusion

From the graphs it can be concluded that the motor shaft speed has reached the desired speed in 3 seconds. The time to reach the desired result can be reduced by changing the components of the PI controller.