如何将数据采集Matlab脚本转换为Simulink? [英] How to convert a data acquisition Matlab script to Simulink?

查看:398
本文介绍了如何将数据采集Matlab脚本转换为Simulink?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写的Matlab脚本将用作控制系统的反馈.我已经下载了一个名为"HX711的自定义Arduino库"的库.尼古拉斯·吉亚科博尼(Nicholas Giacoboni).

The Matlab script which I wrote is going to be used as a feedback for my control system. I have downloaded a library done called "Custom Arduino Library for HX711" by Nicholas Giacoboni.

我想转换我编写的 Matlab脚本的Matlab脚本.我还对脚本进行了单独测试,并且可以正常工作.
HX711是称重传感器放大器ADC转换器.

I want to convert a Matlab script which I wrote Matlab script. I have also tested the script by itself and it works.
HX711 is a load cell amplifier ADC converter.

function data = Loadcell()
eml.extrinsic('arduino','addon','read_HX711')

a = arduino('COM5','Mega2560','libraries','ExampleAddon/HX711');
scale = -338000;
while 1
    LoadCell = addon(a, 'ExampleAddon/HX711',{'D6','D5'});
    data = (read_HX711(LoadCell)-7388092)/scale
    
end
end

当前 Simulink功能块的simulink布局.

the layout of simulink at the moment Simulink function block.

然后我在正常模式下运行Simulink,并在inf上模拟了停止时间,它出现了这个错误.如何解决该错误并使它正常工作?

And I run Simulink on Normal mode and simulation stop time at inf it comes up with this error. How do I solve this error and get this working?

此致

艾伦

推荐答案

至少您需要在文件顶部定义data的大小.解析器不知道read_HX711返回什么,因此无法为data分配内存.您可能需要对aLoadCell做同样的事情.

At a minimum you need to define the size of data at the top of the file. The parser has no idea of what read_HX711 returns and hence cannot allocate memory for data. You probably need to do the same for a and LoadCell.

也就是说,您需要类似的东西,

That is, you need something like,

data = zeros(1,1);
a = zeros(1,1);
LoadCell = zeros(1,1);

在文件顶部.

如果这不起作用,那么我建议您将以上所有代码放入一个单独的m文件中的函数中,该函数仅返回您的data变量.然后在您的MATLAB Function块代码中,只需调用一次您的新函数(仍然需要将其定义为外部函数).

If that doesn't work, then I would suggest that you put all of your above code into a function in a separate m-file, where that function returns just your data variable. Then in your MATLAB Function block code just have one call to your new function (which will still need to be defined as extrinsic).

这篇关于如何将数据采集Matlab脚本转换为Simulink?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