You are on page 1of 12

AE 342 Modelling and analysis lab

Session 4
Simulating the motion of planar mechanisms

Krishna Kumar Mishra (SC17B024) and M Hari Eshwar GK (SC17B018)

I. Problem Introduction
A. Question 1

Figure 1. Compound pendulum Hinged at A

B. Question 2

Figure 2. Compound pendulum connected with spring in viscous medium

1 of 12

Modeling and Analysis Lab Report, IIST


Figure 3. Additional Equations for viscous medium and spring configuration

C. Question 3

Figure 4. 9 Time dependent Variable for slider crank mechanism

II. SCILAB CODES


A. Problem 1:Compound Pendulum

t=linspace (0 ,50 ,1000);


m= 0 . 1 ;
l =2;

2 of 12

Modeling and Analysis Lab Report, IIST


g=9.81;
I =1;
f u n c t i o n X dot= f ( t , X)// x =[ t h e t a ; t h e t a d o t ]
xdd = 0 ; ydd = 0 ;
X( 1 ) = l ∗ cos ( X ( 5 ) ) ;
X( 3 ) = l ∗ s i n ( X ( 5 ) ) ;
R1=m∗xdd ;
R2=m∗ydd+m∗g ;
thetadd =(R1∗X ( 3 ) −R2∗X ( 1 ) ) ;
xdd=− l ∗ thetadd ∗ s i n ( X(5)) − l ∗X ( 6 ) ˆ 2 ∗ cos ( X ( 5 ) ) ;
ydd= l ∗ thetadd ∗ cos ( X(5)) − l ∗X ( 6 ) ˆ 2 ∗ s i n ( X ( 5 ) ) ;

X dot =[X ( 2 ) ; xdd ; X ( 4 ) ; ydd ; X ( 6 ) ; thetadd ] ;


endfunction
f u n c t i o n xdot= f 1 ( t , u )
thetadd=−m∗g∗ l / I ∗ s i n ( u ( 1 ) ) ;
thetad= u ( 2 ) ;
xdot =[ t h e t a d ; thetadd ] ;
endfunction
X0=[ l ; 0 ; 0 ; 0 ; %p i / 4 ; 0 ] ;
t0 =0;
x=ode ( X0 , t0 , t , f ) ;
x0=[% p i / 4 ; 0 ]
s=ode ( x0 , t0 , t , f 1 ) ;
figure (1)
plot ( t , x ( 5 , : ) , t , s ( 1 , : ) )
legend ( ’ Theta ( c o n f i g . v a r i . ) ’ , ’ Theta ( s i n g l e ode ) ’ )
xgrid ( 1 )
x l a b e l ( ’ time ’ )
y l a b e l ( ’ Theta ( rad ) ’ )
figure (2)
plot ( t , x ( 6 , : ) , t , s ( 2 , : ) )
legend ( ’ Omega ( c o n f i g . v a r i . ) ’ , ’ Omega ( s i n g l e ode ) ’ )
xgrid ( 1 )
x l a b e l ( ’ time ’ )
y l a b e l ( ’ Omega ( rad/s ) ’ )
B. Problem 2: Compound Pendulum with spring and viscous force

// t h e t a = l i n s p a c e (0 ,2∗% pi , 1 0 0 0 ) ;
t=linspace (0 ,3 ,1000);
// t h e t a d o t = l i n s p a c e ( 0 , 5 , 1 0 0 0 ) ;
m= 1 0 ;
a =10; r =5; l0 =10;
xc = 1 0 ; yc = 1 0 ;
K= 1 ;
g=9.81;
I =1; b=5;
xdd = 0 ; ydd = 0 ;
f u n c t i o n X dot= f ( t , X)// x =[ t h e t a ; t h e t a d o t ]
// xdd = 0 ; ydd = 0 ;

xb= r ∗ cos ( X ( 5 ) ) ;
yb=r ∗ s i n ( X ( 5 ) ) ;

l = s q r t ( ( xc−xb ) ˆ 2 + ( yc−yb ) ˆ 2 ) ;

3 of 12

