RoadRuner是MathWorks新收购的自动驾驶场景构建工具,Unreal Engine是商业游戏引擎。RoadRunner创建驾驶场景,导入到Unreal Engine,与Simulink联合仿真。这种方法兼具RoadRunner创建场景之便捷性和Unreal Engine渲染的高保真度。

之前的文章,已经介绍了RoadRunner这个工具的一些特点。

卿颜:MATLAB新收购的RoadRunner是什么?自动驾驶场景软件市场又添波澜​zhuanlan.zhihu.com

卿颜:MathWorks中国工程师最全问答 | 自动驾驶场景编辑器——RoadRunner​zhuanlan.zhihu.com

也有文章介绍了RoadRunner在自动驾驶仿真领域的实战应用。

卿颜:MATLAB新杀器 RoadRunner实战篇 | 基于MATLAB、RoadRunner、虚幻引擎和Speedgoat的驾驶员在环系统​zhuanlan.zhihu.com

但还没有文章详细介绍MATLAB+RoadRunner+Unreal Engine这三个软件具体怎么操作实现联合仿真。整个联合仿真的操作流程,几乎都可以在MATLAB帮助文档中找到。但笔者在亲身实践的过程中发现,即便有详细的帮助文档,但依然有一些坑,在MathWorks Support团队的支持下,总算趟完了这些坑,顺利地实现了整个流程。本文将手把手、一步步地详细说明这个联合仿真的过程。

MATLAB刚收购RoadRunner没多久,所以目前联合仿真对软件版本的匹配是有一定要求的。笔者采用的是MATLAB R2020a+RoadRunner+Unreal Engine4.23。

1. 电脑软硬件要求

软件要求:

  • Windows® 64-bitplatform
  • Unreal Editor 4.23
  • Visual Studio® 2017or higher
  • Microsoft® DirectX® —— If this software is not already installedon your machine and you try to simulate in the 3D environment, Vehicle DynamicsBlockset prompts you to install it. Once you install the software, you mustrestart the simulation.
  • Automated DrivingToolbox Interface for Unreal Engine 4 Projects,详见3.1

最低硬件要求:

  • Graphics card (GPU)— Virtual reality-ready GPU with 8 GB of onboard RAM
  • Processor (CPU) —2.60 GHz
  • Memory (RAM) — 12 GB

如果要获得流畅的仿真效果,建议配置高性能显卡。以上信息,引自以下链接中的Support Package for Customizing Scenes(无需关注此链接中其他内容)。

Support Package for Customizing Scenes​www.mathworks.com

2. 安装基础软件

MATLAB和VS的安装顺序没有特别要求。VS需在Ureal Engine之前安装,否则有可能Unreal的.uproject文件没法找到VS进行编译。

2.1 安装Visual Studio2017

参照以下链接。

设置虚幻引擎的Visual Studio​docs.unrealengine.com

设置虚幻引擎的Visual Studio

设置虚幻引擎的Visual Studio​docs.unrealengine.com

请确保在工作量(Workloads)下选择“用C++开发游戏(Game developmentwith C++)”。在右侧的摘要(Summary)工具栏中,展开用C++开发游戏(Game development with C++),并勾选可选(Optional)下的虚幻引擎安装程序(Unreal Engine installer)。注意,不要勾选Windows 10 SDK (10.0.17763.0)。

另外,如果用户需要使用Simulink Real-Time工具箱,需要同时参照以下链接。

How do I set up Microsoft Visual Studio 2017 for SLRT?​ww2.mathworks.cn

2.2 安装MATLAB R2020a

必备工具箱是Automated Driving Toolbox和Vehicle Dynamics Blockset。并使用mex -setup命令将MATLAB的编译器设置成VS2017。

2.3 安装Unreal Engine4.23

进入Unreal Engine官网,点击右上角的下载,注册账号,下载Epic Games Launcher并安装。

虚幻引擎 | 最强大的实时3D创作平台​www.unrealengine.com

登陆Epic Games Launcher,在“库”界面中选择Unreal Engine 4.23并安装。

安装完成后,可在上图界面启动Unreal Editor 4.23。

2.4 安装RoadRunner和RoadRunner Asset Library

用正版或者申请试用版,点击以下链接可申请试用版。

Free RoadRunner Trial​www.mathworks.com

点击以下链接,查看RoadRunner和RoadRunnerAsset Library的下载安装指南。

https://www.mathworks.com/help/roadrunner/ug/install-and-activate-roadrunner.html​www.mathworks.com

