-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] 3 link pendulum #10
base: master
Are you sure you want to change the base?
Changes from 5 commits
06398c4
11a0059
d5f2d44
a61e602
e69d5cf
8d379c2
b7571e7
944ab76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This is a 3 link pendulum problem, assuming links as RigidBodies .. | ||
I will add a fig soon .. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
#For this one we assume RigidBody links | ||
from sympy import symbols,sympify | ||
from sympy.physics.mechanics import * | ||
|
||
#Number of links = 3 | ||
N_links = 3 | ||
|
||
#Number of masses = 3 | ||
N_bobs = 3 | ||
|
||
#Defining Dynamic Symbols ................ | ||
|
||
#Generalized coordinates(angular) ... | ||
|
||
alpha = dynamicsymbols('alpha1 alpha2 alpha3') | ||
beta = dynamicsymbols('beta1 beta2 beta3') | ||
|
||
#Generalized speeds(angular) ... | ||
alphad = dynamicsymbols('alpha1 alpha2 alpha3',1) | ||
betad = dynamicsymbols('beta1 beta2 beta3',1) | ||
|
||
#Mass of each bob: | ||
m = symbols('m:'+str(N_bobs)) | ||
|
||
|
||
#Length and mass of each link .. | ||
l = symbols('l:' + str(N_links)) | ||
M = symbols('M:' + str(N_links)) | ||
#For storing Inertia for each link : | ||
Ixx = symbols('Ixx:'+str(N_links)) | ||
Iyy = symbols('Iyy:'+str(N_links)) | ||
|
||
#gravity and time .... | ||
g, t = symbols('g t') | ||
|
||
|
||
#Now defining an Inertial ReferenceFrame First .... | ||
|
||
I = ReferenceFrame('I') | ||
|
||
#And some other frames ... | ||
|
||
A = ReferenceFrame('A') | ||
A.orient(I,'Body',[alpha[0],beta[0],0],'ZXY') | ||
B = ReferenceFrame('B') | ||
B.orient(I,'Body',[alpha[1],beta[1],0],'ZXY') | ||
C = ReferenceFrame('C') | ||
C.orient(I,'Body',[alpha[2],beta[2],0],'ZXY') | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The .orientnew method is a little more compact here. A = ReferenceFrame('A')
B = A.orientnew('B', 'Body', (alpha[0], beta[0], 0), 'ZXY') Also please read through the PEP8 style guide if you haven't: http://www.python.org/dev/peps/pep-0008/ You should have spaces after your commas. |
||
|
||
#Setting angular velocities of new frames ... | ||
A.set_ang_vel(I, alphad[0] * I.z + betad[0] * I.x) | ||
B.set_ang_vel(I, alphad[1] * I.z + betad[1] * I.x) | ||
C.set_ang_vel(I, alphad[2] * I.z + betad[2] * I.x) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you had defined generalized speed variables you could insert them here instead of the derivatives. u0 = DynamicsSymbols('u0')
u1 = DynamicsSymbols('u1')
A.set_ang_vel(I, u0 * I.z + u1 * I.x) Also did you set the angular velocity of I equal to zero. I think you need to, but not sure. |
||
|
||
|
||
# An Origin point, with velocity = 0 | ||
O = Point('O') | ||
O.set_vel(I,0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pep8, space after comma |
||
|
||
#Three more points, for masses .. | ||
P1 = O.locatenew('P1', l[0] * A.y) | ||
P2 = O.locatenew('P2', l[1] * B.y) | ||
P3 = O.locatenew('P3', l[2] * C.y) | ||
|
||
#Setting velocities of points with v2pt theory ... | ||
P1.v2pt_theory(O, I, A) | ||
P2.v2pt_theory(P1, I, B) | ||
P3.v2pt_theory(P2, I, C) | ||
points = [P1,P2,P3] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pep8 |
||
|
||
Pa1 = Particle('Pa1', points[0], m[0]) | ||
Pa2 = Particle('Pa2', points[1], m[1]) | ||
Pa3 = Particle('Pa3', points[2], m[2]) | ||
particles = [Pa1,Pa2,Pa3] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pep8 |
||
|
||
|
||
|
||
#defining points for links(RigidBodies) | ||
#Assuming CoM as l/2 ... | ||
P_link1 = O.locatenew('P_link1', l[0]/2 * A.y) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pep8 would be 0.locatenew('P_link1', l[0] / 2 * A.y) |
||
P_link2 = O.locatenew('P_link1', l[1]/2 * B.y) | ||
P_link3 = O.locatenew('P_link1', l[2]/2 * C.y) | ||
#setting velocities of these points with v2pt theory ... | ||
P_link1.v2pt_theory(O, I, A) | ||
P_link2.v2pt_theory(P_link1, I, B) | ||
P_link3.v2pt_theory(P_link2, I, C) | ||
|
||
points_rigid_body = [P_link1,P_link2,P_link3] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces |
||
|
||
|
||
#defining inertia tensors for links | ||
|
||
inertia_link1 = inertia(A,Ixx[0],Iyy[0],0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can probably get away with Iyy = 0 but Izz = 0 is very unrealistic for a pendulum link. At the bare minimum you need moments of inertia about the x and z axes (assuming y is "down"). |
||
inertia_link2 = inertia(B,Ixx[1],Iyy[1],0) | ||
inertia_link3 = inertia(C,Ixx[2],Iyy[2],0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above for the comments on inerita. please generalize the inertia or make it explicit about the symmetry of the object |
||
|
||
#Defining links as Rigid bodies ... | ||
|
||
link1 = RigidBody('link1', P_link1, A, M[0], (inertia_link1, O)) | ||
link2 = RigidBody('link2', P_link2, B, M[1], (inertia_link2, P1)) | ||
link3 = RigidBody('link3', P_link3, C, M[2], (inertia_link3, P2)) | ||
links = [link1,link2,link3] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces |
||
|
||
|
||
#Applying forces on all particles , and adding all forces in a list.. | ||
forces = [] | ||
for particle in particles: | ||
|
||
mass = particle.get_mass() | ||
point = particle.get_point() | ||
forces.append((point, -mass * g * I.y) ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make a comment somwhere describing which direction you are defining to be "down" (i.e. aligned with gravity). |
||
|
||
#Applying forces on rigidbodies .. | ||
for link in links: | ||
mass = link.get_mass() | ||
point = link.get_masscenter() | ||
forces.append((point, -mass * g * I.y) ) | ||
kinetic_differentials = [] | ||
for i in range(0,N_bobs): | ||
kinetic_differentials.append(alphad[i] - alpha[i]) | ||
kinetic_differentials.append(betad[i] - beta[i]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have a coordinate, q, and a generalized speed, u, where u = q', then the kinematical differential equations is u - q' = 0. But here you define them as q' - q = 0, which is incorrect. You need to define some explicit generalized speeds. |
||
|
||
#Adding particles and links in the same system ... | ||
total_system = [] | ||
for particle in particles: | ||
total_system.append(particle) | ||
|
||
for link in links: | ||
total_system.append(link) | ||
|
||
q = [] | ||
for angle in alpha: | ||
q.append(angle) | ||
for angle in beta: | ||
q.append(angle) | ||
print q | ||
u = [] | ||
|
||
for vel in alphad: | ||
u.append(vel) | ||
for vel in betad: | ||
u.append(vel) | ||
|
||
print u | ||
kane = KanesMethod(I, q_ind=q, u_ind=u, kd_eqs=kinetic_differentials) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the only main issue you have with this problem is your definitions of generalized speeds and the kinematic differential equations. Check over this carefully in the other examples. |
||
fr, frstar = kane.kanes_equations(forces, total_system) | ||
|
||
print fr | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general inertia matrix has 9 entries: three moments of inertia and 6 products of inertia. You are only introducing the moments of inertia about the x and y axes. Where are the other entries? Is the link assumed symmetric? Depending on the symmetry you can reduce the inertia down to the three moments of inertia but since you have no Z inertia at all this seems problematic. I'd prefer you to add all of the inertia tensor entries here and then if you assume symmetry about various planes you can set the appropriate products of inertia equal to zero when you get to the numerical simulation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only 6 entries will be unique, inertia matrices are always symmetric (i.e., Ixy == Iyx, Ixz == Izx, Iyz == Izy). If you create a 3x3 with 9 unique entries and somehow you accidentally make it non-symmetric, it won't be representative of an inertia matrix and is probably a mistake. The inertia() function in mechanics may be useful here.