Sunday, November 21, 2004

Back to the Nerdy stuff

Hay guys I think we are really getting off track with all this sudo nerdy stuff and so I am convinced you could use a litttle something to remind us of our true nature.
The language is MatLAB

% Written by David Helbley for Kenimatics
% Assignment #16 project 3 part A

clear all
close all

d2r = pi/180;
r2d = 180/pi;

% Define the constants
% For this assignment we will choose omega = 1
w = 1;
% Define the max lift
L = 2.5;
% Define the cam base circle radius
rb = 1;
% Define the follower circle radius
rf = .2;
% Define the follower offset
c = 0;

% Define the betas that make up the cam
B1 = 90;
B2 = 65;
B3 = 45;
B4 = 15;
B5 = 145;
% Define the thetas for the diffeent betas
t = 1:1:360;
t1 = 1:1:B1;
t2 = 1:1:B2;
t3 = 1:1:B3;
t4 = 1:1:B4;
t5 = 1:1:B5;
% Now for computation sake convert to radians
% t = td*d2r;
% t1 = t1d*d2r;
% t2 = t2d*d2r;
% t3 = t3d*d2r;
% t4 = t4d*d2r;
% t5 = t5d*d2r;

% Solve for L1, L2, and L3 from the velocity functions that still have yet
% to be defined. ( It is happening now because of spacial order of
% programming.)
L1 = L/(1+B3/B1+pi*w*B2/(2*B1));
L2 = pi*L1*w*B2/(2*B1);
L3 = L1*B3/B1;
% for each of the different parts define the displacement, velocity, and
%acceleration functions.

% 0<=t<=90 (that is 0 less than or = theta less than or = 90deg)
S1 = L1*(1-cos(pi*t1/(2*B1)));
V1 = pi*L1*w/(2*B1)*sin(pi*t1/(2*B1));
A1 = pi^2*L1*w^2/(2*B1^2)*cos(pi*t1/(2*B1));

% 90<=t<=155 deg
S2 = L1 + L2/B2*t2;
for n = 1:B2
V2(n) = L2*w/B2;
A2(n) = 0;
end

% 155<=t<=200 deg
S3 = L1+L2+ L3*sin(pi*t3/(2*B3));
V3 = pi*L3*w/(2*B3)*cos(pi*t3/(2*B3));
A3 = -L3*pi^2*w^2/(4*B3^2)*sin(pi*t3/(2*B3));

% 200<=t<=215 deg
for n = 1:B4
S4(n) = L;
V4(n) = 0;
A4(n) = 0;
end

% 215<=t<=360 deg
S5 = L*(1-t5/B5+1/(2*pi)*sin(2*pi*t5/B5));
V5 = -L*w/B5*(1-cos(2*pi*t5/B5));
A5 = -2*pi*L*w^2/B5^2*sin(2*pi*t5/B5);

%Now combine the positions, velocities, and accelerations into their
%respective continous curves.
S = [S1, S2, S3, S4, S5];
V = [V1, V2, V3, V4, V5];
A = [A1, A2, A3, A4, A5];



% Calculate the pressure angle for the follower
P = atan2( V-c, ((rb+rf)^2-c^2+S).^(1/2));
Pd = P.*r2d;
% Calculate the geometry of the cam;
delta = atan2( c, ((rb+rf)^2-c^2)^(1/2));
r = (((rb+rf)*cos(delta) + S - rf.*cos(P)).^2 + ((rb+rf)*sin(delta) + rf.*sin(P)).^2).^(1/2);
gama = atan2((rb+rf)*sin(delta) + rf.*sin(P), (rb+rf)*cos(delta) + S - rf.*cos(P));
%the cam x,y data
Cx = r.*cos(t.*d2r+gama);
Cy = r.*sin(t.*d2r+gama);



% Time to plot the results!!!

% Plot the position, veloity, and acceleration of the follower
figure(1)
subplot(5,1,1);
plot(t,S)
Title('Position of the Follower','fontsize',12)
axis([0 360 -0.1 2.6])
xlabel('Cam Position (\theta)')
ylabel('Position (inches)')

subplot(5,1,3);
plot(t,V)
Title('Velocity of the Follower','fontsize',12)
axis([0 360 -0.04 0.02])
xlabel('Cam Position (\theta)')
ylabel('Velocity (inches/second)')

subplot(5,1,5);
plot(t,A)
Title('Acceleration of the Lift','fontsize',12)
axis([0 360 -0.001 0.001])
xlabel('Cam Position (\theta)')
ylabel('Acceleraion (inches/second^2')

% Plot the pressure angle and the geometry of the cam
figure(2)
subplot(2,1,1);
plot(t,Pd)
Title('Position of the Follower','fontsize',12)
axis([0 360 -1.5 1.5])
xlabel('Cam Position (\theta)')
ylabel('Position (inches)')

subplot(2,1,2);
plot(Cx,Cy)
Title('Velocity of the Follower','fontsize',12)
axis([-5 5 -5 5])
xlabel('Cam Position (\theta)')
ylabel('Velocity (inches/second)')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
everyone needs to design a cam with a little simple harmonic rise and level off and then a cycloidal fall back to the beginning....
enjoy.

2 comments:

forkev said...

very nice.
now, where is a copy of matlab for me?

dice said...

You could download and install the freeware version of Matlab called Octave. I have been experimenting with it and it is very powerful as well. It will exicute matlab code almost flawlessly... there is some syntex differences though for some of the functions like PLOT