我们以Windows平台下的individual license为例,加以说明。在MathWorks官网个人账户的my account中,查看License。

点击上图中RoadRunner的license,在以下界面Download Products。

点击Manage Users→Add User。

Add User中设置邮箱和姓名等信息。接着Intall and Activate→Activate。

在下图界面中填写即将安装RoadRunner的电脑的一些信息。

  • Host ID——MAC地址或C盘序列号

如使用C盘序列号,在Windows command prompt中执行vol c:获得信息。

  • Computer Login Name

在Windows command prompt中执行set username获得信息。

  • Activation Label——自行定义

提交上述信息后,网站会生成一个包含上述信息的RoadRunner license文件,将它下载到电脑中。最后安装之前下载的程序,当提示输入license文件时,选择上一步下载的license文件。此时,已完成安装和激活工作。

3. 安装插件

注意:完成上述步骤后,再装插件。

3.1 安装MATLAB的Unreal支持包和Unreal的MathWorks插件

参见

Install Support Package for Customizing Scenes​www.mathworks.com

打开MATLAB的Add On/附加功能界面。

在界面中搜索unreal。

点开上图红框链接(Automated Driving ToolboxInterface for Unreal Engine 4 Projects),选择安装。

安装完成后,需要在MATLAB中执行以下代码。

supportPackageFolder= fullfile( ...

matlabshared.supportpkg.getSupportPackageRoot, ...

"toolbox","shared","sim3dprojects","driving");

localFolder = "C:Local";

projectFolderName= "AutoVrtlEnv";

projectSupportPackageFolder= fullfile(supportPackageFolder,projectFolderName);

projectLocalFolder= fullfile(localFolder,projectFolderName);

if~exist(projectLocalFolder,"dir")

copyfile(projectSupportPackageFolder,projectLocalFolder);

end

ueInstallFolder= "C:Program FilesEpic GamesUE_4.23";

supportPackageFolder= fullfile( ...

matlabshared.supportpkg.getSupportPackageRoot, ...

"toolbox","shared","sim3dprojects","driving");

mwPluginName = "MathWorksSimulation.uplugin";

mwPluginFolder =fullfile(supportPackageFolder,"PluginResources","UE423");

uePluginFolder =fullfile(ueInstallFolder,"Engine","Plugins");

uePluginDestination= fullfile(uePluginFolder,"Marketplace","MathWorks");

cd(uePluginFolder)

foundPlugins =dir("**/" + mwPluginName);

if~isempty(foundPlugins)

numPlugins = size(foundPlugins,1);

msg2 = cell(1,numPlugins);

pluginCell = struct2cell(foundPlugins);

msg1 = "Plugin(s)already exist here:" + newline + newline;

for n = 1:numPlugins

msg2{n} = " " + pluginCell{2,n}+ newline;

end

msg3 = newline + "Please removeplugin folder(s) and try again.";

msg = msg1 + msg2 + msg3;

warning(msg);

else

copyfile(mwPluginFolder,uePluginDestination);

disp("Successfullycopied MathWorksSimulation plugin to UE4 engine plugins!")

end

以上代码引自以下链接的Set Up Scene Customization UsingSupport Package。

Install Support Package for Customizing Scenes​www.mathworks.com

值得注意的是:

  • localFolder ="C:Local",该路径可自行设定,上述代码会把支持包自带的Unreal工程拷贝到该文件夹。
  • ueInstFolder ="C:Program FilesEpic GamesUE_4.23",此处是指明Unreal Engine 4.23的安装路径。如果您的安装路径不是C:ProgramFilesEpic GamesUE_4.23,需要调整成实际路径。

执行结束后,会有两个现象:

① localFolder中出现支持包自带的Unreal工程。

② Unreal Editor中出现MathWorks插件。在Unreal Editor中点击“编辑”→“插件”可进行查看。

3.2 新建Unreal工程,安装Unreal的RoadRunner插件

引自:

Exporting to Unreal​www.mathworks.com

打开Unreal,设置项目文件夹和项目名称后,创建一个项目,如下图。

创建项目后,项目文件夹如下图。注意,路径中不要出现空格

在该路径下新建一个Plugins文件夹。

接着,点击以下链接,下载Unreal的RoadRunner插件。

https://www.mathworks.com/help/roadrunner/ug/Downloading-Plugins.html​www.mathworks.com

将插件文件夹中的RoadRunnerImporter和RoadRunnerMaterials文件夹(如下图)都复制到上图的Plugins文件夹中。每个unreal工程都得拷贝一次,否则roadrunner导出的信息没法加载到Unreal。

