Engee documentation
Notebook

Simulation of electric vehicle movement

This example will demonstrate the simulation of the movement of an electric vehicle.

The movement of an electric vehicle and its inertia are described by the block Electric vehicle. The left port of this unit receives the resulting force from two pairs of wheels connected to gearboxes and electric motors that convert and generate torque. The air resistance force described by the subsystem of the same name is applied to the right port.

The main parameters of the model:

Block name Main parameter
Car Weight 1000 kg
Battery Voltage 680 V
Electric motors Torque constant 4 Nm/A
Wheels Radius 0.32 m
Gearboxes Gear ratio 0.8
Air resistance coefficient 0.5

Model diagram:

electro_car--1728030945984_2.png

Defining the function to load and run the model:

In [ ]:
function start_model_engee()
    try
        engee.close("electro_car", force=true) # закрытие модели 
        catch err # в случае, если нет модели, которую нужно закрыть и engee.close() не выполняется, то будет выполнена её загрузка после catch
            m = engee.load("$(@__DIR__)/electro_car.engee") # загрузка модели
        end;

    try
        engee.run(m) # запуск модели
        catch err # в случае, если модель не загружена и engee.run() не выполняется, то будут выполнены две нижние строки после catch
            m = engee.load("$(@__DIR__)/electro_car.engee") # загрузка модели
            engee.run(m) # запуск модели
        end
end
Out[0]:
start_model_engee (generic function with 1 method)

Running the simulation

In [ ]:
try
    start_model_engee() # запуск симуляции с помощью специальной функции, реализованной выше
    catch err
    end;

Recording speed, torque, and force signals from simout to variables:

In [ ]:
t = simout["electro_car/Скорость в км/ч"].time[:] # время
T = simout["electro_car/Крутящий момент электродвигателя"].value[:] # крутящий момент электродвигателя
speed = simout["electro_car/Скорость в км/ч"].value[:] # скорость автомобиля
forces_left = simout["electro_car/Сила со стороны трансмиссии"].value[:] # силы, 
forces_right = simout["electro_car/Сила сопротивления воздуха"].value[:]
w = simout["electro_car/Частота вращения электродвигателя"].value[:];
In [ ]:
using Plots

Visualization of simulation results

In [ ]:
plot(t, forces_left, label="Усилие от трансмиссии, Н", linewidth=2)
plot!(t, forces_right, label="Сопротивление воздуха, Н", linewidth=2)
plot!(t, (forces_left+forces_right), label="Сумма сил, Н", linewidth=2)
Out[0]:

After analyzing the "Sum of Forces" curve, you can see that it becomes zero as the forces acting on the electric vehicle are balanced. The movement becomes uniform, with a constant speed.

In [ ]:
plot(t, T, label="Крутящий момент электродвигателя, Н*м", linewidth=2)
plot!(t, (w * 9.55), label="Частота вращения электродвигателя, об/мин", linewidth=2)
plot!(t, (T .* w ./1000), label="Мощность электродвигателя, кВт", linewidth=2)
Out[0]:

As the car accelerates, the torque decreases and the rotation speed of the electric motor increases. The mechanical power produced by this electric motor increases as the force of air resistance increases, depending on the speed.

In [ ]:
plot(t, speed, label="Скорость, км/ч", linewidth=2)
Out[0]:

Definition of a function for calculating acceleration time to 100 km/h and its application to electric vehicle speed data:

In [ ]:
function acceleration_time(speeds, t)
    # Находим индекс первого элемента, превышающего 100 км/ч
    index = findfirst(x -> x > 100, speeds)

    # Если индекс найден, возвращаем соответствующее время
    if index != nothing
        return println("Время разгона до 100 км/ч: ", t[index], " с")
    else
        return println("Автомобиль не разогрался до 100 км/ч, максимальная скорость: ", maximum(speed), " км/ч")
    end
end

acceleration_time(speed, t)
println("Максимальная скорость: ", maximum(speed), " км/ч")
Время разгона до 100 км/ч: 8.83 с
Максимальная скорость: 154.8599905585448 км/ч

Conclusion:

This example demonstrates the simulation of the movement of an electric vehicle. He accelerates to a certain steady speed, but the force of air resistance does not allow him to accelerate further. The acceleration time to 100 km/h and the maximum speed of the electric vehicle were calculated.