Modeling and Analysis Lab Report, IIST


Fs=K∗ ( l − l 0 ) ;
Fs1=Fs ∗ ( xc−xb )/ l ;
Fs2=Fs ∗ ( yc−yb )/ l ;

X( 1 ) = l ∗ cos ( X ( 5 ) ) ;
X( 3 ) = l ∗ s i n ( X ( 5 ) ) ;
R1=m∗xdd − Fs1 ;
R2=m∗ydd−Fs2 +m∗g ;

thetadd =( R1∗X ( 3 ) −R2∗X ( 1 ) −b∗X ( 6 ) )/ I ;

xdd=−a ∗ thetadd ∗ s i n ( X(5)) − a ∗X ( 6 ) ˆ 2 ∗ cos ( X ( 5 ) ) ;


ydd=a∗ thetadd ∗ cos ( X(5)) − a ∗X ( 6 ) ˆ 2 ∗ s i n ( X ( 5 ) ) ;

X dot =[X ( 2 ) ; xdd ; X ( 4 ) ; ydd ; X ( 6 ) ; thetadd ] ;

endfunction
f u n c t i o n output= f 1 ( t , s )
m= 1 0 ;
L = 1 0 ; R= 5 ; l o = 1 0 ;
xc = 1 0 ; yc = 1 0 ;
K= 1 ;
g=9.81;
I =1; b=5;

xdotdot = 0 ;
ydotdot = 0 ;
xb=R∗ cos ( s ( 1 ) ) ;
yb=R∗ s i n ( s ( 1 ) ) ;
l = s q r t ( ( xc−xb ) ˆ 2 + ( yc−yb ) ˆ 2 )
Fs=K∗ ( l −l o ) ;
F1=Fs ∗ ( ( xc−xb )/ l ) ;
F2=Fs ∗ ( ( yc−yb )/ l ) ;
R1=m∗ xdotdot −F1 ;
R2=m∗ ydotdot+m∗g−F2 ;
x=L∗ cos ( s ( 1 ) ) ;
y=L∗ s i n ( s ( 1 ) ) ;
odotdot = ( ( R1∗L∗ s i n ( s (1)) − R2∗L∗ cos ( s (1)) − b∗ s ( 2 ) ) / I ) ;
xdotdot=−L∗ odotdot ∗ s i n ( s (1)) − L ∗ ( s ( 2 ) ) ˆ 2 ∗ cos ( s ( 1 ) ) ;
ydotdot=L∗ odotdot ∗ cos ( s (1)) − L ∗ ( s ( 2 ) ) ˆ 2 ∗ s i n ( s ( 1 ) ) ;
// p l o t ( s ( 1 ) , x , ’ o ’ )
output =[ s ( 2 ) ; odotdot ] ;
endfunction
X0 = [ 1 0 ; 0 ; 0 ; 1 ; 0 ; 1 ] ;
t0 =0;
x0 = [ 0 ; 0 ]
x=ode ( X0 , t0 , t , f ) ;
y=ode ( x0 , t0 , t , f 1 ) ;
figure (1)
plot ( t , x ( 5 , : ) , t , y ( 1 , : ) )
legend ( ’ x , y , t h e t a ( c o n f i g . v a r i . ) ’ , ’ Theta ( c o n f i g . v a r i . ) ’ )
xgrid ( 1 )
x l a b e l ( ’ time ’ )
y l a b e l ( ’ Theta ( rad ) ’ )
figure (2)

4 of 12

Modeling and Analysis Lab Report, IIST


plot ( t , x ( 6 , : ) , t , y ( 2 , : ) )
legend ( ’ x , y , t h e t a ( c o n f i g . v a r i . ) ’ , ’ Theta ( c o n f i g . v a r i . ) ’ )
xgrid ( 1 )
x l a b e l ( ’ time ’ )
y l a b e l ( ’ Omega ( rad/s ) ’ )
C. Problem 3:Slider crank Mechanism
1. θ2 taken as dependent variable

global theta2 j
j =0;