然后,右键刚才新建的unreal 工程demo1.uproject,点击Generate Visual Studio project files。之后,双击打开demo1.uproject,在弹出的窗口中选择“是”。引自

Exporting to Unreal​www.mathworks.com

在弹出Unreal Editor中,可以在“编辑”→“插件”中查看到Unreal已经加载了RoadRunner的插件。

4. RoadRunner的场景导出到Unreal

参见:

Exporting to Unreal​www.mathworks.com

我们以RoadRunner自带的FourWaySignal场景为例,将它导出到Unreal。

4.1 将RoadRunner场景导出成文件

打开RoadRunner,新建场景/New Scene。在RoadRunner界面中,“File”→“Open Scene”选择打开自带的场景文件FourWaySignal.rrscene(如下图)。

选择“File”→“Export”→“Unreal (.fbx + .xml)”。

设定导出的目标文件夹和文件名,如下图。

导出完成后,目标文件夹中就包含了导出的文件。

4.2 将导出文件加载到Unreal

打开Unreal Editor,在内容浏览器中点击“导入”。

选择4.1中Exports文件夹中的fbx文件。

接着,导入的设置。设置界面如下图。

具体如何设置,参考以下链接。导入完成后,注意保存,保存时设置MAP名称。

https://www.mathworks.com/help/roadrunner/ug/Exporting-to-Unreal.html​www.mathworks.com

5. MATLAB与UnrealEditor联合仿真联合仿真

Unreal的场景能以两种形式与MATLAB联合仿真:

① Unreal Editor直接运行场景,联合仿真时需要打开Unreal Editor

② Unreal场景导出成可执行文件(exe),联合仿真时无需打开Unreal Editor

此节介绍第一种方式。

5.1 从MATLAB打开Unreal Editor

引自:

Customize Scenes Using Simulink and Unreal Editor​www.mathworks.com

如果直接在Unreal Editor中打开项目文件,则MATLAB和Simulink不会与Unreal Editor建立连接,因此也将无法联合仿真。需要从MATLAB打开Unreal Editor。

双击Simulink模型的Simulation 3D SceneConfiguration模块,将Scene source参数设置为Unreal Editor。在Project参数中,浏览到包含场景的项目文件。

单击“Open Unreal Editor”,Unreal Editor将打开并从您的项目中加载场景。

第一次从MATLAB打开Unreal Editor时,可能会要求您重新编译UE4Editor DLL文件,点击“Yes”以重新编译。

当UnrealEditor打开时,您可以忽略有关名称“_BuiltData”加载失败的文件的所有警告消息。

如果您收到“the lighting needs to be rebuilt”的警告,请从Unreal Editor窗口上方的工具栏中,选择“Build”→“Build Lighting Only”。首次打开场景或向场景中添加新元素时,Unreal Editor会发出此警告。

另外,如果是自定义的场景,单击“Open Unreal Editor”后,在出现的Unreal Editor中需要重设蓝图父项,具体操作如下。

If this is your first time opening a customproject in Unreal Editor 4.23, you may need to associate, or reparent, thisproject with the Sim3dLevelScriptActor level blueprint used in Vehicle DynamicsBlockset. The level blueprint controls how objects interact once placed withinin the Unreal environment. If you do not reparent the project to this levelblueprint, the simulation returns an error.

To reparent the level blueprint:

In theUnreal Editor toolbar above the editor window, select Blueprints > OpenLevel Blueprint.

In theLevel Blueprint window, select File > Reparent Blueprint.

Click theSim3dLevelScriptActor blueprint and close the Level Blueprint window.

If you do not see this blueprint, make surethat you have the MathWorksSimulation plugin installed and enabled.

Navigate back to the editor window. In thetoolbar above this window, select Settings > Plugins.

In the Plugins window, verify that theMathWorks Interface plugin appears. This plugin refers to theMathWorksSimulation.uplugin file that you copied into your local Unreal Editorinstallation from the Vehicle Dynamics Blockset Support Package for UnrealEngine 4 Projects.

If you editor installation includes theplugin, then when you open a project in the editor for the first time, you areprompted to enable this plugin. If you do not see the MathWorks Interfaceplugin in this window, repeat the steps under and reopen the editor fromMATLAB.

Select the Enabled check box.Close the editor, reopen it from MATLAB, andrepeat the steps to reparent the blueprint.

实际操作步骤如下:

如果没找到名为Sim3dLevelScriptActor的蓝图,那要先确认Unreal是否启用了MathWorks插件。查看插件的方式,3.1有说明,正常的状态如下图。

