Solve equilibrium equations in MATLAB for a quadruped robot

조회 수: 28 (최근 30일)
idan
idan 2025년 3월 2일
댓글: Paul 2025년 3월 29일
Hi,
I'm trying to solve a equilibrium equations for quadroped robot,
I assum having all leg's tips location, the weight and the COM location in 3D space and the forces F1 and F2 as given input.
I have writed the 6 sets of equations (linear equations) and when trying to solve it with the solver it says that the rank of A is smaller then 6 (5). I have make sure all tips are not symmetric or geometrically (to not loosing possible answers)
how can I solve this problem?
In the script there is example of values I have tried to solve with
adding the code and photo :)
% Known forces and weight
F1 = [1; 1; 1];
F2 = [2; 3; 5];
W = [1; 1; 10];
x1=50;
y1=31.65;
z1=16.09;
x2=44.68;
y2=-27.26;
z2=-24.34;
x3=-4.72;
y3=-24.4;
z3=-27.21;
x4=0;
y4=25;
z4=-21.65;
xCOM=2.53;
yCOM=1.1;
zCOM=-4.47;
% Position vectors relative to leg 2
r1 = [x1 - x2; y1 - y2; z1 - z2];
r3 = [x3 - x2; y3 - y2; z3 - z2];
r4 = [x4 - x2; y4 - y2; z4 - z2];
rCOM = [xCOM - x2; yCOM - y2; zCOM - z2];
% Unknown forces
syms F3x F3y F3z F4x F4y F4z
F3 = [F3x; F3y; F3z];
F4 = [F4x; F4y; F4z];
% Force equilibrium
eq1 = F1 + F2 + F3 + F4 + W == 0
eq1 = 
% Moment equilibrium
M1 = cross(r1, F1);
M3 = cross(r3, F3);
M4 = cross(r4, F4);
MCOM = cross(rCOM, W);
eq2 = M1 + M3 + M4 + MCOM == 0
eq2 = 
%eq2 = cross(r1, F1) + cross(r3, F3) + cross(r4, F4) + cross(rCOM, W) == 0;
[A, B] = equationsToMatrix([eq1; eq2], [F3x, F3y, F3z, F4x, F4y, F4z]);
rank_A = rank(A);
null(A)
ans = 
rank([A,B])
ans = 6
disp(A);
disp(rank_A);
5
% Solve for F3 and F4
solutions = vpasolve([eq1; eq2], [F3x, F3y, F3z, F4x, F4y, F4z]);
disp(solutions)
F3x: [0x1 sym] F3y: [0x1 sym] F3z: [0x1 sym] F4x: [0x1 sym] F4y: [0x1 sym] F4z: [0x1 sym]
  댓글 수: 2
idan
idan 2025년 3월 4일
이동: Sam Chak 2025년 3월 4일

Another option that I was thinking about is to trying to solve with some kind of assessment and check for a minimum force and moments normal (the overall error), then set the value of f3 and f4 as the value of initial starting point in fsolve.

What do you think about it?

William Rose
William Rose 2025년 3월 4일
What do you mean by "some kind of assessment"? You suggest that we "check for a minimum force and moments normal (the overall error)". What is normal to what? How is "the overall error" defined? If you give fsolve a set of inconsistent equations, it will not find a solution.
You may have a very good idea. I just don't understand it.

댓글을 달려면 로그인하십시오.

채택된 답변

