Engee documentation
Notebook

Simulation of car braking

This example will demonstrate the simulation of car braking.

The movement of the car and its inertia are described by the Car block. The resulting force from two pairs of wheels connected to the braking mechanism 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.

Model diagram:

braking_distance-05.12.24 09_28_24.png

Defining the function to load and run the model:

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

    try
        engee.run(m) # запуск модели
        catch err # в случае, если модель не загружена и engee.run() не выполняется, то будут выполнены две нижние строки после catch
            m = engee.load("$(@__DIR__)/braking_distance.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, displacement, and force signals from simout to variables:

In [ ]:
t = simout["braking_distance/Скорость в км/ч"].time[:]
distance = simout["braking_distance/Перемещение в км"].value[:]
speed = simout["braking_distance/Скорость в км/ч"].value[:]
forces_left = simout["braking_distance/Сила со стороны трансмиссии"].value[:]
forces_right = simout["braking_distance/Сила сопротивления воздуха"].value[:];

Visualization of simulation results

In [ ]:
using Plots
In [ ]:
plot(t, forces_left, label="Усилие от трансмиссии, Н", linewidth=2)
plot!(t, forces_right, label="Сопротивление воздуха, Н", linewidth=2)
plot!(t, (forces_left+forces_right), label="Сумма сил, Н", linewidth=2, title="Силы, действующие на автомобиль")
Out[0]:
In [ ]:
plot(t, speed, label="Скорость, км/ч", linewidth=2)
plot!(t, distance*1000, label="Перемещение, м", linewidth=2)
Out[0]:

Definition of a function for calculating the braking distance of a car and its application to movement data:

In [ ]:
function braking_distance(distance, t)
    index = findfirst(x -> x < 0.00001, distance)
    if index != nothing
        return println("Тормозной путь: ", round(maximum(distance)*1000, digits=2), " м")
    end
end

braking_distance(distance, t)
Тормозной путь: 34.62 м

Conclusions:

In this example, a simulation of car braking was demonstrated. Using the function braking_distance The braking distance was calculated for a car with an initial speed of 100 km/h.