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

     

  • 相关阅读:
    接口幂等性问题
    我的创作纪念日
    m基于光纤光栅传感网接入GPON的光纤通信系统matlab性能仿真,包括解码,解封装,分接,码率恢复,解帧,拆包,译码
    Linux—vmstat命令详解
    布尔矩阵的奇偶性
    关于Android JS与原生的交互
    自己写了一个CM管理GBase数据库集群
    Head First设计模式(阅读笔记)-04.工厂模式
    中小型企业文档管理和工作流程解决方案
    Docker笔记-常用命令
  • 原文地址:https://blog.csdn.net/matlab_dingdang/article/details/128161182