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

简介: 【交通建模】基于模型的自主交通仿真框架附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电子书和数学建模资料


相关文章
|
1月前
|
算法
基于龙格库塔算法的锅炉单相受热管建模与matlab数值仿真
本设计基于龙格库塔算法对锅炉单相受热管进行建模与MATLAB数值仿真,简化为喷水减温器和末级过热器组合,考虑均匀传热及静态烟气处理。使用MATLAB2022A版本运行,展示自编与内置四阶龙格库塔法的精度对比及误差分析。模型涉及热传递和流体动力学原理,适用于优化锅炉效率。
空心电抗器的matlab建模与性能仿真分析
空心电抗器是一种无铁芯的电感元件,通过多层并联导线绕制而成。其主要作用是限制电流、滤波、吸收谐波和提高功率因数。电抗器的损耗包括涡流损耗、电阻损耗和环流损耗。涡流损耗由交变磁场引起,电阻损耗与电抗器半径有关,环流损耗与各层电流相关。系统仿真使用MATLAB2022a进行。
|
2月前
|
算法
基于GA遗传算法的PID控制器参数优化matlab建模与仿真
本项目基于遗传算法(GA)优化PID控制器参数,通过空间状态方程构建控制对象,自定义GA的选择、交叉、变异过程,以提高PID控制性能。与使用通用GA工具箱相比,此方法更灵活、针对性强。MATLAB2022A环境下测试,展示了GA优化前后PID控制效果的显著差异。核心代码实现了遗传算法的迭代优化过程,最终通过适应度函数评估并选择了最优PID参数,显著提升了系统响应速度和稳定性。
271 15
|
3月前
|
算法
基于HASM模型的高精度建模matlab仿真
本课题使用HASM进行高精度建模,介绍HASM模型及其简化实现方法。HASM模型基于层次化与自适应统计思想,通过多层结构捕捉不同尺度特征,自适应调整参数,适用于大规模、高维度数据的分析与预测。MATLAB2022A版本运行测试,展示运行结果。
|
6月前
|
安全
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
本文介绍了2023年高教社杯数学建模竞赛D题的圈养湖羊空间利用率问题,包括问题分析、数学模型建立和MATLAB代码实现,旨在优化养殖场的生产计划和空间利用效率。
272 6
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
|
6月前
|
数据采集 存储 移动开发
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
本文介绍了2023年五一杯数学建模竞赛B题的解题方法,详细阐述了如何通过数学建模和MATLAB编程来分析快递需求、预测运输数量、优化运输成本,并估计固定和非固定需求,提供了完整的建模方案和代码实现。
138 0
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
|
6月前
|
存储 算法 搜索推荐
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
本文提供了2022年华为杯数学建模竞赛B题的详细方案和MATLAB代码实现,包括方形件组批优化问题和排样优化问题,以及相关数学模型的建立和求解方法。
162 3
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
|
9月前
|
数据安全/隐私保护
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混合整数规划的微网储能电池容量规划(matlab代码)
基于混合整数规划的微网储能电池容量规划(matlab代码)
|
9月前
|
算法 调度
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)

热门文章

最新文章