writePosition does not work inside of a function
이전 댓글 표시
So i'm trying to make a function that i can input a number from 0 to 1 and the function turns the servo how i specify. Problem is, the servo just never turns. I don't get an error, it acknowledges the arduino and servo connections, but it just refuses to turn the servo. When i do this in a script, it works just fine. I need help, please.
function servocontrol(theta)
a=arduino();
s=servo(a,'D9');
writePosition(s,theta)
end
댓글 수: 3
Walter Roberson
2018년 3월 1일
I do not recommend creating a connection to arduino each time. I recommend creating it once and storing the connection (a) somewhere that can be accessed. http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
Yousef Gaffary
2018년 3월 1일
Walter Roberson
2018년 3월 1일
I am not aware of any reason why writePosition would not work in a function. I am, however, concerned about the possibility that there might already be a connection open to the arduino and so the arduino() call inside the function might not be able to communicate properly.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!