MATLAB Project - Elbow
Project tasks
2. Script M-file
Run a script M-File to see an animated simulation of the movement of the elbow mechanism. Put the following commands into a MATLAB script M-File named simulate.m, and then run it. You will need to have your theta.m function M-File in the same directory. Watch carefully the behaviour of the angles θ(t) and φ(t) during these two cycles.
% This program simulates the mechanical ``elbow'' system
figure(1)
THETA = linspace(0,2*pi,51); % for plotting circle
for t = 0:0.02:4
x = 15*cos(pi*t);
simulate_theta = theta(t);
% find coordinates of P
Xp = 5*sin(simulate_theta); Yp = 8 + 5*cos(simulate_theta);
axis([-15 15 0 25]), axis('equal'), axis manual
hold on
plot([0 Xp],[8 Yp],'r')
plot([Xp x],[Yp 0],'b')
plot(5*cos(THETA),8 + 5*sin(THETA),'k:') % ...(*)
plot([0 0],[0 15],'k:')
text(-8.5,20,'Simulation over two cycles','fontsize',14)
hold off
if t==0
pause(2)
elseif t==4
pause(2)
else
pause(0.1)
end
clf
end
close