5.2 联合仿真

在UnrealEditor中可以通过数字键切换视角,如下图。

对于自定义的场景,如果也要实现这个功能,需要把DefaultInput.ini从如下路径

C:ProgramDataMATLABSupportPackages<MATLABRelease>toolboxsharedsim3dprojectsdrivingAutoVrtlEnvConfig

拷贝到下面的路径

<uproject路径>Config

确保Simulation 3D Scene Configuration模块的Scene source参数设置为Unreal Editor,Project参数设置为需要联合仿真的场景文件。

先在Simulink中单击运行模型,等待DiagnosticViewer窗口显示以下确认消息:

In the Simulation 3D SceneConfiguration block, you set the scene source to 'Unreal Editor'.

In Unreal Editor, select'Play' to view the scene.

然后在Unreal Editor中点击播放/Play。

6. MATLAB与Unreal可执行文件联合仿真

Unreal场景打包成可执行文件(exe)进行联合仿真,联合仿真时无需打开Unreal Editor。引自:

Package Custom Scenes into Executable​www.mathworks.com

操作步骤:

1. 在Simulation3D Scene Configuration模块,将Scene Source设置为Unreal Editor,选择要打包的uproject,点击“Open Unreal Editor”打开该uproject同时确保已经如步骤5.1中所述重设了父蓝图(如果直接打包exe,而未进行unrealeditor形式的联合仿真,容易疏漏这一步)。

2. 建议先把Unreal Editor的语言设置为English,在Unreal Editor工具栏的编辑→编辑器偏好设置→区域和语言。然后,在Unreal Editor中选择Setting→Project Settings→Packaging,做以下设置。

3. 在List of maps toinclude in a packaged build中,点击“+”添加要打包的Map(Map是指步骤4.2中保存的Map),如下图。

红框中的路径很重要,之后在Simulink中会用到。

4. 回到Unreal Editor主界面,点击Build→Build Lighting Only
If you do notrebuild the lighting, the shadows from the light source in your executable fileare incorrect and a warning about rebuilding the lighting displays duringsimulation.

5. (Optional) If you plan to semantic segmentation data from the sceneby using a Simulation 3D Camera block, enable rendering of the stencil IDs. Inthe left pane, in the Engine section, click Rendering. Then, in the mainwindow, in the Postprocessing section, set Custom Depth-Stencil Pass to Enabledwith Stencil. For more details on applying stencil IDs for semanticsegmentation, see Apply Semantic Segmentation Labels to Custom Scenes.

当需要用自动驾驶工具箱的摄像头模型输出语义分割图时才需要执行这一步。

6. 关闭Project Settings,在Unreal Editor主界面中点击File > Package Project > Windows > Windows (64-bit),选择一个合适的路径,将exe打包到该路径。打包时间长短主要取决于电脑性能和场景的复杂程度。

注意:在建议在打包之前,建议确保完成以下操作,否则exe模式下操作UE4窗口不便。

把DefaultInput.ini从如下路径

C:ProgramDataMATLABSupportPackages<MATLABRelease>toolboxsharedsim3dprojectsdrivingAutoVrtlEnvConfig

拷贝到下面的路径

<uproject路径>Config

7. 打包完成后,在对应路径下会生成对应的exe文件,如下图。

8. 回到Simulink模型,在Simulation 3D Scene Configuration模块,将Scene Source设置为Unreal Executable,File name选择成步骤7中生成的exe文件,Scene设置为步骤3红框中的路径。

9. 在Simulink中运行模型,运行后场景界面会自动打开。

10. 默认情况下,场景是以全屏的方式打开的,如果想把场景以窗口模式打开,可以执行操作:在打包文件路径下的WindowsNoEditor工程名SavedConfigWindowsNoEditor找到GameUserSettings.ini文件,打开该文件:把所有以mode结尾的参数(红色框)都设置成2;分辨率设置(蓝色框)要低于你所用电脑的分辨率。

注:第一次打开WindowsNoEditor工程名时可能找不到Save的文件夹,可以先联合仿真一次,然后Saved文件夹会自动生成。