idan
idan 2025년 3월 29일
Hi,
So the main mistake that I had is when I tried to set by randomize F1 inside the friction cone. the solution for this problem has 3 DOF and by setting F1 in a space which is not linear wuth the solution from this type:
So when I set another 3d vector of F1 as unkown the solution brings the coefficient C1,C2 and C3.
*The forces has inner forces that cancles each other and thats the reason I can't determinate one force in the cone of friction regardeless the this assumption
Now all I have to do is to check if for any combination of those coefficient there is a particular solution for the problem.
adding the script of the solution for those who wants to run it
clc; clear; close all;
% Known forces and weight
F2 = [4; 5; 1]; % User's input force
W = [0; 0; -10]; % Increased weight for better force balance
% Positions of leg tips and center of mass (ensuring asymmetry)
x1 = 0; y1 = 0; z1 = 0; %F1 - Unkown force
x2 = 1; y2 = 0; z2 = 0; %F2 - user's input force
x3 = 0; y3 = 1; z3 = 0; %F3 - unkown force
x4 = 0.85; y4 = 0.9; z4 = 0.15; %F4 - unkown force
xCOM = 0.2; yCOM = 0.2; zCOM = 0.5; %COM location
% Position vectors relative to leg 2 - the users input force
r1 = [x1 - x2; y1 - y2; z1 - z2];
disp("r1= ")
disp(r1)
r2 = [x2 - x2; y2 - y2; z2 - z2];
disp("r2= ")
disp(r2)
r3 = [x3 - x2; y3 - y2; z3 - z2];
disp("r3= ")
disp(r3)
r4 = [x4 - x2; y4 - y2; z4 - z2];
disp("r4= ")
disp(r4)
rCOM = [xCOM - x2; yCOM - y2; zCOM - z2];
disp("rCOM= ")
disp(rCOM)
% Define unknown forces
syms F1x F1y F1z F3x F3y F3z F4x F4y F4z
F1 = [F1x; F1y; F1z];
F3 = [F3x; F3y; F3z];
F4 = [F4x; F4y; F4z];
% Force equilibrium equation (sum of forces must be zero)
eq1 = F1(1) + F2(1) + F3(1) + F4(1) + W(1) == 0; %Fx
disp("eq1= ")
disp(eq1)
eq2 = F1(2) + F2(2) + F3(2) + F4(2) + W(2) == 0; %Fy
disp("eq2= ")
disp(eq2)
eq3 = F1(3) + F2(3) + F3(3) + F4(3) + W(3) == 0; %Fz
disp("eq3= ")
disp(eq3)
% Moment equilibrium equation (sum of moments must be zero)
M1 = cross(r1, F1);
disp("M1= ")
disp(M1)
M2 = cross(r2, F2);
disp("M2= ")
disp(M2)
M3 = cross(r3, F3);
disp("M3= ")
disp(M3)
M4 = cross(r4, F4);
disp("M4= ")
disp(M4)
MCOM = cross(rCOM, W);
disp("MCOM= ")
disp(MCOM)
eq4 = M1 + M3 + M4 + MCOM == 0;
disp("eq4= ")
disp(eq4)
% Convert equations to matrix form A * X = B
[A, B] = equationsToMatrix([eq1; eq2; eq3; eq4], [F1x, F1y, F1z, F3x, F3y, F3z, F4x,F4y, F4z]);
% Display the system matrix and RHS vector
disp('Matrix A:');
disp(A);
disp('Vector B:');
disp(B);
disp("NULLL")
disp(null(A));
NULL=null(A);
% Check the rank of A
rank_A = rank(A);
disp('rank of A:');
disp(rank_A);
% Display the system matrix and RHS vector
disp('Matrix A:');
disp(A);
disp('Vector B:');
disp(B);
% Solve the system
if rank_A == size(A, 1) % Full rank, unique solution exists
X = linsolve(A, B);
disp('Xp Solution for F3 and F4 :');
disp(X);
disp('Xh Solution for F3 and F4 :');
disp("C1* ")
disp(NULL(:,1));
disp("C2* ")
disp(NULL(:,2));
disp("C3* ")
disp(NULL(:,3));
force_norm = norm(A * X - B); % ||Ax - B|| should be small if the solution is good
moment_norm = norm(cross(r1, X(1:3)) + cross(r3, X(4:6))+ cross(r4, X(7:9))+MCOM);
disp('Norm of force residuals:');
disp(round(force_norm, 5));
disp('Norm of moment residuals:');
disp(round(moment_norm, 5));
disp("Done")
end
  댓글 수: 4
idan
idan 2025년 3월 29일

Have you edited somthing in yout answer?

Paul
Paul 2025년 3월 29일
If you're asking me, I didn't edit anything. Looks like Walter Roberson edited you comment to use code formatting for the code. When in text mode, you can enter code formatting by clicking the leftmost icon in the Code section of the ribbon, or alt-enter (at least on Windows). When in a code block, click the leftmost icon on the Text section of the ribbon to go back to text mode, or alt-enter (at least on Windows).

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

William Rose
William Rose 2025년 3월 2일
The same problem arises in a simple example: compute the weight on each wheel of an automobile. If you assume the car, including tires, is a rigid body, then the system is underdetermined, because there are three linear equations and four unknowns. In real life, the fact that the car (especially the tires) is not a rigid body solves the problem. I suspect that if you add one or more stiff, but not infinitely stiff, elements to the system, you will be able to solve it.
  댓글 수: 7
idan
idan 2025년 3월 3일

Thank you for trying any way😊 I’m sure there is a good reason for the inconsistency.

After having a good solution I want to check if F3 and F4 are inside the friction cones and then I can solve the problem😄 (and check If the random F2 is feasible)

idan
idan 2025년 3월 10일
Hi, I want to add some information that might help us.
the solution we need to solve is the complete solution of the equation:
X=Xparticular + CXhomogeneous
where:
  • xpx_pxp is the particular solution, representing one possible way the reaction forces distribute to satisfy the equilibrium.
  • xhx_hxh is the homogeneous solution, representing the null space of the force distribution matrix AAA. It consists of internal force modes that do not affect external equilibrium.
It seems that three are inner forces that applied in the system..
look at the Xh-
Homogeneous Solution xhx_hxh
  • Represents internal force distributions that do not affect the robot’s net force and moment balance.
  • These forces are often due to internal constraints like friction, tension, or redundancy in leg support.
  • Physically, this corresponds to internal stress modes, which allow for multiple valid solutions.
But when trying to solve the equations there is still the Ax=b that I can't solve because of the inconsisnt of the problem, any idea how to solve it?

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2025년 3월 2일
[eq1; eq2] only has rank 5 even though there are 6 equations. There are either no solutions to [eq1; eq2] or else there are an infinite number of solutions.
  댓글 수: 3
