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


目录
打赏
0
0
0
0
838
分享
相关文章
基于PSO粒子群优化的CNN-LSTM-SAM网络时间序列回归预测算法matlab仿真
本项目展示了基于PSO优化的CNN-LSTM-SAM网络时间序列预测算法。使用Matlab2022a开发,完整代码含中文注释及操作视频。算法结合卷积层提取局部特征、LSTM处理长期依赖、自注意力机制捕捉全局特征,通过粒子群优化提升预测精度。适用于金融市场、气象预报等领域,提供高效准确的预测结果。
基于Big-Bang-Big-Crunch(BBBC)算法的目标函数最小值计算matlab仿真
该程序基于Big-Bang-Big-Crunch (BBBC)算法,在MATLAB2022A中实现目标函数最小值的计算与仿真。通过模拟宇宙大爆炸和大收缩过程,算法在解空间中搜索最优解。程序初始化随机解集,经过扩张和收缩阶段逐步逼近全局最优解,并记录每次迭代的最佳适应度。最终输出最佳解及其对应的目标函数最小值,并绘制收敛曲线展示优化过程。 核心代码实现了主循环、粒子位置更新、适应度评估及最优解更新等功能。程序运行后无水印,提供清晰的结果展示。
基于PID控制器的双容控制系统matlab仿真
本课题基于MATLAB2022a实现双容水箱PID控制系统的仿真,通过PID控制器调整泵流量以维持下游水箱液位稳定。系统输出包括水位和流量两个指标,仿真结果无水印。核心程序绘制了水位和流量随时间变化的图形,并设置了硬约束上限和稳态线。双容水箱系统使用一阶线性微分方程组建模,PID控制器结合比例、积分、微分作用,动态调整泵的输出流量,使液位接近设定值。
四自由度SCARA机器人的运动学和动力学matlab建模与仿真
本课题深入研究SCARA机器人系统,提出其动力学与运动学模型,并基于MATLAB Robotics Toolbox建立四自由度SCARA机器人仿真对象。通过理论结合仿真实验,实现了运动学正解、逆解及轨迹规划等功能,完成系统实验和算法验证。SCARA机器人以其平面关节结构实现快速定位与装配,在自动生产线中广泛应用,尤其在电子和汽车行业表现优异。使用D-H参数法进行结构建模,推导末端执行器的位姿,建立了机器人的运动学方程。
基于CS模型和CV模型的多目标协同滤波跟踪算法matlab仿真
本项目基于CS模型和CV模型的多目标协同滤波跟踪算法,旨在提高复杂场景下多个移动目标的跟踪精度和鲁棒性。通过融合目标间的关系和数据关联性,优化跟踪结果。程序在MATLAB2022A上运行,展示了真实轨迹与滤波轨迹的对比、位置及速度误差均值和均方误差等关键指标。核心代码包括对目标轨迹、速度及误差的详细绘图分析,验证了算法的有效性。该算法结合CS模型的初步聚类和CV模型的投票机制,增强了目标状态估计的准确性,尤其适用于遮挡、重叠和快速运动等复杂场景。
基于Adaboost的数据分类算法matlab仿真
本程序基于Adaboost算法进行数据分类的Matlab仿真,对比线性与非线性分类效果。使用MATLAB2022A版本运行,展示完整无水印结果。AdaBoost通过迭代训练弱分类器并赋予错分样本更高权重,最终组合成强分类器,显著提升预测准确率。随着弱分类器数量增加,训练误差逐渐减小。核心代码实现详细,适合研究和教学使用。
分别通过LS和RML进行模型参数辨识matlab仿真
本程序通过最小二乘法(LS)和递归最大似然估计(RML)进行模型参数辨识,并在MATLAB2022A中仿真。仿真输出包括参数辨识误差及收敛值。程序展示了两种方法的参数估计值及其误差收敛情况,适用于控制系统设计与分析。最小二乘法适合离线批量处理,而RML则适用于实时在线处理。核心代码实现了LS辨识,并绘制了参数估计值和误差变化图。
|
7月前
|
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
本文介绍了2023年高教社杯数学建模竞赛D题的圈养湖羊空间利用率问题,包括问题分析、数学模型建立和MATLAB代码实现,旨在优化养殖场的生产计划和空间利用效率。
284 6
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
本文提供了2022年华为杯数学建模竞赛B题的详细方案和MATLAB代码实现,包括方形件组批优化问题和排样优化问题,以及相关数学模型的建立和求解方法。
169 3
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
本文介绍了2023年五一杯数学建模竞赛B题的解题方法,详细阐述了如何通过数学建模和MATLAB编程来分析快递需求、预测运输数量、优化运输成本,并估计固定和非固定需求,提供了完整的建模方案和代码实现。
144 0
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码

热门文章

最新文章