Why cant i get the links connected, I changed alot of the code from last time, but the links just move away from each other

2 次查看(过去 30 天)
This code only relates to 1. Position Analysis
clc; close all; clear; format compact;
% length of links
r1 = 100;
r2 = 50;
r3 = 80;
r4 = 80;
l4 = 125;
eta = deg2rad(30);
% Angle theta 2
th2 = pi/3:2*pi/36:2*pi+pi/3;
n = length(th2)
% Calculations
L = sqrt(r1^2+r2^2-2*r1*r2.*cos(th2));
Sphi = (r2./L).*sin(th2);
Cphi = (r2^2-r1^2-L.^2)./(-2*r1.*L);
phi = atan2(Sphi, Cphi);
th3 = acos((r4^2-r3^2-L.^2)./(-2*r3.*L))-phi;
Cgamma = (r3^2-r4^2-L.^2)./(-2*r4.*L);
Sgamma = (r3/r4).*sin(th3+phi);
gamma = atan2(Sgamma, Cgamma);
th4 = pi-phi-gamma;
% Use this to find the 3rd join on link 4
all = th4-eta;
% Position of joints
xO2 = 0;
yO2 = 0;
yA = r2*cos(th2);
xA = r2*sin(th2);
xB = yA+r3*cos(th3);
yB = xA+r3*sin(th3);
xO4 = r1;
yO4 = 0;
xC5 = xO4+l4*cos(all);
yC5 = yO4+l4*sin(all);
% These are used to plot the length of each link in the Draw-Linkage
Ycrank = [yO2, yA(1)];
Xcrank = [xO2, xA(1)];
Ycoupler = [yA(1), yB(1)];
Xcoupler = [xA(1), xB(1)];
Yrocker = [yB(1), yO4];
Xrocker = [xB(1), xO4];
Yground = [-1.2*r2, r1+10];
Xground = [xO2, yO4];
YC4C5 = [yO4, yC5(1)];
XC4C5 = [xO4, xC5(1)];
YBC5 = [yB(1), yC5(1)];
XBC5 = [xB(1), xC5(1)];
Draw_linkage = plot(xA, yA, '--r',...
Ycrank, Xcrank, 'r', Ycoupler, Xcoupler, 'b',...
Yrocker, Xrocker, 'g', YC4C5, XC4C5, 'g',...
YBC5, XBC5, 'g', Yground, Xground, '--k', 'linewidth', 1.2);
axis([-r2-r3 2*r2+r3 -2*r2 r4]);
axis equal
for i=1:n
delete(Draw_linkage);
Ycrank = [yO2, yA(i)];
Xcrank = [xO2, xA(i)];
Ycoupler = [yA(i), yB(i)];
Xcoupler = [xA(i), xB(i)];
Yrocker = [yB(i), yO4];
Xrocker = [xB(i), xO4];
Yground = [yO2, yO4];
Xground = [-1.2*r2, r1+10];
YC4C5 = [yO4, yC5(i)];
XC4C5 = [xO4, xC5(i)];
YBC4 = [yB(i), yC5(i)];
XBC5 = [xB(i), xC5(i)];
Draw_linkage = plot(yA, xA, '--r',...
Ycrank, Xcrank, 'r', Ycoupler, Xcoupler, 'b',...
Yrocker, Xrocker, 'g', YC4C5, XC4C5, 'g',...
YBC5, XBC5, 'g', Yground, Xground, '--k', 'linewidth', 1.2);
axis([-r2-r3 2*r2+r3 -2*r2 r4]);
axis equal
F(i) = getframe;
pause(1/20);
end
movie(F, 2);

采纳的回答

Ashutosh Singh Baghel
Hi Daniel,
I understand you wish to connect the links which are moving apart. The coordinates of the end points of links connected must be same variable so that they remain connected. Please refer to the following solution.
% YBC4 = [yB(i), yC5(i)]; %% Please interchange the cariables in
% XBC5 = [xB(i), xC5(i)]; %% 'YBC4' and 'XBC5' to get desired output.
YBC5 = [yC5(i), yB(i)];
XBC5 = [xC5(i), xB(i)];

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by