idan
idan 2025년 3월 2일

In addition, does this set is linear or nonlinear? Did I have made some linearization by open the cross componenets?

Walter Roberson
Walter Roberson 2025년 3월 2일
The equations posted are linear equations. I have no information about whether such a system should be linear or not.

댓글을 달려면 로그인하십시오.


idan
idan 2025년 3월 4일

Another option that I was thinking about is to trying to solve with some kind of assessment and check for a minimum force and moments normal (the overall error), then set the value of f3 and f4 as the value of initial starting point in fsolve.

What do you think about it?

  댓글 수: 6
Paul
Paul 2025년 3월 5일

Thinking about it some more … wouldn’t it be true that the resultant moment of the weight and any two contact forces must be zero around the axis that connects the other two contact points?

William Rose
William Rose 2025년 3월 6일
@Paul, the weight acts at the c.o.m. location, which is genreally not on the axis between two contact force points, so the weight is likely to create a net moment about that axis. But I agree with you about the forces at the two contact points: those forces won't create a moment about the axis between the contact points.

댓글을 달려면 로그인하십시오.


Paul
Paul 2025년 3월 8일
Problem parameters
W = [1; 1; 10];
x1=50;y1=31.65;z1=16.09;
x2=sym(44.68);y2=sym(-27.26);z2=sym(-24.34);
x3=-4.72;y3=-24.4;z3=-27.21;
x4=0;y4=25;z4=-21.65;
xCOM=2.53;yCOM=1.1;zCOM=-4.47;
% Position vectors relative to leg 2
r21 = [x1 - x2; y1 - y2; z1 - z2];
r22 = zeros(3,1);
r23 = [x3 - x2; y3 - y2; z3 - z2];
r24 = [x4 - x2; y4 - y2; z4 - z2];
r2COM = [xCOM - x2; yCOM - y2; zCOM - z2];
If the objective is to find the static equilibrium of the rigid body then the contact forces have to satisfy the force and moment balance equations. Combining all four contact forces into a single 12x1 vector we have
% A*F = b, F = [F1;F2;F3;F4]
A = [repmat(eye(3),1,4); ...
sym(vcross(r21)),sym(vcross(r22)),sym(vcross(r23)),sym(vcross(r24))];
b = [-W;-sym(vcross(r2COM))*W];
where the first three rows [A,b] are the force balance equations and the second three rows are the moment balance equations around contact point-2.
We have six equations in 12 unknowns, and the solution space is parameterized by a 12-d vector w
w = sym('w',[12,1]);
with all possible solutions given by
F = pinv(A)*b + (eye(12) - pinv(A)*A)*w; % (1)
Verify that this parametric solution satisfies the equation
A*F - b
ans = 
In the question, it is assumed that two contact forces are known a priori
F1 = sym([1; 1; 1]);
F2 = sym([2; 3; 5]);
If these forces are valid at equilibrium, we should be able to find the corresponding values of w, but solve fails to do so, which, if correct, indicates that F1 and F2 as given are not a valid pair of contact forces for which the body can be in static equilibrium.
sol = solve([eye(6),zeros(6)]*F == [F1;F2],w)
sol = struct with fields:
w1: [0x1 sym] w2: [0x1 sym] w3: [0x1 sym] w4: [0x1 sym] w5: [0x1 sym] w6: [0x1 sym] w7: [0x1 sym] w8: [0x1 sym] w9: [0x1 sym] w10: [0x1 sym] w11: [0x1 sym] w12: [0x1 sym]
If the goal is analyze the static equilirium of the body, then we have to make sure that the contact forces satisfy (1). Of course, (1) yields an infinite number of solutions for equilibrium. Not sure what kind of solution is of interest, but any additional constraint equations added to (1) to further narrow down the scope of the problem need to be linearly independent of the balancing equations.
Or perhaps one could solve for the values in w that yield the minimum norm of F, or any other desirable property of F.
Keep in mind that the mapping from w to F is not 1-1, that is different values in w can lead to the same values in F. For example, solve for F assuming a simple set of values for w
FF = subs(F,w,(1:12).');
Now assume we are given the forces in FF and solve for w. The result is different than what we started from
solw = solve(F==FF)
solw = struct with fields:
w1: -4634578167/723888464 w2: -7633332147/180972116 w3: -40458567/6134648 w4: -2401984815/55683728 w5: -13775113539/361944232 w6: 0 w7: -2238/59 w8: 0 w9: 0 w10: 0 w11: 0 w12: 0
But this solution yields the same force vector.
FF - subs(F,solw)
ans = 
function vc = vcross(v)
vc = [0 -v(3) v(2);v(3) 0 -v(1);-v(2) v(1) 0];
end
  댓글 수: 5
idan
idan 2025년 3월 15일
Hi. I still don't understand yout solution. can you please give a specific example?
Paul
Paul 2025년 3월 15일
What specifically do you not understand? Specific example of what?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by