Hello
I would like to show you my project that I've recently been working on. The idea was to build a desktop robotic arm possible to control with computer mouse. After I achieved that, I came to a conclusion that the project was too simple - that's just controlling 4 servos with a computer mouse - not funny at all, so I started my work on image processing program. I am familiar with Matlab software so I decided to use it for this purpose. Brief introduction and demonstration can be seen here:
Before we proceed - if you enjoyed the video and are interested in this project, please leave an upvote (thumb up) under the video on youtube. I am taking part in Matlab's Hardware Challange and this will really help me
For these of you that don't know - Matlab is extremely powerfull tool. It is capable of solving complex math problems, also is perfect for control systems simulations, image and audio processing, pretty much everything There are 2 ways to make our Arduino board cooperate with Matlab. First is by using Matlab support package for Arduino, it's quite handy when you want to access some variables from Matlab to show them on graphs or do math calculations on them. The second way (the one I used) is using serial comunication.
First things first - mouse
To connect my mouse to Arduino I used this library and this schematic. This is quite easy to use, but connecting mouse's wires to arduino can be tricky- these are very thin and can be damaged easily.
Automatic mode - image processing
The main idea of image processing algorithm is shown on the video. Here I would like to extend it a little and post actual Matlab functions that i used.
First of all - we need to connect Matlab to our webcam. To do this we need to click Add-Ons, Get Hardware Support Packages, Install from Internet, USB Webcams. If you have any problems with Matlab - simply use Mathworks' website, there are many examples and tips there.
The most important Matlab functions that I used are:
snapshot - to acquire images from webcam
rgb2gray - to convert image to greyscale
bwareaopen - to remove noise from binary picture
regionprops - to measure my white spot and find its location
I will try to post my Matlab code on Matlab File Exchange as soon as I switch it to english, I think it will be more convenient than posting the whole code here. I will link it when I'm finished
So from the last function, Matlab is able to find centerpoint of the tape (its position). It then calculates on which out of 3 possible locations the tape is. What is left to do is to send the location number to Arduino with fprintf function. Then arduino (depending on what value it recieved) decides which location to approach.
Matlab support package for Arduino
As I've mentioned before - there is also Arduino package for Matlab which comes in handy from time to time. I didn't use it in this project but I would like to say a few words of an example use of it. A while ago I was working on PID controller on operational amplifiers and I didn't have an idea of how to observe my system's step response. Arduino and Matlab were my saviors. All I had to do was to connect the signal I was interested in to Arduino's analog input and run this code in Matlab.
a=arduino;
i = 1;
tic
while (toc<10)
b(i) = a.readVoltage(0);
plot(b);
drawnow;
i=i+1;
end
Example screenshots:
PID's step response:
System's step response with overshoot:
Optimized system's step response:
You could of course switch X axis to time instead of samples, but this is still nice.
As you see - connecting Arduino to such a powerfull tool like Matlab is pretty easy and has multiple possible applications. If you have any questions or you would like me to explain something in details - simply ask