matlab function for arduino
6 ビュー (過去 30 日間)
古いコメントを表示
Hi
I want to use matlab function to write code for Arduino boards
in the matlab function I have written this :
function [count1 count2 count2]=fcn
a1=arduino('com3','due','Libraries','RotaryEncoder');
a2=arduino('com5','uno','Libraries','RotaryEncoder');
encoder1=rotaryEncoder(a1,'D2','D3');
encoder2=rotaryEncoder(a1,'D4','D5');
encoder3=rptaryEncoder(a2,'D2','D3');
count1=readCount(encoder1);
count1=readCount(encoder2);
count3=readCount(encoder2);
end
but it showed this error:
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/208338/Capture.png)
![Capture1.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/208339/Capture1.png)
0 件のコメント
回答 (2 件)
Madhu Govindarajan
2019 年 3 月 13 日
Based on the error it looks like you are attempting to use MATLAB Function block within a Simulink Model. In this approach, you cannot use arduino function and other MATLAB Support Package for Arduino functions as this workflow is completely different from Simulink Support for Arduino.
If you post details about your project, experts might be able to assist you with selecting the appropriate workflow.
Madhu Govindarajan
2019 年 3 月 14 日
I think you are better off using the Simulink workflow to perform controls and not use the MATLAB Support package for Arduino functions in MATLAB function blocks. Given that comment, if you want to control DC motors from an Arduino people usually use a Motor Control board or are using direct PWM signals.
So I propose you create a new question in Maker Community here mentioning details of your hardware setup including what motors you have, what is the controlling method (see above), what encoders are you using etc. This will get you the right answer the fastest.
If you are looking for generic examples, here are some links -
motor and encoders using MKR Motor Carrier - https://www.mathworks.com/matlabcentral/fileexchange/68620-arduino_engineering_kit_hardware_support_18b
Madhu
参考
カテゴリ
Help Center および File Exchange で Arduino Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!