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 resulting force from two pairs of wheels connected to gearboxes and electric motors that convert and generate torque comes to the left port of this unit. The air resistance force described by the subsystem of the same name is applied to the right port.

The main parameters of the model:

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

Model diagram:

electro_car--1728030945984_2.png

Defining a function to load and run the model:

In [ ]:
function start_model_engee()
    try
        engee.close("electro_car", force=true) # closing the model
        catch err # if there is no model to close and engee.close() is not executed, it will be loaded after catch.
            m = engee.load("$(@__DIR__)/electro_car.engee") # loading the model
        end;

    try
        engee.run(m) # launching the model
        catch err # if the model is not loaded and engee.run() is not executed, the bottom two lines after catch will be executed.
            m = engee.load("$(@__DIR__)/electro_car.engee") # loading the model
            engee.run(m) # launching the model
        end
end
Out[0]:
start_model_engee (generic function with 1 method)

Running the simulation

In [ ]:
try
    start_model_engee() # running the simulation using the special function implemented above
    catch err
    end;

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

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

Visualization of simulation results

In [ ]:
plot(t, forces_left, label="Force from the transmission, N", linewidth=2)
plot!(t, forces_right, label="Air resistance, N", linewidth=2)
plot!(t, (forces_left+forces_right), label="The sum of forces, N", 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="Electric motor torque, NM", linewidth=2)
plot!(t, (w * 9.55), label="Частота вращения электродвигателя, об/мин", linewidth=2)
plot!(t, (T .* w ./1000), label="Electric motor power, kW", 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)
    # We find the index of the first element exceeding 100 km/h
    index = findfirst(x -> x > 100, speeds)

    # If the index is found, we return the appropriate time.
    if index != nothing
        return println("Время разгона до 100 км/ч: ", t[index], " with")
    else
        return println("Автомобиль не разогрался до 100 км/ч, максимальная скорость: ", maximum(speed), " км/ч")
    end
end

acceleration_time(speed, t)
println("Maximum speed: ", 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.