Modelling the motion of an electric vehicle
This example will demonstrate how to simulate the motion of an electric car.
The motion of the electric vehicle and its inertia are described by the Electric Vehicle block. The left port of this block receives the resultant force from two pairs of wheels connected to gearboxes and electric motors that convert and generate torque. The right port receives the air resistance force described by the subsystem of the same name.
The main parameters of the model are:
Block name | Basic parameter |
---|---|
Vehicle | Weight 1000kg |
Battery | Battery |
Electric motors | Constant torque 4 Nm/A |
Wheels | Radius 0.32 m |
Gearboxes | Gear ratio 0.8 |
Air resistance coefficient | 0.5 |
Schematic of the model:

Define the function to load and run the model:
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
Running the simulation
try
start_model_engee() # запуск симуляции с помощью специальной функции, реализованной выше
catch err
end;
Write from simout to variables the velocity, torque and force signals:
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[:];
using Plots
Visualisation of simulation results
plot(t, forces_left, label="Усилие от трансмиссии, Н", linewidth=2)
plot!(t, forces_right, label="Сопротивление воздуха, Н", linewidth=2)
plot!(t, (forces_left+forces_right), label="Сумма сил, Н", linewidth=2)
By analysing the "Sum of forces" curve, it can be seen that it becomes zero as the forces acting on the electric car are balanced. The motion becomes uniform, with constant speed.
plot(t, T, label="Крутящий момент электродвигателя, Н*м", linewidth=2)
plot!(t, (w * 9.55), label="Частота вращения электродвигателя, об/мин", linewidth=2)
plot!(t, (T .* w ./1000), label="Мощность электродвигателя, кВт", linewidth=2)
As the car accelerates, the torque decreases and the rotational speed of the electric motor increases. The mechanical power produced by this electric motor increases as the air resistance force increases, depending on the speed.
plot(t, speed, label="Скорость, км/ч", linewidth=2)
Define a function to calculate the acceleration time to 100 km/h and apply it to the speed data of an electric car:
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), " км/ч")
Conclusion:
This example demonstrates a simulation of the motion of an electric car. It accelerates to a certain steady-state speed and is prevented from accelerating further by air resistance. The acceleration time to 100 km/h and the maximum speed of the electric car were calculated.