Trying to make loop works.
古いコメントを表示
I need to make a loop keep running until a condition in the code is met to break the loop.
I was thinking of using a while loop like this:
while (Y<60);
motorX_down;
end
while(Y>60);
motorX_up
end
if (Y==60);
motor_stop;
end
I use this code to control my motors according to the feedback from the image processing. My objective is to make the camera move so that its center is the same as the detected object coordinate. I had the image processing part done and can get the detected object coordinate in X and Y.
Then arduino will move the motor to adjust the camera.
Now my frame size 160x120 with X:80 and Y:60 as the center.
motorX_up will make the camera move up. motorX_down will make the camera move down. motor_stop will stop the camera.
So far i'm only trying to make the camera move vertically only to test it.
But when I run the code, the motor move only down :( So maybe I thought I had the while loop wrong.
回答 (1 件)
Honglei Chen
2013 年 3 月 5 日
Because you never update Y in your first loop so it keeps going down. You need to update Y value in the loop, for example
Y = Some_function_to_generate_Y;
while Y~=60
if Y < 60
motorX_down;
else
motorX_up;
end
Y = Some_function_to_generate_Y;
end
5 件のコメント
Adrian Dronca
2013 年 3 月 5 日
Y is a variable not a function. It must be initialized before using it.
Honglei Chen
2013 年 3 月 5 日
I can't comment on what you are trying to do here, but your while loop is on vid.FrameAcquired. Once you do
data1 = getdata(vid,1);
I think you need to increase the vid.FrameAcquired by 1. Otherwise your count never goes over 200.
Honglei Chen
2013 年 3 月 5 日
Sounds reasonable but you are really the best person to answer that as I don't know your algorithm.
カテゴリ
ヘルプ センター および File Exchange で Arduino Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!