Hello Matlab community !
I am working on kinematics for a 3DOF finger. I recently made a small program which moves the finger from one spot to another.For example from spot A(x1,y1) to B(x2,y2).
The problem i have with the program is that if x1=x2 or y1=y2 I get an error which says "
"??? Error using ==> horzcatCAT arguments dimensions are not consistent.Error in ==> move at 72C=[ones(size(B))*A1,A2] "
This is the program i have made.
————————————————————
function move(X1,Y1,X2,Y2,phi)%example move(8,4,4,3,0)
%dimensions of the finger bones
l1=3.9;l2=6.2;l3=4.7;%i do that cause i don't know if i will move from A->B or B->A
GB=abs(X1-X2);AG=abs(Y1-Y2);%it is like I create a triangle ABG and i have, AG=Y=|Y1-Y2|
and GB=X=|X1-X2| B=20; %i do that cause i want to have 20 points from A->G and G->B
if X1>X2; A1=Linspace(X1,X2,B); elseif X1<X2; A1=Linspace(X1,X2,B); else A1=[ones(size(B))*X1]; end A1=A1' if Y1>Y2; A2=Linspace(Y1,Y2,B); elseif Y1<Y2; A2=Linspace(Y1,Y2,B); else A2=[ones(size(B))*Y1]; end A2=A2' %--------------------------------------------------------------------
% C= [20 points GB , 20 points AG]
C=[ones(size(B))*A1,A2]%----------------------------------------------------------------
%--------------------------kinematics-------------------------
i=1;for i=1:B Px=C((i),1); Py=C((i),2); %respectively (x,y)
phi=phi*pi/180; sigma=(Px^2+Py^2+l3^2-l1^2-l2^2-2*l3*(Px*cos(phi)+Py*sin(phi)))/2/l1/l2; Q2=atan2(+sqrt(1-sigma^2),sigma); num1=(Py-l3*sin(phi)) * (l1+l2*cos(Q2)) - (Px-l3*cos(phi))*l2*sin(Q2); den=(l1^2+l2^2+2*l1*l2*cos(Q2)); num2=(Px-l3*cos(phi))*(l1+l2*cos(Q2))+(Py-l3*sin(phi))*l2*sin(Q2); Q1=atan2(num1/den,num2/den); Q3=phi-Q1-Q2; Q1=Q1*180/pi; Q2=Q2*180/pi; Q3=Q3*180/pi; Q((i),1)=Q1; Q((i),2)=Q2; endgrid on j=1;for j=1:B, q1=Q((j),1); q2=Q((j),2); q3=Q((j),3); q1=q1*pi/180; q2=q2*pi/180; q3=q3*pi/180; x=l1*cos(q1)+l2*cos(q1+q2)+l3*cos(q1+q2+q3); y=l1*sin(q1)+l2*sin(q1+q2)+l3*sin(q1+q2+q3); f=q1+q2+q3; x1=l1*cos(q1); x2=l1*cos(q1)+l2*cos(q1+q2); y1=l1*sin(q1); y2=l1*sin(q1)+l2*sin(q1+q2); line( [0 x1 x2 x], [0 y1 y2 y], [ 0 0 0 0 ]) hold on plot(0,0,'o') plot(x1,y1,'o') plot(x2,y2,'o') plot(x,y,'o','LineWidth',30) AXIS([-3 15.13 -3 15.13]) pause(0.2)endend
Thanks a lot in advance !
Best Answer