Hi guys,
I have a simple code here. What am I trying to achieve is to get the values of theta1 and theta2 (basically, this is an inverse kinematics). the code gives the output, the problem now is, it is just give me the first output.
Here is the coding
function[theta1_deg,theta2_deg]= inverse_two_links(x2,y2)
r2 = 0.1404;
l1 = 0.3132;
cos_theta2 = (x2^2+y2^2-l1^2-r2^2)/(2*l1*r2);
sin_theta2 = sqrt(1-cos_theta2*cos_theta2);
theta2 = atan2(sin_theta2,cos_theta2);
k1 = l1 + r2 * cos(theta2);
k2 = r2 * sin(theta2);
theta1 = atan2(y2,x2) - atan2(k2,k1);
theta2_deg = theta2 * 180 /pi;
theta1_deg = theta1 * 180 /pi;
when i execute the code for instance, x=-0.1404,y=0.3132, it just give me only 90 degree which is for theta1. Could you help me to figure out, what happened actually in my code?
Thanks in advance..

 채택된 답변

Star Strider
Star Strider 2015년 10월 16일

0 개 추천

By default, MATLAB only returns the first output of a function if only one output is requested. To get both, ask for both. Call your function as:
[theta1_deg,theta2_deg]= inverse_two_links(x2,y2);

댓글 수: 2

siti khadijah binti
siti khadijah binti 2015년 10월 16일
Oh mai!!.. thanks Star Strider.
Star Strider
Star Strider 2015년 10월 16일
My pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

질문:

2015년 10월 16일

댓글:

2015년 10월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by