def test_pendulum_angular_momentum(): """Consider a pendulum of length OA = 2a, of mass m as a rigid body of center of mass G (OG = a) which turn around (O,z). The angle between the reference frame R and the rod is q. The inertia of the body is I = (G,0,ma^2/3,ma^2/3). """ m, a = symbols('m, a') q = dynamicsymbols('q') R = ReferenceFrame('R') R1 = R.orientnew('R1', 'Axis', [q, R.z]) R1.set_ang_vel(R, q.diff() * R.z) I = inertia(R1, 0, m * a**2 / 3, m * a**2 / 3) O = Point('O') A = O.locatenew('A', 2*a * R1.x) G = O.locatenew('G', a * R1.x) S = RigidBody('S', G, R1, m, (I, G)) O.set_vel(R, 0) A.v2pt_theory(O, R, R1) G.v2pt_theory(O, R, R1) assert (4 * m * a**2 / 3 * q.diff() * R.z - S.angular_momentum(O, R).express(R)) == 0
def test_pendulum_angular_momentum(): """Consider a pendulum of length OA = 2a, of mass m as a rigid body of center of mass G (OG = a) which turn around (O,z). The angle between the reference frame R and the rod is q. The inertia of the body is I = (G,0,ma^2/3,ma^2/3). """ m, a = symbols('m, a') q = dynamicsymbols('q') R = ReferenceFrame('R') R1 = R.orientnew('R1', 'Axis', [q, R.z]) R1.set_ang_vel(R, q.diff() * R.z) I = inertia(R1, 0, m * a**2 / 3, m * a**2 / 3) O = Point('O') A = O.locatenew('A', 2*a * R1.x) G = O.locatenew('G', a * R1.x) S = RigidBody('S', G, R1, m, (I, G)) O.set_vel(R, 0) A.v2pt_theory(O, R, R1) G.v2pt_theory(O, R, R1) assert (4 * m * a**2 / 3 * q.diff() * R.z - S.angular_momentum(O, R).express(R)) == 0
def test_rigidbody2(): M, v, r, omega, g, h = dynamicsymbols('M v r omega g h') N = ReferenceFrame('N') b = ReferenceFrame('b') b.set_ang_vel(N, omega * b.x) P = Point('P') I = outer(b.x, b.x) Inertia_tuple = (I, P) B = RigidBody('B', P, b, M, Inertia_tuple) P.set_vel(N, v * b.x) assert B.angular_momentum(P, N) == omega * b.x O = Point('O') O.set_vel(N, v * b.x) P.set_pos(O, r * b.y) assert B.angular_momentum(O, N) == omega * b.x - M*v*r*b.z B.potential_energy = M * g * h assert B.potential_energy == M * g * h assert expand(2 * B.kinetic_energy(N)) == omega**2 + M * v**2
def test_rigidbody2(): M, v, r, omega, g, h = dynamicsymbols('M v r omega g h') N = ReferenceFrame('N') b = ReferenceFrame('b') b.set_ang_vel(N, omega * b.x) P = Point('P') I = outer(b.x, b.x) Inertia_tuple = (I, P) B = RigidBody('B', P, b, M, Inertia_tuple) P.set_vel(N, v * b.x) assert B.angular_momentum(P, N) == omega * b.x O = Point('O') O.set_vel(N, v * b.x) P.set_pos(O, r * b.y) assert B.angular_momentum(O, N) == omega * b.x - M*v*r*b.z B.set_potential_energy(M * g * h) assert B.potential_energy == M * g * h assert B.kinetic_energy(N) == (omega**2 + M * v**2) / 2
def test_rigidbody3(): q1, q2, q3, q4 = dynamicsymbols('q1:5') p1, p2, p3 = symbols('p1:4') m = symbols('m') A = ReferenceFrame('A') B = A.orientnew('B', 'axis', [q1, A.x]) O = Point('O') O.set_vel(A, q2 * A.x + q3 * A.y + q4 * A.z) P = O.locatenew('P', p1 * B.x + p2 * B.y + p3 * B.z) I = outer(B.x, B.x) rb1 = RigidBody('rb1', P, B, m, (I, P)) # I_S/O = I_S/S* + I_S*/O rb2 = RigidBody('rb2', P, B, m, (I + inertia_of_point_mass(m, P.pos_from(O), B), O)) assert rb1.central_inertia == rb2.central_inertia assert rb1.angular_momentum(O, A) == rb2.angular_momentum(O, A)
def test_rigidbody3(): q1, q2, q3, q4 = dynamicsymbols('q1:5') p1, p2, p3 = symbols('p1:4') m = symbols('m') A = ReferenceFrame('A') B = A.orientnew('B', 'axis', [q1, A.x]) O = Point('O') O.set_vel(A, q2*A.x + q3*A.y + q4*A.z) P = O.locatenew('P', p1*B.x + p2*B.y + p3*B.z) I = outer(B.x, B.x) rb1 = RigidBody('rb1', P, B, m, (I, P)) # I_S/O = I_S/S* + I_S*/O rb2 = RigidBody('rb2', P, B, m, (I + inertia_of_point_mass(m, P.pos_from(O), B), O)) assert rb1.central_inertia == rb2.central_inertia assert rb1.angular_momentum(O, A) == rb2.angular_momentum(O, A)
def test_rigidbody3(): q1, q2, q3, q4 = dynamicsymbols("q1:5") p1, p2, p3 = symbols("p1:4") m = symbols("m") A = ReferenceFrame("A") B = A.orientnew("B", "axis", [q1, A.x]) O = Point("O") O.set_vel(A, q2 * A.x + q3 * A.y + q4 * A.z) P = O.locatenew("P", p1 * B.x + p2 * B.y + p3 * B.z) P.v2pt_theory(O, A, B) I = outer(B.x, B.x) rb1 = RigidBody("rb1", P, B, m, (I, P)) # I_S/O = I_S/S* + I_S*/O rb2 = RigidBody("rb2", P, B, m, (I + inertia_of_point_mass(m, P.pos_from(O), B), O)) assert rb1.central_inertia == rb2.central_inertia assert rb1.angular_momentum(O, A) == rb2.angular_momentum(O, A)
# reference frames A = ReferenceFrame('A') B = A.orientnew('B', 'body', [q1, q2, q3], 'xyz') # points B*, O pB_star = Point('B*') pB_star.set_vel(A, 0) # rigidbody B I_B_Bs = inertia(B, I11, I22, I33) rbB = RigidBody('rbB', pB_star, B, m, (I_B_Bs, pB_star)) # kinetic energy K = rbB.kinetic_energy(A) # velocity of point B* is zero print('K_ω = {0}'.format(msprint(K))) print('\nSince I11, I22, I33 are the central principal moments of inertia') print('let I_min = I11, I_max = I33') I_min = I11 I_max = I33 H = rbB.angular_momentum(pB_star, A) K_min = dot(H, H) / I_max / 2 K_max = dot(H, H) / I_min / 2 print('K_ω_min = {0}'.format(msprint(K_min))) print('K_ω_max = {0}'.format(msprint(K_max))) print('\nI11/I33, I22/I33 =< 1, since I33 >= I11, I22, so K_ω_min <= K_ω') print('Similarly, I22/I11, I33/I11 >= 1, ' 'since I11 <= I22, I33, so K_ω_max >= K_ω')
# reference frames A = ReferenceFrame('A') B = A.orientnew('B', 'body', [q1, q2, q3], 'xyz') # points B*, O pB_star = Point('B*') pB_star.set_vel(A, 0) # rigidbody B I_B_Bs = inertia(B, I11, I22, I33) rbB = RigidBody('rbB', pB_star, B, m, (I_B_Bs, pB_star)) # kinetic energy K = rbB.kinetic_energy(A) # velocity of point B* is zero print('K_ω = {0}'.format(msprint(K))) print('\nSince I11, I22, I33 are the central principal moments of inertia') print('let I_min = I11, I_max = I33') I_min = I11 I_max = I33 H = rbB.angular_momentum(pB_star, A) K_min = dot(H, H) / I_max / 2 K_max = dot(H, H) / I_min / 2 print('K_ω_min = {0}'.format(msprint(K_min))) print('K_ω_max = {0}'.format(msprint(K_max))) print('\nI11/I33, I22/I33 =< 1, since I33 >= I11, I22, so K_ω_min <= K_ω') print('Similarly, I22/I11, I33/I11 >= 1, ' 'since I11 <= I22, I33, so K_ω_max >= K_ω')
pA = Point('A') pA.set_vel(N, 0) pA.set_vel(F1, 0) # bearing B, center of mass of disc pB = pA.locatenew('pB', -R * F1.y) pB.set_vel(B, 0) pB.v2pt_theory(pA, N, F1) print('v_B_N = {}'.format(msprint(pB.vel(N)))) Ixx = m * r**2 / 4 Iyy = m * r**2 / 4 Izz = m * r**2 / 2 I_disc = inertia(F2, Ixx, Iyy, Izz, 0, 0, 0) rb_disc = RigidBody('disc', pB, B, m, (I_disc, pB)) H = rb_disc.angular_momentum(pB, N).subs(vals).express(F2).simplify() print("H about B in frame N = {}".format(msprint(H))) #2b # disc/ground contact point pC = pB.locatenew('pC', -r * F2.y) fAx, fAy, fAz, fBx, fBy, fBz = symbols('fAx fAy fAz fBx fBy fBz') fCx, fCy, fCz = symbols('fCx fCy fCz') mAx, mAy, mAz, mBx, mBy, mBz = symbols('mAx mAy mAz mBx mBy mBz') # forces on rod, disc fA = fAx * F1.x + fAy * F1.y + fAz * F1.z # force exerted on rod at point A fB = fBx * F2.x + fBy * F2.y + fBz * F2.z # force exerted on disc by rod at point B fC = fCx * F2.x + fCy * F2.y + fCz * F2.z # force exerted on ground by disc at point C mA = mAx * F1.x + mAy * F1.y + mAz * F1.z # moment exerted on rod A from axis
pA = Point('A') pA.set_vel(N, 0) pA.set_vel(F1, 0) # bearing B, center of mass of disc pB = pA.locatenew('pB', -R*F1.y) pB.set_vel(B, 0) pB.v2pt_theory(pA, N, F1) print('v_B_N = {}'.format(msprint(pB.vel(N)))) Ixx = m*r**2/4 Iyy = m*r**2/4 Izz = m*r**2/2 I_disc = inertia(F2, Ixx, Iyy, Izz, 0, 0, 0) rb_disc = RigidBody('disc', pB, B, m, (I_disc, pB)) H = rb_disc.angular_momentum(pB, N).subs(vals).express(F2).simplify() print("H about B in frame N = {}".format(msprint(H))) #2b # disc/ground contact point pC = pB.locatenew('pC', -r*F2.y) fAx, fAy, fAz, fBx, fBy, fBz = symbols('fAx fAy fAz fBx fBy fBz') fCx, fCy, fCz = symbols('fCx fCy fCz') mAx, mAy, mAz, mBx, mBy, mBz = symbols('mAx mAy mAz mBx mBy mBz') # forces on rod, disc fA = fAx*F1.x + fAy*F1.y + fAz*F1.z # force exerted on rod at point A fB = fBx*F2.x + fBy*F2.y + fBz*F2.z # force exerted on disc by rod at point B fC = fCx*F2.x + fCy*F2.y + fCz*F2.z # force exerted on ground by disc at point C mA = mAx*F1.x + mAy*F1.y + mAz*F1.z # moment exerted on rod A from axis
q1dd, q2dd = dynamicsymbols('q1 q2', 2) m, Ia, It = symbols('m Ia It', real=True, positive=True) N = ReferenceFrame('N') F = N.orientnew('F', 'axis', [q1, N.z]) # gimbal frame B = F.orientnew('B', 'axis', [q2, F.x]) # flywheel frame P = Point('P') P.set_vel(N, 0) P.set_vel(F, 0) P.set_vel(B, 0) I = inertia(F, Ia, It, It, 0, 0, 0) rb = RigidBody('flywheel', P, B, m, (I, P)) H = rb.angular_momentum(P, N) print('H_P_N = {}\n = {}'.format(H.express(N), H.express(F))) dH = H.dt(N) print('d^N(H_P_N)/dt = {}'.format(dH.express(F).subs(q2dd, 0))) print('\ndH/dt = M') print('M = {}'.format(dH.express(F).subs(q2dd, 0))) print('\ncalculation using euler angles') t = symbols('t') omega = F.ang_vel_in(N) wx = omega & F.x wy = omega & F.y wz = omega & F.z s = B.ang_vel_in(F) & F.x Mx = Ia*(wx + s).diff(t)
from sympy import pi, solve, symbols, simplify from sympy import acos, sin, cos # 2a q1 = dynamicsymbols('q1') px, py, pz = symbols('px py pz', real=True, positive=True) sx, sy, sz = symbols('sx sy sz', real=True, sositive=True) m, g, l0, k = symbols('m g l0 k', real=True, positive=True) Ixx, Iyy, Izz = symbols('Ixx Iyy Izz', real=True, positive=True) N = ReferenceFrame('N') B = N.orientnew('B', 'axis', [q1, N.z]) pA = Point('A') pA.set_vel(N, 0) pP = pA.locatenew('P', l0*N.y - 2*l0*N.z) pS = pP.locatenew('S', -px*B.x - pz*B.z) I = inertia(B, Ixx, Iyy, Izz, 0, 0, 0) rb = RigidBody('plane', pS, B, m, (I, pS)) H = rb.angular_momentum(pS, N) print('H about S in frame N = {}'.format(msprint(H))) print('dH/dt = {}'.format(msprint(H.dt(N)))) print('a_S_N = {}'.format(pS.acc(N)))
from sympy.physics.mechanics import inertia, msprint from sympy.physics.mechanics import Point, RigidBody from sympy import pi, solve, symbols, simplify from sympy import acos, sin, cos # 2a q1 = dynamicsymbols('q1') px, py, pz = symbols('px py pz', real=True, positive=True) sx, sy, sz = symbols('sx sy sz', real=True, sositive=True) m, g, l0, k = symbols('m g l0 k', real=True, positive=True) Ixx, Iyy, Izz = symbols('Ixx Iyy Izz', real=True, positive=True) N = ReferenceFrame('N') B = N.orientnew('B', 'axis', [q1, N.z]) pA = Point('A') pA.set_vel(N, 0) pP = pA.locatenew('P', l0 * N.y - 2 * l0 * N.z) pS = pP.locatenew('S', -px * B.x - pz * B.z) I = inertia(B, Ixx, Iyy, Izz, 0, 0, 0) rb = RigidBody('plane', pS, B, m, (I, pS)) H = rb.angular_momentum(pS, N) print('H about S in frame N = {}'.format(msprint(H))) print('dH/dt = {}'.format(msprint(H.dt(N)))) print('a_S_N = {}'.format(pS.acc(N)))