ó
v™xTc           @   s&  d  d l  m Z y d  d l Z Wn e k
 r9 d Z n Xe d k	 ry d  d l m Z d  d l m Z d  d l	 m
 Z
 n/ d  d l Z d  d l Z d „  Z
 d GHd „  Z d  d l Z d	 „  Z d
 „  Z d „  Z e d ƒ Z d „  Z d „  Z d d „ Z d „  Z e d k r"e e j d ƒ n  d S(   iÿÿÿÿ(   t   divisionN(   t   featherstone(   t   matrix(   t   approx_equalc         C   s   t  S(   N(   t   True(   t   a1t   a2(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyR      s    s8   libtbx.test_utils not available: approx_equal() disabledc         C   s%   d } x |  D] } | | 7} q W| S(   Ni    (    (   t   lt   resultt   e(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   sum   s     c           C   sH  t  t t j d ƒ ƒ d ƒ s$ t ‚ t  t t j d ƒ ƒ d ƒ sH t ‚ t  t t j d ƒ ƒ d ƒ sl t ‚ t  t t j d ƒ ƒ d ƒ s� t ‚ t  t t j d ƒ ƒ d ƒ s´ t ‚ t  t t j	 d ƒ ƒ d ƒ sØ t ‚ t  t t j
 d ƒ ƒ d ƒ sü t ‚ t  t t j d d d t j d ƒ d t j d d ƒ ƒ ƒ d ƒ sDt ‚ d  S(   Ngš™™™™™¹?g Ô|‰ë@gš™™™™™É?ge›»JZ®@g333333Ó?g4zêI@i   i   i   i   i   i   i   i   i	   iZ   i    t   mgX9´Èv¾ó?t   ct   It   sym_mat3gu“VN5@(	   i   i   i   i   i   i   i   i   i	   (   i   i   i   (   i   i   i   i   i   i   (   i   i   i   i   i   i   (   i   i   i   (   i   i   i   gš™™™™™¹?gš™™™™™É?g333333Ó?(   R   R
   t   fst   Xrotxt   AssertionErrort   Xrotyt   Xrotzt   Xrott   Xtranst   crmt   crft   mcIR   t   colt   sym(    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   exercise_basic   s    $$$$$$$c         C   s(   t  d |  d ƒ j d | | f ƒ d  S(   Ns   tst_featherstone_exercise_%s.mt   ws-   split_long_rows(0);
output_precision(%d);

%s(   t   opent   write(   t   labelt	   precisiont   code(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   write_matlab_script$   s    c         C   s·   g  } g  } xŒ |  j  ƒ  D]~ } t |  ƒ d k r7 q n  | j g  | j ƒ  D] } t | ƒ ^ qJ ƒ t | ƒ d k r | j t j d | ƒ ƒ g  } q q Wt | ƒ d k s³ t ‚ | S(   Ni    i$   t   elems(	   t
   splitlinest   lent   extendt   splitt   floatt   appendR   t   sqrR   (   t   sR   R#   t   linet   v(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   extract_sqr_matrices+   s     ,sž  
       0.0025000   0.0000000   0.0000000   0.0000000  -0.0000000   0.0000000
       0.0000000   0.3345833   0.0000000   0.0000000   0.0000000  -0.5000000
       0.0000000   0.0000000   0.3345833  -0.0000000   0.5000000   0.0000000
       0.0000000   0.0000000  -0.0000000   1.0000000   0.0000000   0.0000000
      -0.0000000   0.0000000   0.5000000   0.0000000   1.0000000   0.0000000
       0.0000000  -0.5000000   0.0000000   0.0000000   0.0000000   1.0000000

       0.0025000   0.0000000   0.0000000   0.0000000  -0.0000000   0.0000000
       0.0000000   0.3345833   0.0000000   0.0000000   0.0000000  -0.5000000
       0.0000000   0.0000000   0.3345833  -0.0000000   0.5000000   0.0000000
       0.0000000   0.0000000  -0.0000000   1.0000000   0.0000000   0.0000000
      -0.0000000   0.0000000   0.5000000   0.0000000   1.0000000   0.0000000
       0.0000000  -0.5000000   0.0000000   0.0000000   0.0000000   1.0000000
c          C   sì   t  d d d d d d ƒ t j d d ƒ }  |  j d k s@ t ‚ |  j d	 d	 g k s[ t ‚ |  j d
 d	 g k sv t ‚ t |  j ƒ d k s‘ t ‚ t |  j	 ƒ d k s¬ t ‚ t
 d ƒ } t |  j | ƒ sÐ t ‚ t |  j	 t ƒ sè t ‚ d  S(   NR   t   autoTreeR    i   R!   s   autoTree(2)
t   nbi   i    iÿÿÿÿs^  
       1   0   0   0   0   0
       0   1   0   0   0   0
       0   0   1   0   0   0
       0   0  -0   1   0   0
      -0   0   0   0   1   0
       0  -0   0   0   0   1

       1   0   0   0   0   0
       0   1   0   0   0   0
       0   0   1   0   0   0
       0   0   0   1   0   0
       0   0   1   0   1   0
       0  -1   0   0   0   1
(   R"   R   R/   t   NBR   t   pitcht   parentR%   t   XtreeR   R.   R   t   expected_autoTree_I(   t   treet   expected(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   exercise_autoTreeG   s    	c          C   sÓ  t  d d d d d d ƒ t j d d d d	 d
 d d d ƒ }  d |  j d <t j |  j d <d |  j d <t j |  j d <d d d d d d d d d d d d g } d  d! d" d# d$ d% d& d' d( d) d* d+ g } d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 g } g  d8 d9 d: d; d< d= g d> d? d@ dA dB dC g dD dE dF dG dH dI g dJ dK dL dM dN dO g dP dQ dR dS dT dU g dV dW dX dY dZ d[ g d\ d] d^ d_ d` da g db dc dd de df dg g dh di dj dk dl dm g dn do dp dq dr ds g dt du dv dw dx dy g dz d{ d| d} d~ d g g D] } t j | ƒ ^ qø} d€ d� d‚ g } dƒ d„ d… d† d‡ dˆ d‰ dŠ d‹ dŒ d� dŽ g d� d� d‘ d’ d“ d” d• d– d— d˜ d™ dš g d› dœ d� dž dŸ d  d¡ d¢ d£ d¤ d¥ d¦ g g } x/t d  | | g d  d  | g | ƒ D]	\ } }	 }
 t j	 d§ |  d¨ | d© | dª | d« | d¬ |	 ƒ } t
 | ƒ t
 |
 ƒ k st ‚ t g  | D] } | j d­ ^ q)|
 ƒ sNt ‚ t j d§ |  d¨ | d© | d® | d« | d¬ |	 ƒ } t
 | ƒ t
 | ƒ k sœt ‚ t g  | D] } | j d­ ^ q¦| ƒ sÂt ‚ qÂWd  S(¯   NR   t   ID_FDabR    i   R!   s  % modified version of test_FD.m

% test the correctness of FDab, and ID by checking that FDab
% is the inverse of ID.

% step 1: create a complicated kinematic tree, and adjust some of the
% pitches so that it contains helical and prismatic as well as revolute
% joints.

tree = autoTree( 12, 1.5, 1, 0.95 );
tree.pitch(3) = 0.1;
tree.pitch(5) = inf;
tree.pitch(7) = -0.1;
tree.pitch(9) = inf;

% step 2: choose random initial conditions

rand("state", [0]);
q   = pi * (2*rand(12,1) - 1);
qd  = 2*rand(12,1) - 1;
qdd = 2*rand(12,1) - 1;
q
qd
qdd

for i = 1:tree.NB
  f_ext{i} = 2*rand(6,1) - 1;
end
f_ext

grav_accn = 2*rand(3,1) - 1;
grav_accn

% step 3: use ID to calculate the force required to produce qdd; then use
% FDab to calculate the acceleration that this force
% produces.

tau = ID( tree, q, qd, qdd );
qdd_ab = FDab( tree, q, qd, tau );

% step 4: compare results.  In theory, we should have qdd_ab==qdd and
% qdd_crb==qdd.  However, rounding errors will make them slightly
% different.  Expect rounding errors in the vicinity of 1e-14 on this
% test.

tau
qdd_ab

tau = ID( tree, q, qd, qdd, f_ext );
qdd_ab = FDab( tree, q, qd, tau, f_ext );

tau
qdd_ab

tau = ID( tree, q, qd, qdd, f_ext, grav_accn );
qdd_ab = FDab( tree, q, qd, tau, f_ext, grav_accn );

tau
qdd_ab
R0   t   bfg      ø?t   skewi   t   tapergffffffî?gš™™™™™¹?i   i   gš™™™™™¹¿i   i   g/N P@g±�²îù?gèpTï§ðß¿gQyG<€<ø¿gS½�¥"²?g±ÛòX7ã¿gt§ÊÜÑ‡ü?g‡`èíÅó¿grÆ„dÒÂ¿gsÚ�ÔÃà?gSE:ë”ƒ@g0å’·'ž?g ¶ÃÍ¼ìÛ¿gÞ&Â˜_à?gä”9nMÎ?gV'4€hïß¿gÓŸB\H9ê?g’&¤õåî?gº«Ðd™Úã?gFô,A½é?g–_kžMØ¿gmú-q kÝ?g®ÅÍ‘†é?g$…HÉŒ×?gŠX¸ž†¬¿gf+…Žé¿g•záUÚÀ¿g‘~´cÌ?gdÌ¢éÅnê?g�¢kôàÜí?g.æUÇ¿Š§¿g™±+ä<aç?gjá 0¨Þ¿gŒYo“…ã?gW­Ÿzï¸?gü@×ðï¿gñ	q}HÜ?gˆYEI³æÉ¿g¸¶G–BÊä?gº+J†Õ?g¨Ð«Fíï¿g}†XNŠ¿g,RªÊÍ†ç?gÿl(¢Ãcà¿gÛÑ½´_Ö¿gó€øÌµç?gBê©ˆŽÅã¿g`GbHÁ?gUÏ’A„ºà¿gÊ#ñ-ìí?gCXÜJgã?g-¬)z»£º¿gZäÈùÙê¿gíªÿas×¿g¦Ûzÿ.C�?gÀê£Œ³ë?g^ª–=2é¿gê¡R³?º?gIÿ±špÚ?g_»KÕ,J¸?g Ð`Ÿ9 ä?gÓ4� ´?gHeÞ‡¯í?g¡	ƒ‘_jÊ?gêŽ4inÆ?gK¼"úe*¼¿g‘ˆyA¦È?gÂíÚUwÍ¿gâv¿gÝ]Ã?g�½�{ÖÚ¿gz˜m1áã¿g×|¼—Ÿä¿g¨°fÿ³ÞÌ?gŽ)4jÔ?gW!(wB¨¿gÅÿ‘RQ@ê¿g�·
)•|à?gJW2yè?g¾2O°¬ë?gdL¤HÞêå?g?˜«{é?g�{¢^Èë?gƒm¾kƒÉ´?goX0¥ÔË¿gÖ´dø¹FÚ?gVÑ¦g¸Ü¿gGWâ‰¹ñã?gÎÄ¸aú]æ?gìƒo…QHé?g’ahÚ5ýÆ?gòZ›òÈì?giÎhäfÄ?gzXxàÊO¹¿g8gBªë‚Ô?g¸
š=°Âï?gGÜ7*¯ê?g¾ÓÛ’ÖÅâ?gÁÒg¥fºê¿g5¶°ƒZßÌ?gâžµi$Ã›¿gdH]«¨Ð?gFä…AÀæ?g°ÃÞ·rà¿gQAVTp¡Ý?g”{[*ß€è¿g?ù}ùãá¿g5 ]‰rÚâ?g§.™toÕ¿g‰S�ë7ä?g#3¼y¥�é¿gÑ>(¢æ¿gŽm€�%Àg4žÈ„îõÀg±©P¬µc)@göWzò
3@g-¤z)5ÀgUfT¼@g3:šœ™\Þ?g�JÃœºy@gÜEafBIÀg†]Ò!Ò?gA(éòÍìº¿göû"É�6Ã¿g7ëŸO!*#ÀgSA)€€,ô?gIÏ¬T”'@gÈ2¾oï7@g­É¬Ûˆu ÀgUÃPŒú¢@gcÄ®tÑ§Ã?gVÎŒ"‚2ð?g]ºÄ¹ÀgÁˆ4ÍÄuØ?g+¥’¾à*Õ¿g–¼ø:³ã?g¿Éaó.Àg
*j-Ÿ)ÀgØJ`¥Àg“¥ŸÕ ï@gòü©In@g	y­åY®÷?gøÅÂ‘{ç¿g«�¹…ÇÃ¿gînøÇé¿gÐ-%�›úÔ?góT˜%j²Ð¿g?¶ý¦�]ë?t   modelt   qt   qdt   qddt   f_extt	   grav_accni    t   tau(   R"   R   R/   R2   t   InfR   R   t   zipt   Nonet   IDR%   R   R   R#   t   FDab(   R6   R>   R?   R@   t   ft   f_ext_givent   grav_accn_givent   expected_tausRA   RB   t   expected_tauRC   R   t   qdd_ab(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   exercise_ID_FDabc   sN   <$			%		'/	't   tst_featherstone_tmpdirc            s©   d d l  m ‰  d d  l } d d  l ‰ ˆ j j |  ƒ sJ ˆ j |  ƒ n  ˆ j |  ƒ | j j	 d d ƒ ‰ d ‡  ‡ ‡ f d † } | d d ƒ | d	 ƒ | d
 ƒ d  S(   Niÿÿÿÿ(   t	   copy_filet   module_namet   scitbxt   .c            s    ˆ  ˆ j  j ˆ |  ƒ | ƒ d  S(   N(   t   patht   join(   t	   file_namet   target(   RQ   t   ost   scitbx_dist(    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   cpT  s    s   matrix/__init__.pys   scitbx_matrix.pys    rigid_body/proto/featherstone.pys$   rigid_body/proto/tst_featherstone.py(
   t   libtbx.utilsRQ   t   libtbx.load_envRY   RU   t   isdirt   mkdirt   chdirt   envt	   dist_path(   t   tmpdirt   libtbxR[   (    (   RQ   RY   RZ   sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   exercise_standaloneL  s    
c         C   sL   t  |  ƒ d k s t ‚ t ƒ  t ƒ  t ƒ  t d  k	 rC t ƒ  n  d GHd  S(   Ni    t   OK(   R%   R   R   R8   RO   RS   RF   Re   (   t   args(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   runZ  s    
t   __main__i   (   t
   __future__R    RS   t   ImportErrorRF   t   scitbx.rigid_body.protoR   R   R   t   libtbx.test_utilsR   t   scitbx_matrixR
   t   sysR   R"   R.   R5   R8   RO   Re   Rh   t   __name__t   argv(    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/proto/tst_featherstone.pyt   <module>   s2   
								é		