Filter löschen
Filter löschen

Appdesigner error: Index exceeds the number of array elements (2). Error in Robotprac/​Joint3Slid​erValueCha​nged (line 93)

1 Ansicht (letzte 30 Tage)
I am creating a four link robot. Here, I call the objective function to operate the robot, but receive an error in the 3rd line of my for-loop and don't know why.
function Joint3SliderValueChanged(app, event)
%get the values of the sliders from each joint
app.jointangles(4) = app.Joint3Slider.Value;
%plot the robot
fid = fopen('dhobjective.m','w');
%Arbitrary Parameters
d0 = 10.3;
d1 = 9.2;
a2 = 0;
d3 = 2;
%create parameter array
para = [d0,d1,a2,d3];
%create a simple four link robot.
L(1) = Link([0 0 10.3 0]);
L(1).qlim = [-90 90];
L(2) = Link([0 0 9.2 0]);
L(2).qlim = [-90 90];
L(3) = Link([0 0 0 -pi/2]);
L(3).qlim = [-90 90];
%L(4) is the end effector where the pen attaches
L(4) = Link([0 2 0 0]);
L(4).qlim = [-90 90];
%Build this robot
robo = SerialLink(L,'name', 'robo');
count = 0;
%Create random set of numbers to generate 5 data points
R = rand(5,4);
q = [0 0 0 0];
for i = 1:5
%for each iteration, set joint angles randomly
l = L(1).qlim; q(1) = l(1) + diff(L(1).qlim)*R(i,1);
l = L(2).qlim; q(2) = l(2) + diff(L(2).qlim)*R(i,2);
l = L(3).qlim; q(3) = l(3) + diff(L(3).qlim)*R(i,3); %%Error: Index exceeds the number of array elements (2).
l = L(4).qlim; q(4) = l(4) + diff(L(4).qlim)*R(i,4);
T = fkine(robo, q);
q
pos = [T(1,4), T(2,4), T(3,4)]
fprintf(fid, '%f %f %f %f %f\n', q(1), q(2), q(3), q(4))
end
fclose(fid);
para = [d0, d1, a2, d3];
%find original parameters based on optimization
disp('original parameters: ')
para
%Disturb the parameters
para(0) = 4;
para(1) = 5;
para(2) = 6;
para(3) = 7;
disp('disturbed parameters')
para
fminsearch('dhobjective', para)
app.rob.plot (app.jointangles);

Antworten (1)

Dave B
Dave B am 14 Nov. 2021
Bearbeitet: Dave B am 14 Nov. 2021
Above, you set
L(3).qlim = [-90 90];
On the line that errors:
l = L(3).qlim; % so l is [-90 90]
q(3) = l(3) + ... % This says to take the third element of l, but l only has two elements
%Pro tip: if you name your variables "l" or "I" you're asking for trouble

Kategorien

Mehr zu Robotics finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by