【交通建模】基于模型的自主交通仿真框架附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法  神经网络预测 雷达通信  无线传感器

信号处理 图像处理 路径规划 元胞自动机 无人机  电力系统

⛄ 内容介绍

MOBATSim(基于模型的自主交通仿真框架)是一个基于MATLAB®和Simulink®的框架,允许用户开发自动驾驶算法并评估其安全性和性能。通过运行交通模拟,可以在二维和三维可视化选项的支持下,在车辆级别和交通级别上测量所实现的组件或算法的安全性。安全分析是影响工程中许多不同领域的重要课题。作为对安全最关键的领域之一,汽车行业需要工具和技术来评估单个车辆以及整个交通的安全性。提出了一种新的仿真框架 MOBATSim,其中基于仿真的故障注入用于评估自动驾驶系统在组件、车辆和交通级别上的安全性。仿真框架是在 MATLAB Simulink 中设计的,为各种驾驶场景建模提供了构建块,包括城市环境地图和车辆的路标。它基于用故障注入模型扩展的自主车辆模型。在模拟运行期间可以注入几种类型的故障,并且可以检查输出以验证用户指定的安全标准。MOBATSim 支持完整的故障-错误-故障链分析,能够揭示部件故障与车辆和交通水平故障之间的关系。说明性案例研究显示了对用户定义的驾驶场景中由特定低级传感器故障引起的安全标准违规的分析。

⛄ 部分代码

%% Run this script for the Cuboid World or Unreal Engine 4 Simulation of the 2D MOBATSim simulation

% This script:

% 1- should be run after finishing the main simulation on the 2D plot because the logged data is required for this script.

% 2- has to be run in order to update the trajectories after each driving scenario in the main simulation.

% 3- opens the drivingScenarioDesigner APP to simulate the vehicle trajectories in the Cuboid World or using Unreal Engine 4

%% Load all the road information 

MOBATKent_Scenario = scenario_map_v1(); % Output of a function automatically generated from the drivingScenarioDesigner after designing the roads

%% Load all vehicles and generate Trajectories

step_length = 20; % Sampling of WAYPOINTS and SPEEDS -> if this script takes too long to run, increase this number!

% To define the Ego Vehicle, just put the code of the corresponding vehicle to the first place.

egoVehicle = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V2_translation.Data(1,3) -V2_translation.Data(1,1) 0]);

waypoints = [-V2_translation.Data((1:step_length:end),3) -V2_translation.Data((1:step_length:end),1) V2_translation.Data((1:step_length:end),2)];

speed = V2_speed.Data(1:step_length:end);

egoVehicle = defineTrajectory(egoVehicle, waypoints, speed);

% Add the non-ego actors

car1 = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V1_translation.Data(1,3) -V1_translation.Data(1,1) 0]);

waypoints = [-V1_translation.Data((1:step_length:end),3) -V1_translation.Data((1:step_length:end),1) V1_translation.Data((1:step_length:end),2)];

speed = V1_speed.Data(1:step_length:end);

car1 = defineTrajectory(car1, waypoints, speed);

car3 = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V3_translation.Data(1,3) -V3_translation.Data(1,1) 0]);

waypoints = [-V3_translation.Data((1:step_length:end),3) -V3_translation.Data((1:step_length:end),1) V3_translation.Data((1:step_length:end),2)];

speed = V3_speed.Data(1:step_length:end);

car3 = defineTrajectory(car3, waypoints, speed);

car4 = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V4_translation.Data(1,3) -V4_translation.Data(1,1) 0]);

waypoints = [-V4_translation.Data((1:step_length:end),3) -V4_translation.Data((1:step_length:end),1) V4_translation.Data((1:step_length:end),2)];

speed = V4_speed.Data(1:step_length:end);

car4 = defineTrajectory(car4, waypoints, speed);

car5 = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V5_translation.Data(1,3) -V5_translation.Data(1,1) 0]);

