U
    —9%e?  ã                   @   s:   d Z ddlmZ ddlm  mZ ddd„Zdd	d
„Z	dS )zOThis module contains some sample symbolic models used for testing and
examples.é    )ÚbackendNé   Fc              	   C   s  t  d | ¡¡}t  d | ¡¡}t  d | ¡¡}t  d¡}t d | ¡¡}t d | ¡¡}t d | ¡¡}	t d¡}
t d	¡}| |
d
¡ |g}g }g }g }t| ƒD ]<}|d  	d |¡|| |
j
 ¡}| |
|d  |
¡|| |
j
  ¡ | |¡ t d |¡||| ¡}| || ||  ¡  ¡ ||  ||  || ||   }z8|||d  ||d   ||d  ||d    7 }W n tk
rš   Y nX |r²||| | 7 }|rÄ||	| 7 }| |||
j
 f¡ | |¡ q¤tj|
|||d}| ||¡ |S )as  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.

    úm:{}zk:{}zc:{}Úgzx:{}zv:{}zf:{}ÚNÚoriginr   éÿÿÿÿzcenter{}zblock{}r   ©Zq_indZu_indZkd_eqs)ÚsmÚsymbolsÚformatÚmeÚdynamicsymbolsÚReferenceFrameÚPointÚset_velÚrangeÚ	locatenewÚxZvelÚappendÚParticleÚdiffÚ
IndexErrorÚKanesMethodÚkanes_equations)ÚnZapply_gravityZapply_external_forcesZmassZ	stiffnessZdampingZacceleration_due_to_gravityZcoordinatesZspeedsZ
specifiedsZceilingr   ÚpointsZkinematic_equationsÚ	particlesÚforcesÚiÚcenterÚblockZtotal_forceÚkane© r#   ú]/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/physics/mechanics/models.pyÚmulti_mass_spring_damper
   sX    .


ÿÿ
ÿÿ

ÿr%   Tc                 C   s<  | dkrt dƒ‚t d | d ¡¡}t d | d ¡¡}|dkrTt d | d ¡¡}t d | d ¡¡}t d	 | ¡¡}t d
¡\}}	t d¡}
t d¡}| |
d¡ t d¡}| 	||d |
j
 ¡ | |
|d |
j
 ¡ t d||d ¡}|
g}|g}|g}||d  | |
j fg}|d  |	¡|d  g}|dksF|dkrLg }nd}t| ƒD ]Œ}|
 d |¡d||d  |
jg¡}| |
||d  |
j ¡ | |¡ |d  d |d ¡|| |j ¡}| |d |
|¡ | |¡ t dt|d ƒ |||d  ¡}| |¡ | |||d   | |
j f¡ |dkrÀ| || ¡ |dkrn| |
||  |
j f¡ || d kr–| ||| |
j f¡ n*| ||| |
j ||d  |
j  f¡ | ||d   |	¡||d   ¡ qX|dkrt d¡}| |||
j
 f¡ | |¡ tj|
|||d}| ||¡ |S )a-  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.

    r   z/The number of links must be a positive integer.zq:{}r   zu:{}TzT1:{}r   zl:{}zg tÚIÚOÚP0ÚPa0NzB{}ZAxisr   zP{}ZPaÚFr	   )Ú
ValueErrorr   r   r   r
   r   r   r   r   Zset_posr   r   Úyr   r   Z	orientnewÚzZset_ang_velr   r   Zv2pt_theoryÚstrr   r   )r   Z
cart_forceZjoint_torquesÚqÚuÚTÚmÚlr   Útr&   r'   r(   r)   Úframesr   r   r   ZkindiffsZ	specifiedr   ZBiÚPiZPair*   r"   r#   r#   r$   Ún_link_pendulum_on_cartp   sb    1


"
$
"
"

*(


r7   )r   FF)r   TF)
Ú__doc__Z
sympy.corer   r
   Zsympy.physics.mechanicsZphysicsZ	mechanicsr   r%   r7   r#   r#   r#   r$   Ú<module>   s     ÿ
f