matlab您的安装可能需要执行其他配置步骤_手把手超详细介绍MATLAB+RoadRunner+Unreal Engine自动驾驶联合仿真...相关推荐

  1. MATLAB+Unreal Engine自动驾驶联合仿真

    这里假设已经安装好了Unreal Engine(版本4.25)MATLAB2021b 以及Visual Studio® 2017or higher .MATLAB官方文档给的匹配的UE4版本号是4.2 ...

  2. iis配置-- 安装步骤(最新 超详细 图文)

    文章目录 1.安装IIS 2.安装.net 4.0 (.net 4.0.30319.0) 3. 如何新建网站(未完待续) 4.将你新建的网站设置为.net4.0 ------------------- ...

  3. maven配置阿里云_阿里云OSS PicGo 配置图床教程 超详细

    阿里云OSS和PicGo配置图床教程 超详细 废话不多说,直接开始 购买阿里云OSS服务 登录阿里云 打开侧边栏,选择对象存储OSS,如下图: 对象存储界面右部选择创建Bucket,如下图所示: 之后 ...

  4. 阿里云OSS PicGo 配置图床教程 超详细

    阿里云OSS和PicGo配置图床教程 超详细 废话不多说,直接开始 购买阿里云OSS服务 登录阿里云 打开侧边栏,选择对象存储OSS,如下图: 对象存储界面右部选择创建Bucket,如下图所示: 之后 ...

  5. Win10基于python,spleeter 人声提取工具安装和使用(全网最全,超详细)

    Win10基于python,spleeter 音频分轨工具安装和使用(全网最全,超详细) 小声BB(不想看可直接跳到正片) 碎碎念(写给小白) 正片开始 说明 总体的框架 详细步骤 1.安装pytho ...

  6. Windows10系统下配置mmdetection2.6(超详细)

    Windows10系统下配置mmdetection2.6(超详细) 因为最近参加目标检测的比赛,选择Varifocalnet做训练论文链接,代码链接,这个模型需要在mmdetection上配置,这篇博 ...

  7. 操作系统linux配置php,操作系统--Linux的详细介绍

    一 概述 1.什么是操作系统? 操作系统是人与计算机硬件交互的中介.用户无法直接与计算机硬件交互,无法直接指挥计算机工作,因此需要一个中介,这个中介就是操作系统,用户向操作系统发出命令,由操作系统直接 ...

  8. 基于PreSCAN Matlab/Simulink的智能驾驶联合仿真【详细图文】

    在自动驾驶竞争日益激烈的趋势下,自动驾驶功能不断更新迭代,但任何功能的商业化推出之前,测试是必然的前提,如软件测试.仿真测试.道路测试,尽管在我国政策的支持情况下(如颁发道路测试牌照),自动驾驶道路测 ...

  9. Nginx超详细介绍 nginx入门 nginx配置 nginx详解 nginx优化

    # 此文加上部署课程一起 nginx文档 nginx配置基本全了 nginx七种状态(tcp是11种状态) #nginx七种状态 Active connections: 2 server accept ...

最新文章

  1. Homography matrix(单应性矩阵)在广告投放中的实践
  2. C#实现动态编译代码
  3. a*算法流程图_学好流程控制结构轻松应对高考数学程序算法题
  4. 机器学习(1)之梯度下降(gradient descent)
  5. 如何做相册_我是如何对2000张照片进行批量套版的
  6. Go Elasticsearch 删除快速入门
  7. Android7.1开机启动脚本
  8. 软媒魔方6.13正式版:软件管家开启多线程极速下载
  9. GBase数据库日常运维操作(一)
  10. Microsoft Network Monitor的select network栏空白
  11. 英语语法总结--主谓一致
  12. 郑州轻工业大学OJ python 1060: 逆序数字
  13. Android: 如何切换 SCO 链路。
  14. 多张CAD图纸需要转换PDF格式怎么样操作更快?
  15. 实时系统和非实时系统的区别
  16. 软件定义汽车:架构分析
  17. 前端解决图片在浏览器中旋转问题
  18. 云计算机房计算机等级保护三级,等级保护制度第三级要求
  19. java dao层编写及注释_JAVA代码注释规范
  20. 智能空调安卓APP远程控制空调开关和温度(TCP/IP协议)

热门文章

  1. u盘安装linux启动报错,U盘安装centos7,启动报错
  2. 【算法】一个简单的支持向量机(SVM)原理
  3. 【Python】正负无穷
  4. 【Matlab】找到矩阵中每个连通域的最小值
  5. 科大星云诗社动态20220112
  6. 中学计算机科学教育,计算机科学教育周 – Tsinghua International School 清华大学附属中学国际部...
  7. linux 切换用户_Linux 用户态切换到内核态的 3 种方式
  8. python编程标准_Python常见编程规范总结
  9. matlab神经网络4:数据聚类-自组织映射
  10. 你很烫吗?我很烫——关于栈区和静态存储区的思考