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

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
Thank you for the reply my follow up question is, even if i do create the connection every time, how come the servo still won't rotate? Even if i store the connection, i feel like the result will be the same. Is there a reason why writePosition does not work in a function?
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에 대해 자세히 알아보기

질문:

2018년 3월 1일

댓글:

2018년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by