Stephenson 6 bar mechanism example help me matlab codes

1 view (last 30 days)
Hi,
I did my programming, but my program is not working. Can you help? Where couldn't I find my fault and solve it.

Answers (1)

Dheeraj Kumar
Dheeraj Kumar on 6 Dec 2022
clc
clear
L4=6.5;
L5=17.5;
th4=30*pi/180;
q=[th4 165*pi/180 1.8]';
f=1;
qroots=poscrankslid21(q,L4,L5,f,th4) % the results
theta4=qroots(1)*180/pi
theta5=qroots(2)*180/pi
s6=qroots(3)
function Phi=crankslid2(q,L4,L5,f,theta2)
% constraint equations
Phi=[L4*cos(q(1))-L5*cos(q(2))-q(3);...
L4*sin(q(1))-L5*sin(q(2))- f;...
q(1)-theta2];
end
function J=gradcrankslid2(q,L4,L5)
% the Jacobian matrix
J=[-L4*sin(q(1)) L5*sin(q(2)) -1;...
L4*cos(q(1)) -L5*cos(q(2)) 0;...
1 0 0];
end
function q=poscrankslid21(q,L4,L5,f,theta2)
% Newton-Raphson algorithm
epsilon=1.e-3;
Phi=crankslid2(q,L4,L5,f,theta2);
while norm(Phi)>epsilon
J=gradcrankslid2(q,L4,L5);
dq=-inv(J)*Phi;
q=q+dq;
Phi=crankslid2(q,L4,L5,f,theta2);
norm(Phi);
end
end
Results,
4=30°
5=172.61°
S6=22.984
2=72.08°
3=28.317°
q = [2, 3, 4, 5, S6]T = [ 72.08°, 28.317°, 30°, 172.61°, 22.984]T
(Mohammadzadeh, 2007)
C) Simulation of a kinematic behavior of the system
% sewing machine kinematic analysis
clc
clear
close all
d2r=pi/180;
d=10;
L2=10;
L3=9;
L4=6.5;
L5=17.5;
e=7;
f=1;
th40=30*d2r; % crank at 30 deg %180*d2r; %
q=[72.082*d2r 28.317*d2r th40 172.61*d2r 22.984]';
omega4=0.1;
qa=75*d2r;% angle of ternary link th4 + 45 deg*d2r %;
tf=5; h=0.02; t=0:h:tf; N=length(t); % over 5 cycles
qq=zeros(N,5);
dqq=zeros(N,5);
ddqq=zeros(N,5);
h = waitbar(0,'Please wait...');
for i=1:N
theta4=th40+omega4*t(i);
q=posfourbar(q,L2,L3,L4,L5,d,e,f,qa,theta4);
qq(i,:)=q';
J=gradfourbar(q,L2,L3,L4,L5,qa);
dq=J\[0 0 omega4 0 0]';
dqq(i,:)=dq';
gam=gamfourbar(q,dq,L2,L3,L4,L5,qa);
ddq=J\gam;
ddqq(i,:)=ddq';
waitbar(i/N)
end
close(h)
save fourbar
figure(1)
clf
subplot(5,1,1)
plot(t,qq(:,1)/d2r)
ylabel('\theta_2 deg')
xlabel('\ittime s')
grid
subplot(5,1,2)
plot(t,qq(:,2)/d2r)
ylabel('\theta_3 deg')
xlabel('\ittime s')
grid
subplot(5,1,3)
plot(t,qq(:,3)/d2r)
ylabel('\theta_4 deg')
xlabel('\ittime s')
grid
subplot(5,1,4)
plot(t,qq(:,4)/d2r)
ylabel('\theta_5 deg')
xlabel('\ittime s')
grid
subplot(5,1,5)
plot(t,qq(:,5)/d2r)
ylabel('S6')
xlabel('\ittime s')
grid
figure(2)
clf
subplot(5,1,1)
plot(qq(t,dqq(:,1)/d2r))
ylabel('\omega_2 rad/s')
xlabel('\ittime s')
grid
subplot(5,1,2)
plot(qq(t,dqq(:,2)/d2r))
ylabel('\omega_3 rad/s')
xlabel('\ittime s')
grid
subplot(5,1,3)
plot(qq(t,dqq(:,3)/d2r))
ylabel('\omega_4 rad/s')
xlabel('\ittime s')
grid
subplot(5,1,4)
plot(qq(t,dqq(:,4)/d2r))
ylabel('\omega_5 rad/s')
xlabel('\ittime s')
grid
subplot(5,1,5)
plot(qq(t,dqq(:,5)/d2r))
ylabel('V6 rad/s')
xlabel('\ittime s')
grid
figure(3)
clf
subplot(5,1,1)
plot(qq(t,ddqq(:,1)))
ylabel('\epsilon_2 rad/s^2')
xlabel('\ittime s')
grid
subplot(5,1,2)
plot(qq(t,ddqq(:,2)))
ylabel('\epsilon_3 rad/s^2')
xlabel('\ittime s')
grid
subplot(5,1,3)
plot(qq(t,ddqq(:,3)))
ylabel('\epsilon_4 rad/s^2')
xlabel('\ittime s')
grid
subplot(5,1,4)
plot(qq(t,ddqq(:,4)))
ylabel('\epsilon_5 rad/s^2')
xlabel('\ittime s')
grid
subplot(5,1,5)
plot(qq(t,ddqq(:,5)))
ylabel('A6 rad/s^2')
xlabel('\ittime s')
grid
function Phi=fourbar(q,L2,L3,L4,L5,d,e,f,qa,theta4)
Phi=[L2*cos(q(1))+L3*cos(q(2))-L4*cos(qa)-d;...
L2*sin(q(1))+L3*sin(q(2))-L4*sin(qa)-e;...
L4*cos(q(3))-L5*cos(q(4))-q(5);...
L4*sin(q(3))-L5*sin(q(4))-f;...
q(4)-theta4];
end
function J=gradfourbar(q,L2,L3,L4,L5,qa)
J=[-L2*sin(q(1)) -L3*sin(q(2)) L4*sin(qa) 0 0;...
L2*cos(q(1)) L3*cos(q(2)) -L4*cos(qa) 0 0;...
0 0 -L4*sin(q(3)) L5*sin(q(4)) -1;...
0 0 L4*cos(q(3)) -L5*cos(q(4)) 0;...
0 0 1 0 0];
end
function q=posfourbar(q,L2,L3,L4,L5,d,e,f,qa,theta4)
epsilon=1.e-6;
Phi=fourbar(q,L2,L3,L4,L5,d,e,f,qa,theta4);
while norm(Phi)>epsilon
J=gradfourbar(q,L2,L3,L4,L5,qa);
dq=-inv(J)*Phi;
q=q+dq;
Phi=fourbar(q,L2,L3,L4,L5,d,e,f,qa,theta4);
end
end
function gam=gamfourbar(q,dq,L2,L3,L4,L5,qa)
gam=[L2*cos(q(1))*dq(1)^2+L3*cos(q(2))*dq(2)^2-L4*cos(qa)*d(qa^2);...
L2*sin(q(1))*dq(1)^2+L3*sin(q(2))*dq(2)^2-L4*sin(qa)*d(qa^2);...
L4*cos(q(3))*dq(3)^2-L5*cos(q(4))*dq(4)^2;...
L4*sin(q(3))*dq(3)^2-L5*sin(q(4))*dq(4)^2;...
0];
end
  2 Comments
Dheeraj Kumar
Dheeraj Kumar on 6 Dec 2022
Moved: DGM on 7 Dec 2022
this program is not working please help
DGM
DGM on 7 Dec 2022
The code you posted is unformatted and filled with special characters and non-code text. Edit your post to include a formatted copy of the code exactly as you're trying to run it. Alternatively, attach the file(s) using the paperclip icon.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!