Beispiel #1
0
def make_lagrange_eom(dynamic, setup, fbd):
    """Formulate the equations of motion using Lagranges's method.

    Paramters
    ---------
    The dictionaries that are returned from formulated_nchain_parameters

    Returns
    -------

    """

    # calculate the Lagrangian
    L = me.Lagrangian(setup['frames'][0], *fbd['bodies'])
    lagrange = me.LagrangesMethod(L, dynamic['q'], forcelist=fbd['fl'], frame=setup['frames'][0])

    langeqn = lagrange.form_lagranges_equations()
    mass = lagrange.mass_matrix_full
    forcing = lagrange.forcing_full

    eom = dict(L=L, lagrange=lagrange, langeqn=langeqn, mass=mass, forcing=forcing)

    return eom
Beispiel #2
0
# Create the height from the center of gravity to the datum
h = G.pos_from(O1) & N.y

# The forces at the connection point
forceP = c * (x_dot + y_dot) * L1_vector() + c * (-x_dot + y_dot) * L2_vector()

# The forces on the beta frame
forceB = c_beta * beta_dot * N.z

rod.potential_energy = (-m * g * h + 0.5 * k * (L1() - L_1_init)**2 + 0.5 * k *
                        (L2() - L_2_init)**2 + 0.5 * k_beta * beta**2)

Lag = me.Lagrangian(N, rod)

LM = me.LagrangesMethod(Lag, [x, y, beta],
                        forcelist=[(P, forceP), (B, forceB)],
                        frame=N)

EqMotion = LM.form_lagranges_equations()

lrhs = LM.rhs()
EOM = lrhs.subs({
    x: 'x',
    y: 'y',
    beta: 'b',
    x_dot: 'x_dot',
    y_dot: 'y_dot',
    beta_dot: 'beta_dot'
})
print(EOM)
Beispiel #3
0
# Create frame for rod BC
rodBCFrame = mech.ReferenceFrame('rodBCFrame')
rodBCFrame.set_ang_vel(N, -phiDot * N.z)

# Create point for the center of mass of BC
comBC_x = (L / 2) * sympy.cos(phi)
comBC_y = (L / 2) * sympy.sin(phi)
comBC_vx = phiDot * comBC_x
comBC_vy = phiDot * comBC_y

comBC = mech.Point('comBC')
comBC.set_vel(N, comBC_vx * N.x + comBC_vy * N.y)
comBC.set_pos(B, comBC_x * N.x + comBC_y * N.y)

# Create rigid body for blade BC
I_BC = mech.inertia(N, 0, 0, Izz)
rodBC = mech.RigidBody('rodBC', comBC, rodBCFrame, m, (I_BC, comBC))

# Get the kinetic energy of each component to check results
mech.kinetic_energy(N, rodBC)

# Set potential energies
rodBC.potential_energy = (1 / 2) * kT * phi**2

# Get (unforced) Lagrangian of the system
L = mech.Lagrangian(N, rodBC)

# Get equation of motion
LM = mech.LagrangesMethod(L, [rodBC], frame=N)
LM.form_lagranges_equations()
Beispiel #4
0
# Create reference frame for analysis
N = mech.ReferenceFrame( 'N' );

# Set cart position, mass, and velocity
cPoint = mech.Point( 'cPoint' );
cPoint.set_vel(N, xcDot*N.x);
C = mech.Particle('C', cPoint, 4*m );

# Set box position, mass, and velocity
# Create rotated frame
boxFrame = mech.ReferenceFrame('boxFrame');
boxFrame.orient(N, 'Body', [0, 0, -theta], 'XYZ');
bPoint = mech.Point('bPoint');
bPoint.set_vel(N, xbDot*boxFrame.x);
B = mech.Particle('B', bPoint, m );

# Get the kinetic energy of each component to check results
mech.kinetic_energy(N, C)
mech.kinetic_energy(N, B)

# Set potential energies
C.potential_energy = (1/2)*(2*k)*xc**2;
B.potential_energy = (1/2)*k*xb**2 - m*g*xb*sympy.cos(theta);

# Get (unforced) Lagrangian of the system
L = mech.Lagrangian( N, C, B );

# Get equation of motion
LM = mech.LagrangesMethod(L, [xb, xc], frame=N);
LM.form_lagranges_equations()
Beispiel #5
0
"""

import sympy as sym
# from sympy.physics.mechanics import *
import sympy.physics.mechanics as me

I0, I1, m0, m1, R, b, g, l, t = sym.symbols('I0, I1, m0, m1, R, b, g, l, t')

q0, q2 = me.dynamicsymbols('q0 q2')
q0d, q2d = me.dynamicsymbols('q0 q2', 1)  # the 1 is for the 1st derivative
T = 0.5 * (I0 + (m0 + m1) * R**2) * q0d**2 - m1 * l * R * q0d * q2d * sym.cos(
    q2) + 0.5 * (I1 + m1 * l**2) * q2d**2
V = m1 * g * l * (1 - sym.cos(q2))
L = T - V

LM = me.LagrangesMethod(L, [q0, q2])

me.mechanics_printing(pretty_print=False)
LM.form_lagranges_equations()

LM.mass_matrix
LM.forcing

print(LM.mass_matrix)
print(LM.forcing)

# with holonomic constraint
# =============================================================================
# LM = LagrangesMethod(L, [q1, q2], hol_coneqs=[q1 - q2])
# LM.form_lagranges_equations()
# # mass and force matrices augmented with constraints
Beispiel #6
0
rod1 = mech.RigidBody('rod1', B, N, m, (I1, B))

# Create rod AB
Izz = m * L**2 / 12
I2 = mech.inertia(N, 0, 0, Izz)
rod2Frame = mech.ReferenceFrame('rod2Frame')
rod2Frame.set_ang_vel(N, -thetaDot * N.z)
rod2 = mech.RigidBody('rod2', B, rod2Frame, m, (I2, B))

# Get the kinetic energy of each component tp check results
mech.kinetic_energy(N, rod1)
mech.kinetic_energy(N, rod2)

# Set potential energies
deltaz = (L / 2) * (sympy.sin(theta) - 1 / 2)
V1 = m * g * deltaz
# Rod 1
V2 = m * g * deltaz
# Rod 2
Vs = (1 / 2) * k * deltaz**2
# Spring
rod1.potential_energy = V1 + Vs
rod2.potential_energy = V2

# Get (unforced) Lagrangian of the system
L = mech.Lagrangian(N, rod1, rod2)

# Get equation of motion
LM = mech.LagrangesMethod(L, [theta], frame=N)
LM.form_lagranges_equations()
Beispiel #7
-1
    def setup(self):
        # System state variables
        q = me.dynamicsymbols('q')
        qd = me.dynamicsymbols('q', 1)

        # Other system variables
        m, k, b = symbols('m k b')

        # Set up the reference frame
        N = me.ReferenceFrame('N')

        # Set up the points and particles
        P = me.Point('P')
        P.set_vel(N, qd * N.x)

        Pa = me.Particle('Pa', P, m)

        # Define the potential energy and create the Lagrangian
        Pa.potential_energy = k * q**2 / 2.0
        L = me.Lagrangian(N, Pa)

        # Create the list of forces acting on the system
        fl = [(P, -b * qd * N.x)]

        # Create an instance of Lagranges Method
        self.l = me.LagrangesMethod(L, [q], forcelist=fl, frame=N)