models¶
Introduction¶
The pydy.models
file provides canned symbolic models of classical
dynamic systems that are mostly for testing and example purposes. There are
currently two models:
multi_mass_spring_damper()
A one dimensional series of masses connected by linear dampers and springs that can optionally be under the influence of gravity and an arbitrary force.
n_link_pendulum_on_cart()
This is an extension to the classic two dimensional inverted pendulum on a cart to multiple links. You can optionally apply an arbitrary lateral force to the cart and/or apply arbitrary torques between each link.
Example Use¶
A simple one degree of freedom mass spring damper system can be created with:
>>> from pydy.models import multi_mass_spring_damper
>>> sys = multi_mass_spring_damper()
>>> sys.constants_symbols
{m0, c0, k0}
>>> sys.coordinates
[x0(t)]
>>> sys.speeds
[v0(t)]
>>> sys.eom_method.rhs()
Matrix([
[ v0(t)],
[(-c0*v0(t) - k0*x0(t))/m0]])
A two degree of freedom mass spring damper system under the influence of gravity and two external forces can be created with:
>>> sys = multi_mass_spring_damper(2, True, True)
>>> sys.constants_symbols
{c1, m1, k0, c0, k1, m0, g}
>>> sys.coordinates
[x0(t), x1(t)]
>>> sys.speeds
[v0(t), v1(t)]
>>> sys.specifieds_symbols
{f0(t), f1(t)}
>>> from sympy import simplify
>>> sm.simplify(sys.eom_method.rhs())
Matrix([
[ v0(t)],
[ v1(t)],
[ (-c0*v0(t) + c1*v1(t) + g*m0 - k0*x0(t) + k1*x1(t) + f0(t))/m0],
[-(m1*(-c0*v0(t) + g*m0 + g*m1 - k0*x0(t) + f0(t) + f1(t)) + (m0 + m1)*(c1*v1(t) - g*m1 + k1*x1(t) - f1(t)))/(m0*m1)]])
API¶
This module contains some sample symbolic models used for testing and examples.
- pydy.models.multi_mass_spring_damper(n=1, apply_gravity=False, apply_external_forces=False)[source]¶
Returns a system containing the symbolic equations of motion and associated variables for a simple mutli-degree of freedom point mass, spring, damper system with optional gravitational and external specified forces. For example, a two mass system under the influence of gravity and external forces looks like:
---------------- | | | | g \ | | | V k0 / --- c0 | | | | x0, v0 --------- V | m0 | ----- --------- | | | | | \ v | | | k1 / f0 --- c1 | | | | x1, v1 --------- V | m1 | ----- --------- | f1 V
- Parameters
- ninteger
The number of masses in the serial chain.
- apply_gravityboolean
If true, gravity will be applied to each mass.
- apply_external_forcesboolean
If true, a time varying external force will be applied to each mass.
- Returns
- systempydy.system.System
A system constructed from the KanesMethod object.
- pydy.models.n_link_pendulum_on_cart(n=1, cart_force=True, joint_torques=False)[source]¶
Returns the system containing the symbolic first order equations of motion for a 2D n-link pendulum on a sliding cart under the influence of gravity.
| v y o g ^ / | / ----|-/-- theta0 | |/ | F-> | o --|---> x | | --------- o o
- Parameters
- ninteger
The number of links in the pendulum.
- cart_forceboolean, default=True
If true an external specified lateral force is applied to the cart.
- joint_torquesboolean, default=False
If true joint torques will be added as specified inputs at each joint.
- Returns
- systempydy.system.System
The system containing the symbolics.
Notes
The degrees of freedom of the system are n + 1, i.e. one for each pendulum link and one for the lateral motion of the cart.
M x’ = F, where x = [u0, …, un+1, q0, …, qn+1]
The joint angles are all defined relative to the ground where the x axis defines the ground line and the y axis points up. The joint torques are applied between each adjacent link and the between the cart and the lower link where a positive torque corresponds to positive angle.