ó
~9­\c           @   sP   d  Z  d d l m Z d d l j j Z d e e d „ Z	 d e
 e d „ Z d S(   sO   This module contains some sample symbolic models used for testing and
examples.iÿÿÿÿ(   t   backendNi   c         C   s¢  t  j d j |  ƒ ƒ } t  j d j |  ƒ ƒ } t  j d j |  ƒ ƒ } t  j d ƒ } t j d j |  ƒ ƒ } t j d j |  ƒ ƒ } t j d j |  ƒ ƒ }	 t j d ƒ }
 t j d	 ƒ } | j |
 d
 ƒ | g } g  } g  } g  } x‚t |  ƒ D]t} | d j	 d j | ƒ | | |
 j
 ƒ } | j |
 | d j |
 ƒ | | |
 j
 ƒ | j | ƒ t j d j | ƒ | | | ƒ } | j | | | | j ƒ  ƒ | | | | | | | | } y: | | | d | | d | | d | | d 7} Wn t k
 rn X| r+| | | | 7} n  | rB| |	 | 7} n  | j | | |
 j
 f ƒ | j | ƒ qõ Wt j |
 d | d | d | ƒ} | j | | ƒ | S(   sq  Returns a system containing the symbolic equations of motion and
    associated variables for a simple multi-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
    ----------
    n : integer
        The number of masses in the serial chain.
    apply_gravity : boolean
        If true, gravity will be applied to each mass.
    apply_external_forces : boolean
        If true, a time varying external force will be applied to each mass.

    Returns
    -------
    kane : sympy.physics.mechanics.kane.KanesMethod
        A KanesMethod object.

    s   m:{}s   k:{}s   c:{}t   gs   x:{}s   v:{}s   f:{}t   Nt   origini    iÿÿÿÿs   center{}s   block{}i   t   q_indt   u_indt   kd_eqs(   t   smt   symbolst   formatt   met   dynamicsymbolst   ReferenceFramet   Pointt   set_velt   ranget	   locatenewt   xt   velt   appendt   Particlet   difft
   IndexErrort   KanesMethodt   kanes_equations(   t   nt   apply_gravityt   apply_external_forcest   masst	   stiffnesst   dampingt   acceleration_due_to_gravityt   coordinatest   speedst
   specifiedst   ceilingR   t   pointst   kinematic_equationst	   particlest   forcest   it   centert   blockt   total_forcet   kane(    (    s=   lib/python2.7/site-packages/sympy/physics/mechanics/models.pyt   multi_mass_spring_damper   sN    ,	" 	c         C   sI  |  d k r t  d ƒ ‚ n  t j d j |  d ƒ ƒ } t j d j |  d ƒ ƒ } | t k r~ t j d j |  d ƒ ƒ } n  t j d j |  d ƒ ƒ } t j d j |  ƒ ƒ } t j d	 ƒ \ } }	 t j d
 ƒ }
 t j d ƒ } | j	 |
 d ƒ t j d ƒ } | j
 | | d |
 j ƒ | j	 |
 | d |
 j ƒ t j d | | d ƒ } |
 g } | g } | g } | | d | |
 j f g } | d j |	 ƒ | d g } | t k sÃ| t k rÌg  } n d } xút |  ƒ D]ì} |
 j d j | ƒ d | | d |
 j g ƒ } | j |
 | | d |
 j ƒ | j | ƒ | d j d j | d ƒ | | | j ƒ } | j | d |
 | ƒ | j | ƒ t j d t | d ƒ | | | d ƒ } | j | ƒ | j | | | d | |
 j f ƒ | t k r¡| j | | ƒ | d k r<| j |
 | | |
 j f ƒ n  | |  d k rm| j | | | |
 j f ƒ q¡| j | | | |
 j | | d |
 j f ƒ n  | j | | d j |	 ƒ | | d ƒ qßW| t k rt j d ƒ } | j | | |
 j f ƒ | j | ƒ n  t j |
 d | d | d | ƒ} | j | | ƒ | S(   s*  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.

    ::

                  |
         o    y   v
          \ 0 ^   g
           \  |
          --\-|----
          |  \|   |
      F-> |   o --|---> x
          |       |
          ---------
           o     o

    Parameters
    ----------
    n : integer
        The number of links in the pendulum.
    cart_force : boolean, default=True
        If true an external specified lateral force is applied to the cart.
    joint_torques : boolean, default=False
        If true joint torques will be added as specified inputs at each
        joint.

    Returns
    -------
    kane : sympy.physics.mechanics.kane.KanesMethod
        A KanesMethod object.

    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.

    i    s/   The number of links must be a positive integer.s   q:{}i   s   u:{}s   T1:{}s   m:{}s   l:{}s   g tt   It   Ot   P0t   Pa0s   B{}t   Axisiÿÿÿÿs   P{}t   Pat   FR   R   R   N(   t
   ValueErrorR
   R   R	   t   TrueR   R   R   R   R   t   set_posR   R   t   yR   t   NoneR   t	   orientnewt   zt   set_ang_velR   R   t   v2pt_theoryt   strR   R   (   R   t
   cart_forcet   joint_torquest   qt   ut   Tt   mt   lR   t   tR.   R/   R0   R1   t   framesR$   R&   R'   t   kindiffst	   specifiedR(   t   Bit   Pit   PaiR4   R,   (    (    s=   lib/python2.7/site-packages/sympy/physics/mechanics/models.pyt   n_link_pendulum_on_cartp   sb    .				/.+'"!4.!(   t   __doc__t
   sympy.coreR    R   t   sympy.physics.mechanicst   physicst	   mechanicsR
   t   FalseR-   R6   RM   (    (    (    s=   lib/python2.7/site-packages/sympy/physics/mechanics/models.pyt   <module>   s
   c