solve() fails to solve inverse kinematics with 4-DOF
2 次查看(过去 30 天)
显示 更早的评论
I would like to solve for 4 joint variables given a constant (4x4) goal pose, but solve cannot find a solution.
% main .m file
% Analytical Inverse Kinematics with Symbols in 4-DOF (Matlab)
% Define Joint Variables as Symbols
% If you don't declare them as "real", you may get imaginary numbers
syms theta1 theta2 theta3 theta4 real
% Define Goal Pose (set from Forward Kinematics)
EE = ...
zrotate(-0.528585) * ... % base
translate(0, 0, 0.670) * ...
yrotate(-0.585409) * ... % shoulder
translate(0.7, 0, 0) * ...
yrotate(1.23597) * ... % elbow
translate(0.7, 0.05, 0) * ...
xrotate(0.917576) * ... % wrist
translate(0.18, 0, 0)
% Define Joint Frames
Base = zrotate(theta1);
Shoulder = ...
translate(0, 0, 0.670) * ...
yrotate(theta2);
Elbow = ...
translate(0.7, 0, 0) * ...
yrotate(theta3);
Wrist = translate(0.7, 0.05, 0) * ...
xrotate(theta4);
Tool = translate(0.18, 0, 0);
% Define IK Equation
IK = Base * Shoulder == EE * inv(Tool) * inv(Wrist) * inv(Elbow);
% Solve a 4x4 system of nonlinear equations with 4 unknowns
solve(IK, [theta1, theta2, theta3, theta4])
% Dependency functions in separate .m files
function frame = translate(x, y, z)
frame = [
1 0 0 x;
0 1 0 y;
0 0 1 z;
0 0 0 1
];
end
function frame = xrotate(theta)
frame = [
1 0 0 0;
0 cos(theta) -sin(theta) 0;
0 sin(theta) cos(theta) 0;
0 0 0 1
];
end
function frame = yrotate(theta)
frame = [
cos(theta) 0 sin(theta) 0;
0 1 0 0;
-sin(theta) 0 cos(theta) 0;
0 0 0 1
];
end
function frame = zrotate(theta)
frame = [ ...
[cos(theta), -sin(theta), 0, 0];
[sin(theta), cos(theta), 0, 0];
[0, 0, 1, 0];
[0, 0, 0, 1]
];
end
4 个评论
John D'Errico
2024-2-27
编辑:John D'Errico
2024-2-27
You don't understand. Solve will not solve over-determined problems, unless the extra equations are simply duplicate information. An over-determined problem is one where you have more equations than unknowns. 12, versus 4, so this is over-determined.
Typically over-determined problems might be treated to minimize the errors over all, since no set of parameters will be expected to solve all 12 equations exactly. However, solve does not solve that class of problem. And, since the coefficients in those equations are generated from only approximate floating point numbers, it will be almost certain that there is no set of 4 parameters that could solve the entire set exactly.
This means your best approach will be to turn each of those 12 equations into expressions nominally equal to zero. Then use a tool like lsqnonlin, which is explicitly designed to solver over determined problems. It will return a purely numeric solution.
Torsten
2024-2-28
编辑:Torsten
2024-2-28
If you are telling me that I need to pre-analyze the matrix and choose 4 equations out of 12 then pass those in to solve instead of the entire matrix?
You can try this, but I doubt you will get an analytical solution and - if you got one - that it would satisfy the other 8 equations. Use lsqnonlin as @John D'Errico said as an attempt to generate a least-squares solution.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!