matlab您的安装可能需要执行其他配置步骤_手把手超详细介绍MATLAB+RoadRunner+Unreal Engine自动驾驶联合仿真...
RoadRuner是MathWorks新收購(gòu)的自動(dòng)駕駛場(chǎng)景構(gòu)建工具,Unreal Engine是商業(yè)游戲引擎。RoadRunner創(chuàng)建駕駛場(chǎng)景,導(dǎo)入到Unreal Engine,與Simulink聯(lián)合仿真。這種方法兼具RoadRunner創(chuàng)建場(chǎng)景之便捷性和Unreal Engine渲染的高保真度。
之前的文章,已經(jīng)介紹了RoadRunner這個(gè)工具的一些特點(diǎn)。
卿顏:MATLAB新收購(gòu)的RoadRunner是什么?自動(dòng)駕駛場(chǎng)景軟件市場(chǎng)又添波瀾?zhuanlan.zhihu.com卿顏:MathWorks中國(guó)工程師最全問答 | 自動(dòng)駕駛場(chǎng)景編輯器——RoadRunner?zhuanlan.zhihu.com也有文章介紹了RoadRunner在自動(dòng)駕駛仿真領(lǐng)域的實(shí)戰(zhàn)應(yīng)用。
卿顏:MATLAB新殺器 RoadRunner實(shí)戰(zhàn)篇 | 基于MATLAB、RoadRunner、虛幻引擎和Speedgoat的駕駛員在環(huán)系統(tǒng)?zhuanlan.zhihu.com但還沒有文章詳細(xì)介紹MATLAB+RoadRunner+Unreal Engine這三個(gè)軟件具體怎么操作實(shí)現(xiàn)聯(lián)合仿真。整個(gè)聯(lián)合仿真的操作流程,幾乎都可以在MATLAB幫助文檔中找到。但筆者在親身實(shí)踐的過程中發(fā)現(xiàn),即便有詳細(xì)的幫助文檔,但依然有一些坑,在MathWorks Support團(tuán)隊(duì)的支持下,總算趟完了這些坑,順利地實(shí)現(xiàn)了整個(gè)流程。本文將手把手、一步步地詳細(xì)說明這個(gè)聯(lián)合仿真的過程。
MATLAB剛收購(gòu)RoadRunner沒多久,所以目前聯(lián)合仿真對(duì)軟件版本的匹配是有一定要求的。筆者采用的是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(無需關(guān)注此鏈接中其他內(nèi)容)。
Support Package for Customizing Scenes?www.mathworks.com2. 安裝基礎(chǔ)軟件
MATLAB和VS的安裝順序沒有特別要求。VS需在Ureal Engine之前安裝,否則有可能Unreal的.uproject文件沒法找到VS進(jìn)行編譯。
2.1 安裝Visual Studio2017
參照以下鏈接。
設(shè)置虛幻引擎的Visual Studio?docs.unrealengine.com設(shè)置虛幻引擎的Visual Studio
設(shè)置虛幻引擎的Visual Studio?docs.unrealengine.com請(qǐng)確保在工作量(Workloads)下選擇“用C++開發(fā)游戲(Game developmentwith C++)”。在右側(cè)的摘要(Summary)工具欄中,展開用C++開發(fā)游戲(Game development with C++),并勾選可選(Optional)下的虛幻引擎安裝程序(Unreal Engine installer)。注意,不要勾選Windows 10 SDK (10.0.17763.0)。
另外,如果用戶需要使用Simulink Real-Time工具箱,需要同時(shí)參照以下鏈接。
How do I set up Microsoft Visual Studio 2017 for SLRT??ww2.mathworks.cn2.2 安裝MATLAB R2020a
必備工具箱是Automated Driving Toolbox和Vehicle Dynamics Blockset。并使用mex -setup命令將MATLAB的編譯器設(shè)置成VS2017。
2.3 安裝Unreal Engine4.23
進(jìn)入U(xiǎn)nreal Engine官網(wǎng),點(diǎn)擊右上角的下載,注冊(cè)賬號(hào),下載Epic Games Launcher并安裝。
虛幻引擎 | 最強(qiáng)大的實(shí)時(shí)3D創(chuàng)作平臺(tái)?www.unrealengine.com登陸Epic Games Launcher,在“庫(kù)”界面中選擇Unreal Engine 4.23并安裝。
安裝完成后,可在上圖界面啟動(dòng)Unreal Editor 4.23。
2.4 安裝RoadRunner和RoadRunner Asset Library
用正版或者申請(qǐng)?jiān)囉冒?#xff0c;點(diǎn)擊以下鏈接可申請(qǐng)?jiān)囉冒妗?/p>Free RoadRunner Trial?www.mathworks.com
點(diǎn)擊以下鏈接,查看RoadRunner和RoadRunnerAsset Library的下載安裝指南。
https://www.mathworks.com/help/roadrunner/ug/install-and-activate-roadrunner.html?www.mathworks.com我們以Windows平臺(tái)下的individual license為例,加以說明。在MathWorks官網(wǎng)個(gè)人賬戶的my account中,查看License。
點(diǎn)擊上圖中RoadRunner的license,在以下界面Download Products。
點(diǎn)擊Manage Users→Add User。
Add User中設(shè)置郵箱和姓名等信息。接著Intall and Activate→Activate。
在下圖界面中填寫即將安裝RoadRunner的電腦的一些信息。
- Host ID——MAC地址或C盤序列號(hào)
如使用C盤序列號(hào),在Windows command prompt中執(zhí)行vol c:獲得信息。
- Computer Login Name
在Windows command prompt中執(zhí)行set username獲得信息。
- Activation Label——自行定義
提交上述信息后,網(wǎng)站會(huì)生成一個(gè)包含上述信息的RoadRunner license文件,將它下載到電腦中。最后安裝之前下載的程序,當(dāng)提示輸入license文件時(shí),選擇上一步下載的license文件。此時(shí),已完成安裝和激活工作。
3. 安裝插件
注意:完成上述步驟后,再裝插件。
3.1 安裝MATLAB的Unreal支持包和Unreal的MathWorks插件
參見
Install Support Package for Customizing Scenes?www.mathworks.com打開MATLAB的Add On/附加功能界面。
在界面中搜索unreal。
點(diǎn)開上圖紅框鏈接(Automated Driving ToolboxInterface for Unreal Engine 4 Projects),選擇安裝。
安裝完成后,需要在MATLAB中執(zhí)行以下代碼。
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",該路徑可自行設(shè)定,上述代碼會(huì)把支持包自帶的Unreal工程拷貝到該文件夾。
- ueInstFolder ="C:Program FilesEpic GamesUE_4.23",此處是指明Unreal Engine 4.23的安裝路徑。如果您的安裝路徑不是C:ProgramFilesEpic GamesUE_4.23,需要調(diào)整成實(shí)際路徑。
執(zhí)行結(jié)束后,會(huì)有兩個(gè)現(xiàn)象:
① localFolder中出現(xiàn)支持包自帶的Unreal工程。
② Unreal Editor中出現(xiàn)MathWorks插件。在Unreal Editor中點(diǎn)擊“編輯”→“插件”可進(jìn)行查看。
3.2 新建Unreal工程,安裝Unreal的RoadRunner插件
引自:
Exporting to Unreal?www.mathworks.com打開Unreal,設(shè)置項(xiàng)目文件夾和項(xiàng)目名稱后,創(chuàng)建一個(gè)項(xiàng)目,如下圖。
創(chuàng)建項(xiàng)目后,項(xiàng)目文件夾如下圖。注意,路徑中不要出現(xiàn)空格。
在該路徑下新建一個(gè)Plugins文件夾。
接著,點(diǎn)擊以下鏈接,下載Unreal的RoadRunner插件。
https://www.mathworks.com/help/roadrunner/ug/Downloading-Plugins.html?www.mathworks.com將插件文件夾中的RoadRunnerImporter和RoadRunnerMaterials文件夾(如下圖)都復(fù)制到上圖的Plugins文件夾中。每個(gè)unreal工程都得拷貝一次,否則roadrunner導(dǎo)出的信息沒法加載到Unreal。
然后,右鍵剛才新建的unreal 工程demo1.uproject,點(diǎn)擊Generate Visual Studio project files。之后,雙擊打開demo1.uproject,在彈出的窗口中選擇“是”。引自
Exporting to Unreal?www.mathworks.com在彈出Unreal Editor中,可以在“編輯”→“插件”中查看到Unreal已經(jīng)加載了RoadRunner的插件。
4. RoadRunner的場(chǎng)景導(dǎo)出到Unreal
參見:
Exporting to Unreal?www.mathworks.com我們以RoadRunner自帶的FourWaySignal場(chǎng)景為例,將它導(dǎo)出到Unreal。
4.1 將RoadRunner場(chǎng)景導(dǎo)出成文件
打開RoadRunner,新建場(chǎng)景/New Scene。在RoadRunner界面中,“File”→“Open Scene”選擇打開自帶的場(chǎng)景文件FourWaySignal.rrscene(如下圖)。
選擇“File”→“Export”→“Unreal (.fbx + .xml)”。
設(shè)定導(dǎo)出的目標(biāo)文件夾和文件名,如下圖。
導(dǎo)出完成后,目標(biāo)文件夾中就包含了導(dǎo)出的文件。
4.2 將導(dǎo)出文件加載到Unreal
打開Unreal Editor,在內(nèi)容瀏覽器中點(diǎn)擊“導(dǎo)入”。
選擇4.1中Exports文件夾中的fbx文件。
接著,導(dǎo)入的設(shè)置。設(shè)置界面如下圖。
具體如何設(shè)置,參考以下鏈接。導(dǎo)入完成后,注意保存,保存時(shí)設(shè)置MAP名稱。
https://www.mathworks.com/help/roadrunner/ug/Exporting-to-Unreal.html?www.mathworks.com5. MATLAB與UnrealEditor聯(lián)合仿真聯(lián)合仿真
Unreal的場(chǎng)景能以兩種形式與MATLAB聯(lián)合仿真:
① Unreal Editor直接運(yùn)行場(chǎng)景,聯(lián)合仿真時(shí)需要打開Unreal Editor
② Unreal場(chǎng)景導(dǎo)出成可執(zhí)行文件(exe),聯(lián)合仿真時(shí)無需打開Unreal Editor
此節(jié)介紹第一種方式。
5.1 從MATLAB打開Unreal Editor
引自:
Customize Scenes Using Simulink and Unreal Editor?www.mathworks.com如果直接在Unreal Editor中打開項(xiàng)目文件,則MATLAB和Simulink不會(huì)與Unreal Editor建立連接,因此也將無法聯(lián)合仿真。需要從MATLAB打開Unreal Editor。
雙擊Simulink模型的Simulation 3D SceneConfiguration模塊,將Scene source參數(shù)設(shè)置為Unreal Editor。在Project參數(shù)中,瀏覽到包含場(chǎng)景的項(xiàng)目文件。
單擊“Open Unreal Editor”,Unreal Editor將打開并從您的項(xiàng)目中加載場(chǎng)景。
第一次從MATLAB打開Unreal Editor時(shí),可能會(huì)要求您重新編譯UE4Editor DLL文件,點(diǎn)擊“Yes”以重新編譯。
當(dāng)UnrealEditor打開時(shí),您可以忽略有關(guān)名稱“_BuiltData”加載失敗的文件的所有警告消息。
如果您收到“the lighting needs to be rebuilt”的警告,請(qǐng)從Unreal Editor窗口上方的工具欄中,選擇“Build”→“Build Lighting Only”。首次打開場(chǎng)景或向場(chǎng)景中添加新元素時(shí),Unreal Editor會(huì)發(fā)出此警告。
另外,如果是自定義的場(chǎng)景,單擊“Open Unreal Editor”后,在出現(xiàn)的Unreal Editor中需要重設(shè)藍(lán)圖父項(xiàng),具體操作如下。
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.
實(shí)際操作步驟如下:
如果沒找到名為Sim3dLevelScriptActor的藍(lán)圖,那要先確認(rèn)Unreal是否啟用了MathWorks插件。查看插件的方式,3.1有說明,正常的狀態(tài)如下圖。
5.2 聯(lián)合仿真
在UnrealEditor中可以通過數(shù)字鍵切換視角,如下圖。
對(duì)于自定義的場(chǎng)景,如果也要實(shí)現(xiàn)這個(gè)功能,需要把DefaultInput.ini從如下路徑
C:ProgramDataMATLABSupportPackages<MATLABRelease>toolboxsharedsim3dprojectsdrivingAutoVrtlEnvConfig
拷貝到下面的路徑
<uproject路徑>Config
確保Simulation 3D Scene Configuration模塊的Scene source參數(shù)設(shè)置為Unreal Editor,Project參數(shù)設(shè)置為需要聯(lián)合仿真的場(chǎng)景文件。
先在Simulink中單擊運(yùn)行模型,等待DiagnosticViewer窗口顯示以下確認(rèn)消息:
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中點(diǎn)擊播放/Play。
6. MATLAB與Unreal可執(zhí)行文件聯(lián)合仿真
Unreal場(chǎng)景打包成可執(zhí)行文件(exe)進(jìn)行聯(lián)合仿真,聯(lián)合仿真時(shí)無需打開Unreal Editor。引自:
Package Custom Scenes into Executable?www.mathworks.com操作步驟:
1. 在Simulation3D Scene Configuration模塊,將Scene Source設(shè)置為Unreal Editor,選擇要打包的uproject,點(diǎn)擊“Open Unreal Editor”打開該uproject。同時(shí)確保已經(jīng)如步驟5.1中所述重設(shè)了父藍(lán)圖(如果直接打包exe,而未進(jìn)行unrealeditor形式的聯(lián)合仿真,容易疏漏這一步)。
2. 建議先把Unreal Editor的語(yǔ)言設(shè)置為English,在Unreal Editor工具欄的編輯→編輯器偏好設(shè)置→區(qū)域和語(yǔ)言。然后,在Unreal Editor中選擇Setting→Project Settings→Packaging,做以下設(shè)置。
3. 在List of maps toinclude in a packaged build中,點(diǎn)擊“+”添加要打包的Map(Map是指步驟4.2中保存的Map),如下圖。
紅框中的路徑很重要,之后在Simulink中會(huì)用到。
4. 回到Unreal Editor主界面,點(diǎn)擊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.
當(dāng)需要用自動(dòng)駕駛工具箱的攝像頭模型輸出語(yǔ)義分割圖時(shí)才需要執(zhí)行這一步。
6. 關(guān)閉Project Settings,在Unreal Editor主界面中點(diǎn)擊File > Package Project > Windows > Windows (64-bit),選擇一個(gè)合適的路徑,將exe打包到該路徑。打包時(shí)間長(zhǎng)短主要取決于電腦性能和場(chǎng)景的復(fù)雜程度。
注意:在建議在打包之前,建議確保完成以下操作,否則exe模式下操作UE4窗口不便。
把DefaultInput.ini從如下路徑
C:ProgramDataMATLABSupportPackages<MATLABRelease>toolboxsharedsim3dprojectsdrivingAutoVrtlEnvConfig
拷貝到下面的路徑
<uproject路徑>Config
7. 打包完成后,在對(duì)應(yīng)路徑下會(huì)生成對(duì)應(yīng)的exe文件,如下圖。
8. 回到Simulink模型,在Simulation 3D Scene Configuration模塊,將Scene Source設(shè)置為Unreal Executable,File name選擇成步驟7中生成的exe文件,Scene設(shè)置為步驟3紅框中的路徑。
9. 在Simulink中運(yùn)行模型,運(yùn)行后場(chǎng)景界面會(huì)自動(dòng)打開。
10. 默認(rèn)情況下,場(chǎng)景是以全屏的方式打開的,如果想把場(chǎng)景以窗口模式打開,可以執(zhí)行操作:在打包文件路徑下的WindowsNoEditor工程名SavedConfigWindowsNoEditor找到GameUserSettings.ini文件,打開該文件:把所有以mode結(jié)尾的參數(shù)(紅色框)都設(shè)置成2;分辨率設(shè)置(藍(lán)色框)要低于你所用電腦的分辨率。
注:第一次打開WindowsNoEditor工程名時(shí)可能找不到Save的文件夾,可以先聯(lián)合仿真一次,然后Saved文件夾會(huì)自動(dòng)生成。
總結(jié)
以上是生活随笔為你收集整理的matlab您的安装可能需要执行其他配置步骤_手把手超详细介绍MATLAB+RoadRunner+Unreal Engine自动驾驶联合仿真...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: julia 调用python库_Juli
- 下一篇: zookeeper安装_Linux下安装