Call slider values from within another function

I've got the following code setting up a timer object that should take a demical value from a slider (named AlphaSider) convert that into radians and pass that into another angle variable. The idea is that this is done for 4 slider variables and these angles are used to construct a serial link plot with the robotics toolbox. All relevant code (I hope) is below:
L(1)=Link ( [ 0 0 1 0 0] ) ;
L(2)=Link ( [ 0 0 1 0 0] ) ;
L(3)=Link ( [ 0 0 0.1 pi/2 0] ) ;
L(4)=Link ( [ 0 0 1 0 0] ) ;
fourlink = serialLink(L,'name', 'four link');
%declare decimal angle variables
global o
global a
global b
global g
%set initial values
o=0;
a=0;
b=0;
g=0;
function runbtn_Callback(hObject, eventdata, handles)
global t
t = timer('TimerFcn', ReadVals, 'ExecutionMode', 'FixedRate', 'BusyMode', 'Queue', 'Period', 0.5);
set(handles.statusdisp,'String', 'Running');
start(t)
function [rado,rada,radb,radg]=ReadVals(o,a,b,g, hObject, eventdata, handles)
global fourlink
o=get(handles.OmegaSlider,'Value');
set(handles.OmegaVal,'Value', o);
rado=(o*pi)/180;
a=get(handles.AlphaSlider,'Value');
set(handles.AlphaVal,'Value', o);
rada=(a*pi)/180;
% etc... for the other two then :
L(1)=Link ( [ 0 0 1 0 0] ) ;
L(2)=Link ( [ 0 0 1 0 0] ) ;
L(3)=Link ( [ 0 0 0.1 pi/2 0] ) ;
L(4)=Link ( [ 0 0 1 0 0] ) ;
fourlink = serialLink(L,'name', 'four link');
fourlink.plot([rado rada radb radd]);
function stopbtn-Callback(hObject, eventdata, handles)
global t
stop(t)
set(handles statusdisp,'String', 'Stopped');
Unfortunately when I run this it throws back "Not enough input arguements" Concerning the lines such as "o = get (handles.OmegaSlider,'Value'
When I remove these and just set o = to any number, say 90, and do so with the other 3 angles, the code runs fine and plots the serial plot with all joints at 90 degrees to each other so i know that that aspect of the code should be ok and its just obtaining the values in the first place from the slider. HELP PLEASE?
Thanks in advance

 Accepted Answer

t = timer('TimerFcn', @(hObject, eventdata) ReadVals(hObject, eventdata, gcf), 'ExecutionMode', 'FixedRate', 'BusyMode', 'Queue', 'Period', 0.5);
function ReadVals(hObject, eventdata, thisfig)
global fourlink
handles = guidata(thisfig);
Note: you cannot return values from callbacks (well, not unless they are filter functions, and those ones do not take the same inputs as other callbacks)

1 Comment

That's great thanks. Aside from this, when I plot the Serial link just using the code below:
fourlink = serialLink(L,'name', 'four link');
fourlink.plot([rado rada radb radd]);
it automatically plots in the unused axes in my GUI which is perfect, and is where I want it, but when i try to command it to plot there so that I can define another plot in another axes it does not accept it. I've tried using :
fourlink = serialLink(L,'name', 'four link');
fourlink.plot(handles.axes2, [rado rada radb radd]);
as i have used for making polar plots of my angl variables but it returns an error saying only "unknown option:" could you help me with a suitable line for plotting this to a specific axes or let me know where I'm missing some sort of parameter somewhere. Thanks

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!