function f= deriv ( t , x )
j = j +1;
//r 2 = 1 0 ; r 3 = 1 1 ; a = 0 . 0 1 ; b = 0 . 0 1 ;m2= 0 . 0 1 ;m3= 0 . 0 1 ;m4= 0 . 0 3 ; g = 9 . 8 1 ;
r 2 = 2 ; r 3 = 2 0 ; a = 0 . 1 ; b = 1 ;m2= 2 ;m3= 3 ;m4= 2 ; g = 9 . 8 1 ;
t h e t a 2 =x ( 1 ) ;
disp ( t h e t a 2/%p i ∗ 1 8 0 , ” t h e t a 2 = ” ) ;

t h e t a 3 =2∗%p i + a s i n (− r 2 ∗ s i n ( t h e t a 2 )/ r 3+b /(2∗ r 3 ) ) ;


disp ( t h e t a 3/%p i ∗ 1 8 0 , ” t h e t a 3 = ” ) ;

theta4 =0;
i f t h e t a 3 <=%p i /180∗270 then
abort ;
end

t h e t a 2 d o t =x ( 2 ) ;
t h e t a 3 d o t=− r 2 ∗ cos ( t h e t a 2 ) ∗ x ( 2 ) / ( r 3 ∗ cos ( t h e t a 3 ) ) ;

xg2=r 2 ∗ cos ( t h e t a 2 ) ;
yg2=r 2 ∗ s i n ( t h e t a 2 ) ;
xg3 =2∗ r 2 ∗ cos ( t h e t a 2 )+ r 3 ∗ cos ( t h e t a 3 ) ;
yg3=2∗ r 2 ∗ s i n ( t h e t a 2 )+ r 3 ∗ s i n ( t h e t a 3 ) ;
xg4 =2∗ r 2 ∗ cos ( t h e t a 2 )+2∗ r 3 ∗ cos ( t h e t a 3 )+ a ;
yg4=b ;

xA= 0 ; yA= 0 ;
xB=xg2+r 2 ∗ cos ( t h e t a 2 ) ; yB=yg2+r 2 ∗ s i n ( t h e t a 2 ) ;
xC=xg4−a ; yC=b ; // p o s i t i o n s o f j o i n t s (A, B , C) o f l i n k s

c=cos ( t h e t a 2 ) ; s= s i n ( t h e t a 2 ) ; c3=cos ( t h e t a 3 ) ; s3= s i n ( t h e t a 3 ) ;

A=[0 1 0 1 0 0 0 0 −m2∗ r 2 ∗ c 0 ;
1 0 1 0 0 0 0 0 +m2∗ r 2 ∗ s 0 ;
r 2 ∗ s − r 2 ∗ c − r 2 ∗ s r 2 ∗ c 0 0 0 0 −m2∗ r 2 ˆ2/3 0 ;
0 0 0 −1 0 1 0 0 −2∗m3∗ r 2 ∗ c −m3∗ r 3 ∗ c3 ;
0 0 −1 0 1 0 0 0 2∗m3∗ r 2 ∗ s m3∗ r 3 ∗ s3 ;
0 0 − r 3 ∗ s3 r 3 ∗ c3 − r 3 ∗ s3 r 3 ∗ c3 0 0 0 −m3∗ r 3 ˆ 2 / 3 ;
0 0 0 0 0 −1 +1 0 0 0 ;
0 0 0 0 −1 0 0 0 2∗m4∗ r 2 ∗ s 2∗m4∗ r 3 ∗ s3 ;
0 0 0 0 0 a 0 1 0 0;
0 0 0 0 0 0 0 0 r 2 ∗ c r 3 ∗ c3 ] ;

