How can use a MATLAB value in Arduino Uno code?

4 ビュー (過去 30 日間)
Kasper van Wijk
Kasper van Wijk 2015 年 4 月 1 日
コメント済み: Raphael Ferreira 2018 年 2 月 24 日
Dear all,
I have a question regarding to sending information between MATLAb and an Arduino Uno. I have made a little Matlab program that detects red objects from a webcam, and labels their coordinates. Now i have a setup with an Arduino Uno that includes a servo. I want this servo to respond to the variable y-coordinate send from my matlab program. How do i do this?
my detection program is:
if true
cam = webcam;
thresh = 0.29;
nFrame = 0;
while(nFrame < 100)
imgRGB = snapshot(cam);
imgGrey = imsubtract(imgRGB(:,:,1), rgb2gray(imgRGB));
imgGrey = medfilt2(imgGrey, [3 3]);
imgGrey = im2bw(imgGrey, thresh);
imgGrey = bwareaopen(imgGrey,200);
bw = bwlabel(imgGrey, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
imshow(imgRGB)
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','blue','LineWidth',1)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontSize', 12, 'Color', 'blue');
end
hold off
nFrame = nFrame+1;
end
the value bw(2) is the y-coordinate that i want to use to move my servo. what is the corresponding code that i should use in arduino? and matlab?
regards,
Kasper NL
  1 件のコメント
khsuhhal qasimyar
khsuhhal qasimyar 2016 年 11 月 2 日
編集済み: Walter Roberson 2016 年 11 月 2 日
Hi!
I am khushhal qasimyar from afghanistan i have final project smart soccer bots , in vision system i need your code to detect the red color and move servo with it send me your code if posibale i really need it urgently my mail is khushhal.qasimyar@gmail.com

サインインしてコメントする。

採用された回答

Abhishek GS
Abhishek GS 2015 年 4 月 6 日
Hi Kasper van Wijk,
Once you have the MATLAB Arduino support package installed, go through this example which shows how to use the MATLAB Support Package to control a servo motor. Once you go through the example you will be able to modify it suit your algorithm of making the servo respond to 'bw(2)'.
Thanks, Abhishek
  1 件のコメント
Kasper van Wijk
Kasper van Wijk 2015 年 4 月 6 日
編集済み: Kasper van Wijk 2015 年 4 月 6 日
Thanks a lot for your quick reply, Abhishek! I really appreciate it! I finally managed to get something working, although I do still have some trouble with the communication between my arduino and macbook. After uploading a file onto my arduino once, it stops communication and gives the following error:
avrdude: ser_open(): can't open device "/dev/tty.usbserial-A702MVJ5": Resource busy
ioctl("TIOCMGET"): Inappropriate ioctl for device.
I looked it up, but i can't find a concrete solution to the problem. Now I just have to close and re-open Matlab and arduino everytime I want to upload a new script, or run my matlab script.
Do you have a solution for this as well?
grz.Kasper

サインインしてコメントする。

その他の回答 (2 件)

kwstis xoustoulakis
kwstis xoustoulakis 2015 年 5 月 16 日
Hello! I have built a robotic arm with 3 servo and a camera mounted on the upper arms. Looking a code to detect red objects via the camera and move the arm at them. I suppose that something similar u have built ....? If you can help I would appreciate it !!! Thanks

Raphael Ferreira
Raphael Ferreira 2018 年 2 月 24 日
Hello! I'm from Brazil. I need your code to apply in a neurosurgery softwrae. Please, if you can, please send this red color code to my email. E-mail: <mailto:rkhayker@gmail.com rkhayker@gmail.com> I'm grateful already!
  2 件のコメント
Kasper van Wijk
Kasper van Wijk 2018 年 2 月 24 日
Please check your mail address. google says it doesn't exist...
Raphael Ferreira
Raphael Ferreira 2018 年 2 月 24 日
Has arrived! Thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by