我在一个图中有多个滑块,当其中一个发生变化时,我想发布它们的值(使用机器人工具箱)。我无法访问多个滑块的值 - 尝试访问滑块值会导致sliderMoving
函数出现以下错误:
Undefined variable "event1" or class "event1.Value".
代码如下:
function sliderchanging
%rosinit('129.78.214.177');
first_val = 0;
euler_v = rossubscriber('/Euler_values');
slider_v = rospublisher('/Slider_values', 'std_msgs/Float64MultiArray');
slidermsg = rosmessage(slider_v);
eulermsg = rostopic('echo', '/Euler_values');
ypr = eulermsg.Data;
y = ypr(1);
p = ypr(2);
r = ypr(3);
fig = uifigure;
sld = uislider(fig,'Position',[20 50 260 20],'ValueChangingFcn',@(sld,event) sliderMoving(event, slidermsg, slider_v, y, p, r));
sld1 = uislider(fig,'Position',[20 80 260 20],'ValueChangingFcn',@(sld1,event1) sliderMoving(event1, slidermsg, slider_v, y, p, r));
if first_val == 0
send(slider_v, eulermsg);
end
sld.Limits = [y-2 y+2];
sld.Value = y;
sld.Position = [20 50 260 20];
sld1.Limits = [p-2 p+2];
sld1.Value = p;
sld1.Position = [20 80 260 20];
end
function sliderMoving(event, slidermsg, slider_v, y, p, r)
first_val = 1;
disp(event.Value)
disp(event1.Value)
slidermsg.Data = [event.Value, p, r];
send(slider_v, slidermsg)
end
这段代码有什么问题?如何从sliderMoving
回调中访问所有可用滑块的值?