내 조이스틱 입력의 상태를 주기적으로 검사하는 matlab에서 GUI를 작성하려고합니다. 아이디어는이 입력을 받아서 서보를 제어하는 것입니다. 지금까지는 모든 일을 따로 할 수는 있지만 결코 함께 할 수는 없습니다. 바로 지금, 마이크로 컨트롤러는 시리얼 라인을보고 이것을 기반으로 서보 (0에서 180 사이)를 조정하도록 설정됩니다. 이것은 잘 작동합니다. 여기에 내가 주기적으로 MATLAB gui에서 조이스틱 입력을 캡처하는 방법
function Foo
h.fig = figure('position', [1100 30 210 60]);
h.serial = serial('COM3');
fopen(h.serial);
h.joy = vrjoystick(1);
h.timerObject = timer('TimerFcn',@JoyInput,'ExecutionMode','fixedRate',...
'Period',1.0);
h.buttonOne = uicontrol('style', 'pushbutton' ,...
'position', [10 10 100 40],...
'string' , 'Start');
set(h.buttonOne, 'callback', {@Start, h})
function h = Start(hObject, eventdata, h)
h.buttonTwo = uicontrol('style', 'pushbutton' ,...
'position', [100 10 100 40],...
'string' , 'Stop');
set(h.buttonTwo, 'callback', {@Stop, h});
set(h.buttonOne, 'enable', 'off');
start(h.timerObject);
%fprintf(h.serial,'150') This works as is
function h = Stop(hObject, eventdata, h)
delete(h.buttonTwo)
h = rmfield(h, 'buttonTwo');
set(h.buttonOne, 'enable', 'on');
stop(h.timerObject);
fclose(h.serial);
delete(h.serial);
function h=JoyInput(hObject, eventdata, h)
fprintf(h.serial,'150') %doesn't work
% a = 1 % this repetively outputs a=1 without the fprintf
내가
??? Error while evaluating TimerFcn for timer 'timer-17'
Input argument "h" is undefined.
내가 MATLAB에서 GUI를 사용하여 아주 새로운 오전이 내가 시간을 사용할 수있을 때 무엇을 의미하는지에 딱하다 말하는 오류가 발생, 지금까지 무엇을 가지고 다른 콜백 함수의 다른 곳에서 .serial. 도와 줘서 고마워!