Last active
August 29, 2015 14:07
-
-
Save moorepants/e579e0275ef274ec7829 to your computer and use it in GitHub Desktop.
A simple example to demonstrate the issues with having specified positions, velocities, and accelerations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""This derives the equations of motion for a point mass pendulum on a | |
laterally moving base, i.e. the classic inverted pendulum on a moving cart. | |
iy | |
^ E | |
| o m | |
| l / | | |
| / v g | |
| J / theta | |
O -----o------> ix | |
|-x->| | |
""" | |
import sympy as sy | |
import sympy.physics.mechanics as me | |
m, l, g = sy.symbols('m, l, g') | |
theta, omega, x, v, a = me.dynamicsymbols('theta, omega, x, v, a') | |
inertial_frame = me.ReferenceFrame('I') | |
pendulum_frame = inertial_frame.orientnew('P', 'Axis', (theta, | |
inertial_frame.z)) | |
pendulum_frame.set_ang_vel(inertial_frame, omega * inertial_frame.z) | |
origin = me.Point('O') | |
joint = origin.locatenew('J', x * inertial_frame.x) | |
joint.set_vel(inertial_frame, v * inertial_frame.x) | |
joint.set_acc(inertial_frame, a * inertial_frame.x) | |
end = joint.locatenew('E', l * pendulum_frame.x) | |
end.v2pt_theory(joint, inertial_frame, pendulum_frame) | |
end.a2pt_theory(joint, inertial_frame, pendulum_frame) | |
bob = me.Particle('B', end, m) | |
gravitational_force = -m * g * inertial_frame.y | |
kane = me.KanesMethod(inertial_frame, (theta,), (omega,), | |
(theta.diff() - omega,)) | |
fr, frstar = kane.kanes_equations([(end, gravitational_force)], [bob]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment