How I can to resolve the code below?

12 visualizaciones (últimos 30 días)
Ky
Ky el 24 de En. de 2024
Respondida: Sandeep Mishra el 18 de Sept. de 2024
function [x, y, z] = Forward_Kinematics1(theta1, theta2, theta3)
syms x y z
% kinematic parameters
R = 94.52;
L1 = 170;
L2 = 319.5;
r = 65;
% Calculate sine and cosine values
c1 = cosd(theta1); s1 = sind(theta1);
c2 = cosd(theta2); s2 = sind(theta2);
c3 = cosd(theta3); s3 = sind(theta3);
% define B1'
B1 = [0; -R - L1*c1 + r; L1*s1];
% define B2'
B2 = [(-sqrt(3)/2)*(-R-L1*c2+r); (-1/2)*(-R-L1*c2+r); L1*s2];
% define B3'
B3 = [(sqrt(3)/2)*(-R-L1*c3+r); (-1/2)*(-R-L1*c3+r); L1*s3];
% Define constants
a1 = 2*(B1(1) - B2(1)); a2 = 2*(B1(1) - B3(1));
b1 = 2*(B1(2) - B2(2)); b2 = 2*(B1(2) - B3(2));
c1 = 2*(B1(3) - B2(3)); c2 = 2*(B1(3) - B3(3));
d1 = (B2(1)^2 + B2(2)^2 + B2(3)^2) - (B1(1)^2 + B1(2)^2 + B1(3)^2);
d2 = (B3(1)^2 + B3(2)^2 + B3(3)^2) - (B1(1)^2 + B1(2)^2 + B1(3)^2);
% Define coefficients for z
A = 1;
B = -2*B1(3);
C = B1(3)^2 - L2^2 + (B1(1))^2 + (B1(2))^2;
% Define equations as symbolic expressions
eq1 = a1 * x + b1 * y + c1 * z - d1;
eq2 = a2 * x + b2 * y + c2 * z + d2;
eq3 = A * z^2 + B * z + C;
  2 comentarios
Anjaneyulu Bairi
Anjaneyulu Bairi el 24 de En. de 2024
can you post the error that you are getting?
Thanks
Ky
Ky el 24 de En. de 2024
I'm calculating Forward kinematics for delta robot. Programe of me is bellow:
function [x, y, z] = Forward_Kinematics1(theta1, theta2, theta3)
syms x y z real
% kinematic parameters
R = 94.52;
L1 = 170;
L2 = 319.5;
r = 65;
% Calculate sine and cosine values
c1 = cosd(theta1); s1 = sind(theta1);
c2 = cosd(theta2); s2 = sind(theta2);
c3 = cosd(theta3); s3 = sind(theta3);
% define B1'
B1 = [0; -R - L1*c1 + r; L1*s1];
% define B2'
B2 = [(-sqrt(3)/2)*(-R-L1*c2+r); (-1/2)*(-R-L1*c2+r); L1*s2];
% define B3'
B3 = [(sqrt(3)/2)*(-R-L1*c3+r); (-1/2)*(-R-L1*c3+r); L1*s3];
% Define constants
a1 = 2*(B1(1) - B2(1)); a2 = 2*(B1(1) - B3(1));
b1 = 2*(B1(2) - B2(2)); b2 = 2*(B1(2) - B3(2));
c1 = 2*(B1(3) - B2(3)); c2 = 2*(B1(3) - B3(3));
d1 = (B2(1)^2 + B2(2)^2 + B2(3)^2) - (B1(1)^2 + B1(2)^2 + B1(3)^2);
d2 = (B3(1)^2 + B3(2)^2 + B3(3)^2) - (B1(1)^2 + B1(2)^2 + B1(3)^2);
% Define coefficients for z
A = 1;
B = -2*B1(3);
C = B1(3)^2 - L2^2 + (B1(1))^2 + (B1(2))^2;
% Define equations as symbolic expressions
eq1 = a1 * x + b1 * y + c1 * z - d1;
eq2 = a2 * x + b2 * y + c2 * z + d2;
eq3 = A * z^2 + B * z + C;
% Convert equations to functions
equations = matlabFunction([eq1; eq2; eq3], 'vars', [x; y; z]);
% Solve the system of equations
initial_guess = [0; 0; 0];
result = fsolve(equations, initial_guess);
% Extract results
x = result(1);
y = result(2);
z = result(3);
% Display results
fprintf('Nghiệm x: %.4f\n', x);
fprintf('Nghiệm y: %.4f\n', y);
fprintf('Nghiệm z: %.4f\n', z);
end
and error, when I run program is
[x, y, z] = Forward_Kinematics1(0,0,0)
Not enough input arguments.
Error in symengine>@(x,y,z)[x.*(-3.455787771261424e+2)-y.*5.9856e+2;x.*3.455787771261424e+2-y.*5.9856e+2;z.^2-6.227201960000001e+4]
Error in fsolve (line 264)
fuser = feval(funfcn{3},x,varargin{:});
Error in Forward_Kinematics1 (line 46)
result = fsolve(equations, initial_guess);
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.

Iniciar sesión para comentar.

Respuestas (1)

Sandeep Mishra
Sandeep Mishra el 18 de Sept. de 2024
Hi Ky,
I executed the code snippet in MATLAB R2022a and encountered the same error.
After investigating further, I came across a relevant MATLAB Answers post addressing a similar issue:
The root cause of the error is related to the fsolvefunction, to resolve this, you can update the code snippet by passing the inputs in the following manner:
equations = matlabFunction([eq1; eq2; eq3], 'Vars', {[x; y; z]});
Please refer to the below MathWorks documentation to learn more about ‘fsolvefunction of MATLAB:
I hope this helps.

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by