# Demo entry 6349917

1

Submitted by g on Mar 02, 2017 at 04:55
Language: Matlab. Code size: 2.0 kB.

```function [ out ] = theta_skeleton_v16(theta_in_rad, fbg)
%THETA Summary of this function:
% This function calculates the output angles of a fourbar mechanism
% based on the input crank angles and the 4 Bar mechanism geometry

%   Detailed explanation goes here
%  The inputs to the function are the input angle array Theta2 (in radians please)
%  and the fbg (four bar geometry) array of 4 lengths of the 4 bar mechanism.

% theta_skeleton_v16 By: Dr. Joel Huegel for Mechanisms 2016a

a=fbg(1,1); b=fbg(1,2); c=fbg(1,3);d=fbg(1,4); %where a,b,c,d are the 4 link lengths
t2 = theta_in_rad;  %this should come in as an array of theta2 values
cos_t2 = cos(t2);  %precalculate sine and cosine for all angles of t2
sin_t2 = sin(t2);

%Compute the outputs for theta1, theta3, and theta4. (careful with the two solutions)
% These are the lines of code you need to change per the equations in the
% book page 167, 168 (4th Ed.) or pp. 129-131 (5th Ed)
% substitute the code here for the missing variable formulas ------------------

K1 = d / a; %fix line per textbook
K2 = d / c; %fix line per textbook
K3 = (a^2 - b^2 + c^2 + d^2)/(2 * a * c); %fix line per textbook
K4 = d / b; %fix line per textbook
K5 = (c^2 - d^2 - a^2 - b^2)/(2 * a * b);%fix line per textbook

A = cos_t2 - K1 - K2 * cos_t2 + K3; %this line is right
B = - 2 * sin_t2; %fix line per textbook
C = K1 - (K2 + 1) * cos_t2 +K3;  %this line is right
D = cos_t2 - K1 + K4 * cos_t2 + K5; %fix line per textbook
E = - 2 * sin_t2; %fix line per textbook
F = K1 + (K4 - 1) * cos_t2 + K5; %fix line per textbook

out(2,:) = theta_in_rad;  %this line is right
out(3,:) = 2.* atan(( -E - sqrt( E.^2 - 4.*D.*F))./(2.*D)); %this line is right
out(4,:) = 2.* atan(( -B - sqrt( B.^2 - 4.*A.*C))./(2.*A)); %this line is right
out(1,:) = 0; %this line is right

%for solution 2 you would add these lines of code:
%out(5,:) = 2.* atan(( -E - sqrt( E.^2 - 4.*D.*F))./2.*D);
%out(6,:) = 2.* atan(( -B - sqrt( B.^2 - 4.*A.*C))./2.*A);

end
```

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.