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


相关文章
|
2月前
|
算法 计算机视觉
永磁同步电机的矢量控制PMSM仿真+simulink仿真建模(matlab仿真与图像处理)
永磁同步电机的矢量控制PMSM仿真+simulink仿真建模(matlab仿真与图像处理)
104 1
|
18天前
|
存储 人工智能 机器人
【Matlab】Matlab电话拨号音合成与识别(代码+论文)【独一无二】
【Matlab】Matlab电话拨号音合成与识别(代码+论文)【独一无二】
|
2月前
|
机器学习/深度学习 算法 计算机视觉
霍夫变换车道线识别-车牌字符识别代码(matlab仿真与图像处理系列第5期)
霍夫变换车道线识别-车牌字符识别代码(matlab仿真与图像处理系列第5期)
30 2
|
2月前
|
机器学习/深度学习 算法
基于自适应支持向量机的matlab建模与仿真,不使用matlab的SVM工具箱函数
基于自适应支持向量机的matlab建模与仿真,不使用matlab的SVM工具箱函数
|
2月前
|
算法 机器人 vr&ar
基于双目RGB图像和图像深度信息的三维室内场景建模matlab仿真
基于双目RGB图像和图像深度信息的三维室内场景建模matlab仿真
|
3月前
|
Perl
【MFAC】基于全格式动态线性化的无模型自适应控制(Matlab代码)
【MFAC】基于全格式动态线性化的无模型自适应控制(Matlab代码)
|
3月前
【数值分析】迭代法求方程的根(附matlab代码)
【数值分析】迭代法求方程的根(附matlab代码)
|
3月前
【数值分析】Jacobi、Seidel和Sor迭代法求解线性方程组(附matlab代码)
【数值分析】Jacobi、Seidel和Sor迭代法求解线性方程组(附matlab代码)
|
3月前
【数值分析】二分法求方程的根(附matlab代码)
【数值分析】二分法求方程的根(附matlab代码)
|
2月前
|
算法
MATLAB | 插值算法 | 一维interpl插值法 | 附数据和出图代码 | 直接上手
MATLAB | 插值算法 | 一维interpl插值法 | 附数据和出图代码 | 直接上手
40 0

热门文章

最新文章