Clear Filters
Clear Filters

i want to make inverse kinematics for 3 dof robot arm usnig Newton Raphson in matlap but i always get this error "(Not enough input arguments. Error in robo2 (line 2) )"

3 views (last 30 days)
function f = roots_fn_inv(t1,t2,t3,x,y,z,l1,l2,l3)
f = [l1*cos(t1)*(cos(t2+t3)+cos(t2))-x;
l2*sin(t1)*(cos(t2+t3)+cos(t2))-y;
l1*sin(t2+t3)+l1*sin(t2)+l3-z];
end
function f_dash = drev_roots_fn_inv(t1,t2,t3,l1,l2,l3)
f_dash = [-l1*sin(t1)*(cos(t2 + t3) + cos(t2)), -l1*cos(t1)*(sin(t2 + t3) + sin(t2)), -l1*cos(t1)*sin(t2 + t3);
l1*cos(t1)*(cos(t2 + t3) + cos(t2)), -l2*sin(t1)*(sin(t2 + t3) + sin(t2)), -l2*sin(t1)*sin(t2 + t3);
0, l1*cos(t2+t3)+l1*cos(t2), l1*cos(t2+t3)];
end
function param_vec = compute_inv (x, y, z, l1, l2, l3, epsilon)
t1 = pi/2; % initial guess
t2 = pi/9; % initial guess
t3 = pi/6; % initial guess
param_vec=[t1,t2,t3];
F_n = roots_fn_inv(t1, t2, t3, x, y, z, l1, l2, l3);
while norm(F_n) > epsilon
% compute F' matrix
F_n_dash = drev_roots_fn_inv(t1, t2, t3, l1, l2, l3);
% update parameters
param_vec = param_vec - F_n_dash\F_n;
t1 = param_vec(1);
t2 = param_vec(2);
t3 = param_vec(3);
F_n = roots_fn_inv(t1, t2, t3, x, y, z, l1, l2, l3);
end
param_vec = [t1, t2, t3];
x = 2;
y = 3;
z = 5;
l1 = 10;
l2 = 10;
l3 = 4.5;
epsilon = 0.01;
t = compute_inv(x, y, z, l1, l2, l3, epsilon);
f = roots_fn_inv(t(1), t(2), t(3), x, y, z, l1, l2, l3);
end

Answers (1)

Walter Roberson
Walter Roberson on 17 Dec 2023
Reorder the parts.
format long g
x = 2;
y = 3;
z = 5;
l1 = 10;
l2 = 10;
l3 = 4.5;
epsilon = 0.01;
t = compute_inv(x, y, z, l1, l2, l3, epsilon);
f = roots_fn_inv(t(1), t(2), t(3), x, y, z, l1, l2, l3);
f
f = 3×1
1.0e+00 * -0.000143758866944621 -6.58465291976107e-05 1.63199682194914e-05
function f = roots_fn_inv(t1,t2,t3,x,y,z,l1,l2,l3)
f = [l1*cos(t1)*(cos(t2+t3)+cos(t2))-x;
l2*sin(t1)*(cos(t2+t3)+cos(t2))-y;
l1*sin(t2+t3)+l1*sin(t2)+l3-z];
end
function f_dash = drev_roots_fn_inv(t1,t2,t3,l1,l2,l3)
f_dash = [-l1*sin(t1)*(cos(t2 + t3) + cos(t2)), -l1*cos(t1)*(sin(t2 + t3) + sin(t2)), -l1*cos(t1)*sin(t2 + t3);
l1*cos(t1)*(cos(t2 + t3) + cos(t2)), -l2*sin(t1)*(sin(t2 + t3) + sin(t2)), -l2*sin(t1)*sin(t2 + t3);
0, l1*cos(t2+t3)+l1*cos(t2), l1*cos(t2+t3)];
end
function param_vec = compute_inv (x, y, z, l1, l2, l3, epsilon)
t1 = pi/2; % initial guess
t2 = pi/9; % initial guess
t3 = pi/6; % initial guess
param_vec=[t1,t2,t3];
F_n = roots_fn_inv(t1, t2, t3, x, y, z, l1, l2, l3);
while norm(F_n) > epsilon
% compute F' matrix
F_n_dash = drev_roots_fn_inv(t1, t2, t3, l1, l2, l3);
% update parameters
param_vec = param_vec - F_n_dash\F_n;
t1 = param_vec(1);
t2 = param_vec(2);
t3 = param_vec(3);
F_n = roots_fn_inv(t1, t2, t3, x, y, z, l1, l2, l3);
end
param_vec = [t1, t2, t3];
end

Products

Community Treasure Hunt

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

Start Hunting!