waypoints = [-V5_translation.Data((1:step_length:end),3) -V5_translation.Data((1:step_length:end),1) V5_translation.Data((1:step_length:end),2)];

speed = V5_speed.Data(1:step_length:end);

car5 = defineTrajectory(car5, waypoints, speed);

car6 = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V6_translation.Data(1,3) -V6_translation.Data(1,1) 0]);

waypoints = [-V6_translation.Data((1:step_length:end),3) -V6_translation.Data((1:step_length:end),1) V6_translation.Data((1:step_length:end),2)];

speed = V6_speed.Data(1:step_length:end);

car6 = defineTrajectory(car6, waypoints, speed);

car7 = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V7_translation.Data(1,3) -V7_translation.Data(1,1) 0]);

waypoints = [-V7_translation.Data((1:step_length:end),3) -V7_translation.Data((1:step_length:end),1) V7_translation.Data((1:step_length:end),2)];

speed = V7_speed.Data(1:step_length:end);

car7 = defineTrajectory(car7, waypoints, speed);

car8 = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V8_translation.Data(1,3) -V8_translation.Data(1,1) 0]);

waypoints = [-V8_translation.Data((1:step_length:end),3) -V8_translation.Data((1:step_length:end),1) V8_translation.Data((1:step_length:end),2)];

speed = V8_speed.Data(1:step_length:end);

car8 = defineTrajectory(car8, waypoints, speed);

car9 = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V9_translation.Data(1,3) -V9_translation.Data(1,1) 0]);

waypoints = [-V9_translation.Data((1:step_length:end),3) -V9_translation.Data((1:step_length:end),1) V9_translation.Data((1:step_length:end),2)];

speed = V9_speed.Data(1:step_length:end);

car9 = defineTrajectory(car9, waypoints, speed);

car10 = vehicle(MOBATKent_Scenario, ...

    'ClassID', 1, ...

    'Position', [-V10_translation.Data(1,3) -V10_translation.Data(1,1) 0]);

waypoints = [-V10_translation.Data((1:step_length:end),3) -V10_translation.Data((1:step_length:end),1) V10_translation.Data((1:step_length:end),2)];

speed = V10_speed.Data(1:step_length:end);

car10 = defineTrajectory(car10, waypoints, speed);

%% Open the scenario in drivingScenarioDesigner (This way it can be also edited or simulated 3D in Unreal Engine)

drivingScenarioDesigner(MOBATKent_Scenario)

%% This function uses try-catch-try structure as a workaround the geometric errors caused by the "trajectory" function

function car = defineTrajectory(car, waypoints, speed)

try

    trajectory(car, waypoints, speed)

catch

    [~,I,~] = unique(waypoints, 'rows','stable');

    waypoints = waypoints(I,:,:);

    speed = speed(I,:,:);

    try

        trajectory(car, waypoints, speed)

    catch

        idx =(speed~=0);

        speed = (speed(idx));

        waypoints = waypoints(idx,:,:);

        try

            trajectory(car, waypoints, speed);

        catch

            % Try to generate waypoints by skipping the first 10 waypoints

            waypoints = waypoints(10:end,:,:);

            speed = speed(10:end);

            try

                trajectory(car, waypoints, speed);

            catch

                % The last try: Sample each waypoint in 5

                I = 1:5:length(waypoints);

                waypoints = waypoints(I,:,:);

                speed = speed(I,:,:);

                

                % If this also doesn't work, then it simply fails, try changing the scenario.

                trajectory(car, waypoints, speed);

            end

        end

    end

end

end

⛄ 运行结果

⛄ 参考文献

​[1] Saraoglu M ,  Morozov A ,  Janschek K . MOBATSim: MOdel-Based Autonomous Traffic Simulation Framework for Fault-Error-Failure Chain Analysis - ScienceDirect[J]. IFAC-PapersOnLine, 2019, 52( 8):239-244.

⛄ Matlab代码关注

❤️部分理论引用网络文献,若有侵权联系博主删除

❤️ 关注我领取海量matlab电子书和数学建模资料

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值