Hello!
On running lagrange.py file of Unit3, getting the error of "cannt set attributes,
I ran this whole code in Jupyter Notebook and i didnot get any error.
Kindly help in solving it.
Thanks
Hello!
On running lagrange.py file of Unit3, getting the error of "cannt set attributes,
Hello @misbahsuhail123,
could you please compare your file with the code shown below?
The first part of the lagrange.py file, where you build the Lagrangian should look like this:
from __future__ import print_function, division
from sympy import symbols, simplify, trigsimp
from sympy.physics.mechanics import (dynamicsymbols, ReferenceFrame, Point,
inertia, RigidBody, Lagrangian, LagrangesMethod)
from sympy.physics.vector import init_vprinting, vlatex
init_vprinting(use_latex='mathjax', pretty_print=False)
inertial_frame = ReferenceFrame('I')
lower_link_frame = ReferenceFrame('L')
upper_link_frame = ReferenceFrame('U')
theta_1, theta_2 = dynamicsymbols('theta_1 theta_2')
dtheta_1, dtheta_2 = dynamicsymbols('theta_1 theta_2', 1)
tau_1, tau_2 = dynamicsymbols('tau_1 tau_2')
l_1, l_2 = symbols('l_1 l_2', positive=True)
r_1, r_2 = symbols('r_1 r_2', positive=True)
m_1, m_2, b, g = symbols('m_1 m_2 b g')
I_1_yy, I_2_yy = symbols('I_{1yy}, I_{2yy}')
lower_link_frame.orient(inertial_frame, 'Axis', [theta_1, inertial_frame.y])
upper_link_frame.orient(lower_link_frame, 'Axis', [
theta_2, lower_link_frame.y])
shoulder = Point('S')
shoulder.set_vel(inertial_frame, 0)
elbow = Point('E')
elbow.set_pos(shoulder, l_1 * lower_link_frame.z)
elbow.v2pt_theory(shoulder, inertial_frame, lower_link_frame)
CM_1 = Point('CM_1')
CM_1.set_pos(shoulder, r_1 * lower_link_frame.z)
CM_1.v2pt_theory(shoulder, inertial_frame, lower_link_frame)
CM_2 = Point('CM_2')
CM_2.set_pos(elbow, r_2 * upper_link_frame.z)
CM_2.v2pt_theory(elbow, inertial_frame, upper_link_frame)
I_1 = inertia(lower_link_frame, 0, I_1_yy, 0)
BODY_1 = RigidBody('lower_link', CM_1, lower_link_frame, m_1, (I_1, CM_1))
I_2 = inertia(upper_link_frame, 0, I_2_yy, 0)
BODY_2 = RigidBody('upper_link', CM_2, upper_link_frame, m_2, (I_2, CM_2))
P_1 = m_1 * g * inertial_frame.z
r_1_CM = CM_1.pos_from(shoulder).express(inertial_frame)
BODY_1.potential_energy = r_1_CM.dot(P_1)
P_2 = m_2 * g * inertial_frame.z
r_2_CM = CM_2.pos_from(shoulder).express(inertial_frame).simplify()
BODY_2.potential_energy = r_2_CM.dot(P_2)
L = Lagrangian(inertial_frame, BODY_1, BODY_2)
print(L)
See if you can find any differences,
Cheers,
Roberto
Hello!
Thanks for your help. code is working now
This topic was automatically closed after 21 hours. New replies are no longer allowed.