Simulink 模型导出FMU
背景
有时我们需要将SIMULINK仿真模型到处FMU,在其他软件中进行联合仿真。
本文操作步骤来源于B站视频教学,操作的案例为matlab官网飞行器协同控制案例,但是没有成功,下面会说明详细说明遇到的问题。
补充
请转到2020b版本,官方文档有相关介绍,可以很方便导出FMU,不需要下面步骤的折腾了。
软件
-
matlab版本:matlab2018b
硬件
-
机器:联想Y7000
-
操作系统版本:win10教育版(64)
操作步骤
1 下载FMU工具
github下载链接 https://github.com/CATIA-Systems/FMIKit-Simulink/releases
我选择的是2.9版本
该项目还在这个页面描述了大概的用法,大致如下
% add the folder to the MATLAB path
addpath(fullfile(pwd, 'FMIKit-Simulink-2.9'))
% initialize FMI Kit
FMIKit.initialize()
如何导出该项目的fmu_export.md描述了我们要做的事情,可以配合视频,以及我的图解搭配着看。
2 FMU导出
新建文件,将模型与下载的压缩包放在该文件夹下,双击解压。
2.1 加载FMKIt
将上面的指令输入在matlab命令行中。提示完成
2.2 配置面板:
2.2.1 Solver配置
将Type设置为Fixed-typed
Solver 这个参数应该是精度 这里设置auto(tips如果模型很简单 Euler 格式可以更快,一般使用Odin1或者ode4(Runge-Kutta))
将Solver details 中的 Fixed-step-size 设置为0.1
2.2.2 Code Generation
将 Target selection中System target file的grtfmi.tlc (如果没有说明之前的指令加载失败)
2.3 生成代码
或者
一般到这就完成了,建议还是吧B站教学视频看一下,整体流程就是这样,我的错误主要是我的matlab没有编译器,可以通过mex -setup查看自己的电脑的matlab 编译器是哪种 VC2015 或者VC2017版本兼容可能会好一点。
我的错误
The call to grtfmi_make_rtw_hook, during the after_make hook generated the following error: Failed to run CMake. Run [grtfmi_install_cmake](matlab: grtfmi_install_cmake) to download and install CMake into the FMI Kit directory or install from [cmake.org](https://cmake.org/) and set the cmake command in Configuration Parameters > Code Generation > CMake Build > CMake Command if the cmake executable is not on the path and it is not installed in the default location.
因为没有编译器,这里让下载一个cmake 但是下载了自己也不会配置,233…………。
有关 cmake 配置面板位置如下图。
一般不用看这个。
后续更新
关于上图
CMAKE command
这里填写cmake.exe的系统完整路径就好例如 自己按照自己的填写(CMAKE generator正确的话这个不填也没事。。)D:\asbwarm\FMIKit-Simulink-2.9\cmake-3.15.2-win64-x64\bin\cmake.exe
CMAKE generator
我一直以为 Visual Studio 16 2019 是指visual 库 才发现她是真的是指 Visual Studio2019版本 ,我按照下面[链接](https://www.freesion.com/article/9239673162/ )https://www.freesion.com/article/9239673162/ 下载了
重启电脑解决问题
相关参考