Wednesday, April 21, 2010

Theo Jansen Mechanism Matlab Code


As promised, here is some of the Matlab code for the Theo Jansen Mechanism we posted a video of a little while back. We begin every Matlab program with the clear all command. Next are the lengths for all of the linkages.

clear all

%Link Lengths

L1=286;

L2=120;

L3=400;

L4=275;

L5=400;

L6=290;

L7=275;

L8=275;

L9=400;

L10=290;

L11=400;

L12=275;

L13=170;


 

%To get the video output:

a=1;

mov=avifile('TheoJansen.avi','COMPRESSION','None');

for theta=0:pi/20:8*pi


 

%Relating all values to theta2 of 4-bar mechanism O2ABO1

theta2=pi-theta;

ssquared=(L2)^2+(L1)^2-(2*L1*L2*cos(theta2));

s=sqrt(ssquared);

beta=asin((L2*sin(theta2))/s);

psi=acos(((L3^2)+(s^2)-(L4^2))/(2*L3*s));

lambda=acos((L4^2+s^2-L3^2)/(2*L4*s));

theta3=pi-psi+beta;

theta4=pi+beta+lambda;

theta5=lambda+beta;


 

%Finding the points relative to the motion of theta2

O1=[0,0];

O2=[-L1,0];

A=[L2*cos(theta) L2*sin(theta)];

B=[A(1)-L3*cos(psi-beta) A(2)+L3*sin(psi-beta)];


 


%Plotting the 4-bar mechanism


plot ([O1(1),A(1)],[O1(2),A(2)],'r','linewidth',3)

hold on

plot ([O2(1),O1(1)],[O2(2),O1(2)],'black','linewidth',3)

plot ([A(1),B(1)],[A(2),B(2)],'g','linewidth',3)

plot ([O2(1),B(1)],[O2(2),B(2)],'r','linewidth',3)

%Bottom triangle DEF

F=[E(1)-L12*cos(lambda+beta) E(2)-L12*sin(lambda+beta)];


 

plot([D(1),F(1)],[D(2),F(2)],'linewidth',3)

plot([E(1),F(1)],[E(2),F(2)],'linewidth',3)


 


%Link FG


G=[F(1)-L13*cos(lambda+beta) F(2)-L13*sin(lambda+beta)];


 


%Trajectory of point G


plot([F(1),G(1)],[F(2),G(2)],'linewidth',3)

Gx(a)=G(1);

Gy(a)=G(2);

plot(Gx,Gy)


 

axis([-800 400 -800 400])

hold off

a=a+1;

pause(.1)

M=getframe;

mov=addframe(mov,M);

end

mov=close(mov);


 

I left out a portion in the middle so you'll just have to figure that out by yourself!


 




Bookmark and Share

Thursday, April 8, 2010

Looking for Guest Bloggers

Are you interested in guest blogging? Do you have CAD experience or an interesting project to share? Want to get recognition and build links to your own blog or website? Leave your name and email in the comment field and I will contact you about writing an article for this blog!