Problems solving a trigonometric equation with 2 unknowns

조회 수: 6 (최근 30일)
Denis Emanuel Pop
Denis Emanuel Pop 2020년 11월 29일
댓글: Denis Emanuel Pop 2020년 12월 3일
Hello,
So, I have 2 trigonometric equations, the unknowns here are q2 and q3.
The 2 equations are:
Py=2*cos(q1) * ( cos(q2+q3) + 3*cos(q2) )
Pz=2*sin(q2+q3) + 6*sin(q2) + 14
First I tried on paper to get some function q3=f(q2), and that's what I ended up with:
q3=atan((Pz/2-7-3*sin(q2))/(Py/2/cos(q1)-3*cos(q2)))
Then I tried to solve only the first equation, substituting q3 with that function of q2 like this:
solve((Pz/2-7)==(sin(q2+q3)+3*sin(q2)), q2);
And the answer was: "Warning: Possibly spurious solutions."
I've also tried this, as I've seen in some post here
eqns = [(2*cos(q1)*(cos(q2+q3)+3*cos(q2))) == Py, (2*sin(q2+q3)+3*sin(q2)) == 0];
S = solve(eqns,[q2 q3])
Unsuccesfully tho
In another attempt I wanted to do in Matlab the same thing I did on paper, that is to get some q3=f(q2) and substitute it afterwards in the equation, but I ended up with complex numbers, and that's not something I wanted because q2 and q3 are angles for my robot, and Py and Pz are coordinates of the robot, so I can't get complex angles.
eqn = sin(b+c)+3*sin(b) == z/2-7;
sol = solve(eqn, b)
In this case b=q2, c=q3 and z=Pz. I tried it for the second equation and I got complex numbers too.
In my last attempt I tried a more direct approach
Result=solve(2*cos(q1)*(cos(q2+q3)+3*cos(q2)) == Py,...
2*sin(q2+q3)+6*sin(q2)+14 == Pz ,q2,q3)
But I ended up with complex numbers again and a very long solution too. By no means the result that you should get from a robot with that has the first rotation about the Z-axis and the last 2 about the Y-axis.

답변 (1개)

Raynier Suresh
Raynier Suresh 2020년 12월 1일
편집: Raynier Suresh 2020년 12월 1일
Using “solve” you can solve the equations and using simplify” command you can do algebraic simplifications of the result.
You can use the following code to solve your equation. In the result you can substitute the values for end effector (Py, Pz) and q1 to calculate q2 and q3. By substituting proper value for Py, Pz and q1 you may not get complex values.
syms q1 q2 q3 Py Pz
eqns = [Py==2*cos(q1) * (cos(q2+q3) + 3*cos(q2)), Pz==2*sin(q2+q3) +6*sin(q2) + 14]
vars = [q2 q3]
result = solve(eqns,vars)
q2 = simplify(result.q2)
q3 = simplify(result.q3)
Refer the below documentation links for more information:
  댓글 수: 3
Raynier Suresh
Raynier Suresh 2020년 12월 3일
Unnecessary white spaces in the eqns is what causing this, please replace the eqns with the below one.
eqns = [Py==2*cos(q1)*(cos(q2+q3)+3*cos(q2)), Pz==2*sin(q2+q3)+6*sin(q2)+14]
The result i got was
q2 =
2*atan(((-(132*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2)*(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))^(1/2) - 168*cos(q1)^2 + 12*Pz*cos(q1)^2)/(228*cos(q1)^2 + Pz^2*cos(q1)^2 + 12*Py*cos(q1) + Py^2 - 28*Pz*cos(q1)^2))
-2*atan((168*cos(q1)^2 + (-(132*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2)*(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))^(1/2) - 12*Pz*cos(q1)^2)/(228*cos(q1)^2 + Pz^2*cos(q1)^2 + 12*Py*cos(q1) + Py^2 - 28*Pz*cos(q1)^2))
q3 =
-2*atan((-(132*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2)*(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))^(1/2)/(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))
2*atan((-(132*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2)*(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))^(1/2)/(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))
Denis Emanuel Pop
Denis Emanuel Pop 2020년 12월 3일
It works now, thank you for your help

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by