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.
更多回答(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!