HOW DO I CONTROL SERVO MOTOR USING EDIT TEXT GUI MATLAB
14 views (last 30 days)
Show older comments
apri zulham
on 19 Apr 2020
Commented: apri zulham
on 19 May 2020
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 Comments
Accepted Answer
Image Analyst
on 21 Apr 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!