Can you help and show if any where ive gone wrong with any codes

3 Ansichten (letzte 30 Tage)
Daniel Martelli
Daniel Martelli am 13 Sep. 2021
Kommentiert: Tanmay Das am 30 Dez. 2021
This code is only for Position Analysis
clc; close all; clear; format compact;
% length of links
r1 = 100;
r2 = 50;
r3 = 780;
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;
xA = r2*cos(th2);
yA = r2*sin(th2);
xB = xA+r3*cos(th3);
yB = yA+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
Xcrank = [xO2, xA(1)];
Ycrank = [yO2, yA(1)];
Xcoupler = [xA(1), xB(1)];
Ycoupler = [yA(1), yB(1)];
Xrocker = [xB(1), xO4];
Yrocker = [yB(1), yO4];
Xground = [-1.2*r2, r1+10];
Yground = [yO2, yO4];
XC4C5 = [xO4, xC5(1)];
YC4C5 = [yO4, yC5(1)];
XBC5 = [xB(1), xC5(1)];
YBC5 = [yB(1), yC5(1)];
Draw_linkage = plot(xA, yA, '--r',...
Xcrank, Ycrank, 'r', Xcoupler, Ycoupler, 'b',...
Xrocker, Yrocker, 'g', XC4C5, YC4C5, 'g',...
XBC5, YBC5, 'g', Xground, Yground, '--k', 'linewidth', 1.2);
axis([-r2-r3 2*r2+r3 -2*r2 r4]);
axis equal
for i=1:n
delete(Draw_linkage);
Xcrank = [xO2, xA(i)];
Ycrank = [yO2, yA(i)];
Xcoupler = [xA(i), xB(i)];
Ycoupler = [yA(i), yB(i)];
Xrocker = [xB(i), xO4];
Yrocker = [yB(i), yO4];
Xground = [-1.2*r2, r1+10];
Yground = [yO2, yO4];
XC4C5 = [xO4, xC5(i)];
YC4C5 = [yO4, yC5(i)];
XBC5 = [xB(i), xC5(i)];
YBC4 = [yB(i), yC5(i)];
Draw_linkage = plot(xA, yA, '--r',...
Xcrank, Ycrank, 'r', Xcoupler, Ycoupler, 'b',...
Xrocker, Yrocker, 'g', XC4C5, YC4C5, 'g',...
XBC5, YBC5, 'g', Xground, Yground, '--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);

Antworten (1)

Tanmay Das
Tanmay Das am 19 Sep. 2021
Hi,
atan2(Y,X) returns the four-quadrant inverse tangent (tan-1) of Y and X, which must be real. In the given code, Sgamma is a vector of complex quantities. So it generates an error that "Inputs must be real".
  2 Kommentare
Daniel Martelli
Daniel Martelli am 19 Sep. 2021
Im not really undestanding what you are trying to say
Tanmay Das
Tanmay Das am 30 Dez. 2021
In your code, you have written these lines:
Sgamma = (r3/r4).*sin(th3+phi);
gamma = atan2(Sgamma, Cgamma);
where Sgamma comes out to be a complex quantity. (You may try printing the value of Sgamma in command window)
However, 'atan2' function only takes real input arguments. So, it gnerated the error that "Inputs must be real"

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by