B=[−m2∗ r 2 ∗ s ∗ t h e t a 2 d o t ˆ2+m2∗g ;

5 of 12

Modeling and Analysis Lab Report, IIST


−m2∗ r 2 ∗ c ∗ t h e t a 2 d o t ˆ 2 ;
0;
−2∗m3∗ r 2 ∗ s ∗ t h e t a 2 d o t ˆ2 −m3∗ r 3 ∗ s3 ∗ t h e t a 3 d o t ˆ2+m3∗g ;
−2∗m3∗ r 2 ∗ c ∗ t h e t a 2 d o t ˆ2 −m3∗ r 3 ∗ c3 ∗ t h e t a 3 d o t ˆ 2 ;
0;
m4∗g ;
−2∗m4∗ r 2 ∗ c ∗ t h e t a 2 d o t ˆ2 − 2∗m4∗ r 3 ∗ c3 ∗ t h e t a 3 d o t ˆ 2 ;
0;
r 2 ∗ s ∗ t h e t a 2 d o t ˆ2+ r 3 ∗ s3 ∗ t h e t a 3 d o t ˆ 2 ] ;
z=A\B ;

f =[ x ( 2 ) ; z ( 9 , 1 ) ] ;
endfunction

t0 =0;
t =[0:0.1:15];
Xo=[0∗% p i / 1 8 0 ; 2 ] ; / / t h e t a 2 and t h e t a 2 d o t being t h e two v a r i a b l e s :
U=ode ( Xo , t0 , t , d e r i v ) ;

scf ( 5 ) ;
p l o t ( t ,U( 1 , : ) , ’ c ’ , t ,U( 2 , : ) , ’ k ’ ) ;
x l a b e l ( ” Time ” ) ;
y l a b e l ( ” Deg or Rad/s ” )
legend ( ” Theta ( 2 ) ( i n deg ) ” , ” omega ( 2 ) ( rad/s ) ” ) ;
t i t l e ( ” S i m u l a t i o n o f a S l i d e r Crank Mechanism ” ) ;
2. All Nine parameter are taken as dependent Variable

l2 =5;
l3 =10;
r 2= l 2 / 2 ;
r 3= l 3 / 2 ;
a =1;
b=0;
m2= 2 ;
m3= 2 ;
m4= 2 ;
g=9.81;
r 2=l2/sqrt ( 2 ) ; // r a d i u s o f g y r a t i o n
r 3=l3/sqrt ( 2 ) ; //
I 2 =m2∗ l 2 ˆ 2 / 1 2 ; //moment o f i n e r t i a o f l i n k AB
I 3 =m3∗ l 3 ˆ 2 / 1 2 ; // moment o f i n e r t i a o f l i n k BC
function s l i d e c r n k =deriv ( t , s )

