- https://www.mathworks.com/help/supportpkg/raspberrypiio/examples/track-a-green-ball.html
- https://www.mathworks.com/help/vision/examples/motion-based-multiple-object-tracking.html
- https://www.mathworks.com/help/vision/tracking-and-motion-estimation.html
Matlab (function block in simulink)
2 views (last 30 days)
Show older comments
Hi everyone,
First I want to introduce the issue that I have and hope I make it clear. So, my objective is to use a servo and camera using Raspberry Pi to track a green tennis ball. The thing is that I can get the centre position of the ball (x and y) but my real problem is how I use those parameters to make the servo follow the ball. I have tried to write a simple script using the function block in matlab simulink but I dont see it working at all. So, I looked up and I found someone who's using the same thing a camera and servo but the code is in python. I got his idea but I failed to implement his Idea in matlab. The following is what I have written so far and also the simulink tracking of the system and also a link for the python script that I have found. I'm really still new to matlab and any input or help is appreciated. Also, sorry if my English isn't that great
Kind Regards Sal
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237555/image.png)
% Xin is the centre position of the ball
% Xout is the angle that the servo should
function Xout = fcn(Xin)
%intial position of the servo
panAngle=90;
%Move the servo between this range (90-140), and so that the servo moves the camera to the
%left and the camera keeps tracking the centre of the tennis ball. Once the
%ball is at the centre of the camera, servo must stop
if Xin<60 %( The tennis ball here is on the left side of the camera)
panAngle=Xin+panAngle; %(Move the servo to left)
Xout=panAngle;
% maximum range the servo should move to the left
if panAngle>140
Xout=140;
end
%Move the servo between this range (90-30), and so that the servo moves the camera to the
%left and the camera keeps tracking the centre of the tennis ball. Once the
%ball is at the centre of the camera, servo must stop
elseif Xin>100 %( The tennis ball here is on the right side of the camera)
panAngle=Xin-panAngle; %(Move the servo to right)
Xout=panAngle;
%maximum range the servo should move to the right
if panAngle<40
Xout=40;
end
% if object is not detected or outside the range of the camera (160*120)
% (x,y) then the servo shouldn't move or stay at it's last position since last time it saw the tennis ball
else
Xout=PanAngle;
end
0 Comments
Answers (1)
Rajani Mishra
on 13 Sep 2019
Hi,
I have found some tutorials for object tracking in MATLAB. Please go through below links:
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!