【问题标题】:serial communication beteen arduino and MATLABarduino 和 MATLAB 之间的串行通信
【发布时间】:2016-04-12 08:23:30
【问题描述】:

我目前正在做我最后一年的学习项目,我正在使用arduino due 和放置在轮椅上的超声波传感器来制造一个自主的。

所以我的问题是我正在读取传感器的距离,我需要将它们发送到matlab simulink 以在模糊逻辑控制器块中使用它们,但我不能因为我在串行中发送的内容ardiuno 的监视器类似于“ #distance1#distance2#...#distance10# " 是一个字符串类型,那么我如何使用串口获取数据(距离)以便在 matlab simulink 中使用它们。

我必须更改 arduino 代码还是应该在 simulink 中使用一些块? 任何回应都可能有帮助

【问题讨论】:

    标签: matlab arduino simulink serial-communication arduino-due


    【解决方案1】:

    您需要根据分隔符解析输入,并决定您应该经常对传感器进行采样。

    您希望您的输入在散列处被拆分。你应该使用类似的东西:

    str = input;    % from arduino buffer
    delimiter = "#";
    C = strsplit(str,delimiter)
    C = int(C)    % type case to an int
    

    您可能应该根据传感器的频率每 5 个信号读取一次。如果传感器每秒进行 100 次测量,您可能只需要处理 20 次。这看起来像:

     C = C[1:5:end]
    

    也许……

    处理您可能希望在某处使用传感器数据表中的错误标准的信号。解析输入可能在它被传递到 simulink 之前,或者作为第一个块之一。这取决于你(我不知道是否有最佳实践)。

    希望对你有所帮助!

    str split 的文档在这里: http://au.mathworks.com/help/matlab/ref/strsplit.html

    【讨论】:

    • 这可能对我很有帮助,谢谢 Jordan Stewart
    猜你喜欢
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多