a2=s ( 1 ) ;
da2=s ( 2 ) ;
a3=s ( 3 ) ;
da3=s ( 4 ) ;
// c r e a t i n g matrix 15 x15 matrix
A=[1 0 r 2 ∗ s i n ( s ( 1 ) ) 0 0 0 0 0 0 0 0 0 0 0 0;
0 1 − r 2 ∗ cos ( s ( 1 ) ) 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 l 2 ∗ cos ( s ( 1 ) ) 0 0 l 3 ∗ cos ( s ( 3 ) ) 0 0 0 0 0 0 0 0 0;
0 0 l 2 ∗ sin ( s ( 1 ) ) 1 0 r3 ∗ sin ( s ( 3 ) ) 0 0 0 0 0 0 0 0 0;
0 0 − l 2 ∗ cos ( s ( 1 ) ) 0 1 − r 3 ∗ s i n ( s ( 3 ) ) 0 0 0 0 0 0 0 0 0;
0 0 l2 ∗ sin ( s ( 1 ) ) 0 0 l3 ∗ sin ( s ( 3 ) ) 1 0 0 0 0 0 0 0 0;

6 of 12

Modeling and Analysis Lab Report, IIST


m2 0 0 0 0 0 0 −1 0 −1 0 0 0 0 0 ;
0 m2 0 0 0 0 0 0 −1 0 −1 0 0 0 0 ;
0 0 I 2 0 0 0 0 − r 2 ∗ s i n ( s ( 1 ) ) r 2 ∗ cos ( s ( 1 ) ) ( l 2 −r 2 ) ∗ s i n ( s ( 1 ) ) −( l 2 −r 2 ) ∗ cos ( s ( 1 ) ) 0 0 0 0 ;
0 0 0 m3 0 0 0 0 0 1 0 −1 0 0 0 ;
0 0 0 0 m3 0 0 0 0 0 1 0 −1 0 0 ;
0 0 0 0 0 I 3 0 0 0 r 3 ∗ s i n ( s ( 3 ) ) − r 3 ∗ cos ( s ( 3 ) ) −( l 2 ∗ s i n ( s ( 1 ) ) + r 3 ∗ s i n ( s (3)) − b ) −( l 3 −r 3 ) ∗ c
0 0 0 0 0 0 m4 0 0 0 0 1 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 −1 1 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 a 0 1];
B=[− r 2 ∗ s ( 2 ) ˆ 2 ∗ cos ( s ( 1 ) ) − r 2 ∗ s ( 2 ) ˆ 2 ∗ s i n ( s ( 1 ) ) l 2 ∗ s i n ( s ( 1 ) ) ∗ s ( 2 ) ˆ 2 + l 3 ∗ s i n ( s ( 3 ) ) ∗ s ( 4 ) ˆ 2 − l
Y=A\B ;
s l i d e c r n k =[ s ( 2 ) , Y ( 3 ) , s ( 4 ) , Y ( 6 ) , s ( 6 ) , Y ( 1 ) , s ( 8 ) , Y ( 4 ) , s ( 1 0 ) , Y ( 7 ) , s ( 1 2 ) , Y ( 2 ) , s ( 1 4 ) , Y ( 5 ) ] ’ ;
endfunction
// v e l o c i t y and a c c e l e r a t i i o n e q u a t i o n
a2 0 =0;
a 3 0 = a s i n ( ( b− l 2 ∗ s i n ( a 2 0 ) ) / l 3 )
x 2 0 =r 2 ∗ cos ( a 2 0 ) ;
y2 0=r 2 ∗ s i n ( a 2 0 ) ;
da2 0 = 5 ;
da3 0=−( l 2 / l 3 ) ∗ cos ( a 2 0 ) ∗ da2 0 ;
dx2 0=− r 2 ∗ s i n ( a 2 0 ) ∗ da2 0 ;
dy2 0=r 2 ∗ cos ( a 2 0 ) ∗ da2 0 ;
x 3 0 = l 2 ∗ cos ( a 2 0 )+ r 3 ∗ cos ( a 3 0 ) ;
dx3 0=− l 2 ∗ s i n ( a 2 0 ) ∗ da2 0 −r 3 ∗ s i n ( a 3 0 ) ∗ da3 0 ;
y3 0= l 2 ∗ s i n ( a 2 0 )+ r 3 ∗ s i n ( a 3 0 ) ;
dy3 0= l 2 ∗ cos ( a 2 0 ) ∗ da2 0+r 3 ∗ cos ( a 3 0 ) ∗ da3 0 ;
x 4 0 = l 2 ∗ cos ( a 2 0 )+ l 3 ∗ cos ( a 3 0 )+ a ;
dx4 0=− l 2 ∗ s i n ( a 2 0 ) ∗ da2 0 − l 3 ∗ s i n ( a 3 0 ) ∗ da3 0 ;

t =[0:0.01:9] ’;
x i n =[ a2 0 , da2 0 , a3 0 , da3 0 , x2 0 , dx2 0 , x3 0 , dx3 0 , x4 0 , dx4 0 , y2 0 , dy2 0 , y3 0 , dy3 0 ] ’ ;
// f ( 0 , x i n )
x=ode ( x i n , 0 , t , 0 . 0 0 0 1 , 0 . 0 0 0 1 , d e r i v ) ;

flag =0; c t r =0;


A2 ( 1 ) = a 2 0 ;
A3 ( 1 ) = a 3 0 ;
Y3 ( 1 ) = y3 0 ;
for i =2: length ( t )
i f ( A2 ( i − 1))>2∗% p i then
flag=flag +1;
A2 ( i − 1)=x ( 1 , i −1)− f l a g ∗2∗% p i
end
A2 ( i )= x ( 1 , i )− f l a g ∗2∗% p i ;

i f ( A3 ( i − 1))>2∗% p i then
c t r = c t r +1;
end
A3 ( i )= x ( 3 , i )− c t r ∗2∗% p i ;
Y3 ( i )= l 2 ∗ s i n ( A2 ( i ) ) + r 3 ∗ s i n ( A3 ( i ) ) ;
end
// p l o t t i n g t h e r e q u i r e d graphs

figure (1)
p l o t ( t , A2 , t , x ( 5 , : ) , t , x ( 1 1 , : ) , t , x ( 2 , : ) , ’ LineWidth ’ , 4 )

7 of 12

Modeling and Analysis Lab Report, IIST


x l a b e l ( ’ Time ’ )
y l a b e l ( ’ Deg or rad/s or m’ )
legend ( ’ Theta ( 2 ) ( i n deg ) ’ , ’ XG2 ’ , ’ YG2 ’ , ’ Omega ( 2 ) ( rad/s ) ’ )
xgrid ( 1 ) ;

figure (2)
p l o t ( t , A3 , t , x ( 7 , : ) , t , Y3 , t , x ( 4 , : ) , ’ LineWidth ’ , 4 )
x l a b e l ( ’ Time ’ )
y l a b e l ( ’ Deg or rad/s or m’ )
legend ( ’ Theta ( 3 ) ( i n deg ) ’ , ’ XG3 ’ , ’ YG3 ’ , ’ Omega ( 3 ) ( rad/s ) ’ )
xgrid ( 1 ) ;

figure (3)
p l o t ( t , x ( 9 , : ) , ’ LineWidth ’ , 4 )
x l a b e l ( ’ time ’ )
y l a b e l ( ’ i n m’ )
legend ( ’ XG4 ’ )
xgrid ( 1 ) ;
III. Graph and Analysis
A. Problem 1 Graphs
Following Graphs shows Variation of angle and angular velocity for x,y,θ and θ alone as configuration
variable.

Figure 5. Angle Variation with time for compound pendulum

8 of 12

Modeling and Analysis Lab Report, IIST


Figure 6. Angular speed Variation with time for compound pendulum

B. Problem 2 Graphs
Following Graphs shows Variation of angle and angular velocity for x,y,θ and θ alone as configuration vari-
able under the viscous medium condition.

Figure 7. Angle Variation with time for compound pendulum

9 of 12

Modeling and Analysis Lab Report, IIST


Figure 8. Angular speed Variation with time for compound pendulum

C. Problem 3 Graphs
Following graphs shows the variation of time dependent variable which are not constant:

Figure 9. Plots for Link 2(crank rod)

10 of 12

Modeling and Analysis Lab Report, IIST


Figure 10. Plots for Link 3(connecting rod)

Figure 11. Plots for Link 4(slider Box)

The Graph below is for θ2 as dependent Variable for slider crank mechanism analysis

11 of 12

Modeling and Analysis Lab Report, IIST


Figure 12. Plots for Link 4(slider Box)

D. Analysis
Compound pendulum(Problem 1)gives us an idea of how close the analytical and experimental iterations
can get. As can be seen, the question at hand was simple and hence analytically easier but when it comes to
problems like problem 2 where the spring and the viscous term induces some difficulty, scilab iterations be-
come more rigorous. Figure(7)justifies the analytical reasoning that the compound pendulum is following
a sinusoidal variation and damped after a certain time to viscous effect of the medium. Problem 2 intro-
duces the spring and the viscous term thus, incorporating some resistance to the motion. By changing the
configuration variable change taking same boundary condition depicts the same nature of graphs but there
is some change in time in time period of motion as well as amplitude.
For Problem 3 all the unknowns as the state variables was found to give expected variation. Almost all
of the graphs pertaining to various different parameters have been plotted and agree with the differential
calculus in the fact that the differentiation of one term is leading to the other.

IV. Conclusion
The analysis was performed successfully using scilab and latex on an online platform(overleaf) to find
the efficiency of iterative methods of scilab in different ways and get a hold of how parameters changed the
variations in different cases.

12 of 12

Modeling and Analysis Lab Report, IIST

You might also like