HOW DO I CONTROL SERVO MOTOR USING EDIT TEXT GUI MATLAB
조회 수: 19 (최근 30일)
이전 댓글 표시
Hello everyone,
Was wondering if you could help, I'm a bit of a newbie so this may be a very simple question.
how do i control multiple servo motors using edit text value.
Thank you
댓글 수: 12
채택된 답변
Image Analyst
2020년 4월 21일
I'm not seeing any static text labels on your figure so I don't know what handles.text2 refers to. All I see are edit text boxes. Anyway, to get the edit text box and the slider/scrollbar to sync up when you change either, you can do this:
%=======================================================================
% --- Executes on button press in pushbutton1.
% Edit field is the master value and we send that value to the slider.
function pushbutton1_Callback(hObject, eventdata, handles)
global s1;
% Get contents of the edit box.
editBoxContents = str2num(handles.edit1.String);
% Make static text label have the integer value of the edit field.
handles.text2.String = num2str(int16(editBoxContents));
% Make the slider have the same value as the edit box.
handles.slider1.Value = number; % The value before we divided it by 180.
if handles.slider1.Value > handles.slider1.Max
handles.slider1.Max = handles.slider1.Value;
end
% Now prepare value for sending to the servo:
% Send value to servo #1.
number = editBoxContents / 180;
writePosition(s1, number);
%=======================================================================
% Change in edit field is just like pushing the button.
% Edit field is the master value and we send that value to the slider.
function edit1_Callback(hObject, eventdata, handles)
pushbutton1_Callback(hObject, eventdata, handles)
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
global s1;
% Get value from slider.
sliderValue = handles.slider1.Value;
% Send the same value to edit box #1.
handles.edit1.String = sprintf('%d', round(sliderValue));
% Send the same value to static text label #2.
handles.text2.String = handles.edit1.String;
% Now prepare value for sending to the servo:
pos1 = pos / sliderValue;
number = 1 - pos1; %For position inversion
% Send value to servo #1.
writePosition(s1, number);
% Read it back.
readPosition(s1);
Repeat for the other sets of edit fields, sliders, static text labels, and buttons.
댓글 수: 6
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!