Sie sind auf Seite 1von 4

6/6/2018 Modeling Overhead Gantry Crane

MATLAB Examples
Examples Home  MATLAB Family  MATLAB  Mathematics

Modeling Overhead Gantry Crane By James Wiken 

Explore:
We will derive the equations of motion for an overhead gantry crane system. We simplify the gantry cane system as just a payload
Mathematical Modeling
with MATLAB Webinar

This example also uses:


Curve Fitting Toolbox
Global Optimization
Toolbox
Neural Network Toolbox
Optimization Toolbox
Parallel Computing
Where: Toolbox

r = length of pendulum Statistics and Machine


Learning Toolbox
m = mass of bob
Symbolic Math Toolbox
M = mass of the movable support
θ = angle of pendulum with respect to vertical; measure positive counterclockwise

View in: File Exchange

Euler-Lagrange equations of motion

d ∂L ∂L Related Examples
− = τk ; k = 1…n
dt ∂q
˙ ∂qk
k

where n is the DOF of the system, { q (1) ... q (n) } is a set of generalized coordinates, {
defined as the difference between the kinetic and potential energy of the n- DOF system.

Note : For system, we will choose q = {X, θ }

Setting up theta and etheta

syms theta(t)
th = theta(t) Calculate Equations for
Pendulum
th = θ t ()
Mathematics MATLAB MATLAB
Product Family
Defining normalized unit vectors for X and θ (perpendicular to tangent)

ei = [sym(1); sym(0)]

ei =
( )
1

https://www.mathworks.com/examples/matlab/community/32246-modeling-overhead-gantry-crane 1/4
6/6/2018 Modeling Overhead Gantry Crane

etheta = [cos(th);sin(th)]

etheta =
( )
( ( ))
cos θ t

sin(θ (t ))

Defining veloctites for the two masses (M and m) in order to calculate T (Kinetic Energy)

syms r X(t) Generating Swing-Free


vM = diff(X) * ei Maneuvers for Simple Gantry
Crane System
vM(t) =
  In this demo, we use optimization to

∂t  X t ()  find optimal bang-coast-bang
acceleration basis functions.
0
Acceleration function is calculated to

vm = diff(X) * ei + r * diff(theta) * etheta

vm(t) =
 
∂ ∂
 X (t ) + r cos(θ (t ))  θ (t )

∂t ∂t



 


r sin(θ (t ))  θ (t )
∂t

Defining Kinetic Energy and Potential Energy:

syms M g m
KE = simplify(1/2 * M * transpose(vM) * vM + 1/2 * m * transpose(vm) * vm)

KE(t) =
( ) 2 ( ) 2 ( ) 2
∂ ∂ ∂
M ()
 X t m  X t() mr
2
()
 θ t
∂t ∂t ∂t ∂ ∂
+ + ( ( ))
+ m r cos θ t ()
 θ t ()
 X t
2 2 2 ∂t ∂t

PE = -(m * g * r * cos(theta))

PE(t) = −g m r cos θ t ( ( ))

Calculating the Lagrangian function (T - V or KE - PE)

L = simplify(KE + PE * -1)

L(t) =
( ) 2 ( ) 2 ( ) 2
∂ ∂ ∂
M ()
 X t m  X t() mr
2
()
 θ t
∂t ∂t ∂t ∂
+ + ( ( )) + m r cos(θ (t))
+ g m r cos θ t
2 2 2 ∂t

Calculating Partial Derivatives of the Lagrangian:


To facilitate obtaining the partial derivatives of the Lagrangian, we will substitute our states

syms q1 q_1_p q2 q_2_p


L = subs(L, {X(t), diff(X), theta, diff(theta)} , [q1, q_1_p, q2, q_2_p])
https://www.mathworks.com/examples/matlab/community/32246-modeling-overhead-gantry-crane 2/4
6/6/2018 Modeling Overhead Gantry Crane
L = subs(L, {X(t), diff(X), theta, diff(theta)} , [q1, q_1_p, q2, q_2_p])

L(t) =
2 2 2 2
M q1, p m q1, p m q2, p r
+ + + g m r cos q2 ( )+mq 1, p
( )
q2, p r cos q2
2 2 2

Partial derivative of the Lagrangian with respect to q2p = θ'(t) and q2 = θ(t) and resubsitution

dLdq2p = diff(L, q_2_p)

dLdq2p(t) = m q2, p r
2
+ m q1, p cos q2 ( )r

dLdq2p = subs(dLdq2p, [q1, q_1_p, q2, q_2_p], [X(t), diff(X), theta, diff(theta)])

dLdq2p(t) =

∂ ∂
mr
2
 θ t ( ) + m cos(θ (t)) r  X t ()
∂t ∂t

dLdq2 = diff(L, q2)

dLdq2(t) = −g m r sin q2 ( )−mq 1, p


( )
q2, p r sin q2

dLdq2 = subs(dLdq2, [q1, q_1_p, q2, q_2_p], [X(t), diff(X), theta, diff(theta)])

dLdq2(t) =

∂ ∂
−m r sin θ t ( ( ))  θ t()  X t( ) − g m r sin(θ (t))
∂t ∂t

Equations of motion
The dynamics of the n -DOF system will be described by a set of n coupled second order differential equations. We convert our se
numerically.

Euler-Lagrange equation corresponding to coordinate θ

eqn2 = diff(dLdq2p, t) - dLdq2 == sym(0)

eqn2(t) =
2 2
∂ ∂
mr
2

2
 θ t( ) + m cos(θ (t)) r 2
 X t( ) + g m sin(θ (t)) r = 0
∂t ∂t

Using equation above, derive equation for θ''(t)

syms DT2;
dt2 = diff(theta,2);

eq2_T = solve(subs(eqn2, dt2, DT2), DT2)

eq2_T =
2

( ( ))
cos θ t
2
 X t ( ) + g sin(θ (t))
∂t

r

syms accel(t) y1 y2
MLoutput = subs(eq2_T, {th, diff(th), diff(X, 2)}, {y1, y2, accel(t)})

MLoutput =
https://www.mathworks.com/examples/matlab/community/32246-modeling-overhead-gantry-crane 3/4
6/6/2018 Modeling Overhead Gantry Crane
MLoutput =

( ) cos(y ) + g sin(y )
accel t 1 1

r

f = matlabFunction(MLoutput,'file','odeEqn');

Undefined function or variable 'swingeq'.

Copyright 2017 The MathWorks, Inc.

mathworks.com
© 1994-2018 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered
trademarks of their respective holders.

https://www.mathworks.com/examples/matlab/community/32246-modeling-overhead-gantry-crane 4/4