
    y<j                     Z   d Z ddlZddlZddlmZmZmZmZm	Z	 ddl
mZmZmZ  ej                  g d      dz  Zd\  ZZZZZdZd	Zd
dddddZd Zd Zd Zd Zedk(  rMej;                         D ]9  \  ZZ ee      Z de dZ! ee e!        e"de! de jF                  rdnd d       ; yy)aK  Parametric build123d connector for the SO-100 modular arm (Phase 2 / structural).

One printable solid per inter-servo link, built directly in the CHILD link frame (mm):
  - COLLAR: cylinder around the PARENT servo output axis at the link origin (grips the driven horn).
  - BEAM:   thick rod from the parent output (origin) to THIS link's servo BODY (so it grips the body
            it carries; the servo OUTPUT stays free to drive the next joint).
  - BOSS:   cylinder at the servo body, embracing the holder so the connection actually mates.
Union -> watertight solid -> STL (mm). Length adapts per joint. Thick by design (bears load).

Target is the servo BODY CENTRE (not the output point): the output horn sticks ~18mm beyond the
holder, so a beam to the output would leave a gap. Body centre guarantees the connector grips the holder.
    N)VectorCylinderAxis
export_stlfillet)JOINTSROLLS
servo_pose)gffffff@g333333#             @@)g      "@g      .@g      >@g      0@g      6@g       @g      @shoulder	upper_arm	lower_armwristgripper)               c                    t        ddd      }t        | j                         }t        j                  t        j                  t        dt        d|j                  |                              }|j                  |      }|j                  dk  rt        ddd      }| j                  t        dt        |            |      S )Nr   r   g      g      ?g&.>)r   r   r   )r   
normalizedmathdegreesacosmaxmindotcrosslengthrotater   tuple)solidaxis_veczaangaxs         :/data/cameron/repos/smith300_para_stuff/so100_connector.py_orientr*      s    q!QA$$&A
,,tyyT3sAEE!H+=!>?
@C	
B	yy4Aq!_<<Yb	2C88    c                 B   t        |  t        | }} || z
  }t        t        ||j                        t	        |            }|j                  | j                  |j                  z   dz  | j                  |j                  z   dz  | j                  |j                  z   dz  f      S )Nr   )	r   r*   r   r    r"   	translateXYZ)p1p2rvrods        r)   _rodr6   #   s    R[&"+B
RA
(1ahh'q
2C==244"$$;!+bddRTTkQ->PQ@QRSSr+   c                 ^    t        t        ||      |      j                  t        |             S )N)r*   r   r-   r"   )centeraxisr3   hs       r)   _cyl_atr;   *   s$    8Aq>4(225=AAr+   c                 0   t         |    \  }}}}}}}}t         | dz
     d   }t        |||t        |          \  }}	|j                  t              |	z   dz  }
d}t        ||t        t              t        ||t        t        dz         z
  }t        |t        |
      t              }t        |
 j                         }t        t        |
      t        |      t        t              }||z   |z   }	 t!        |j#                         t$              }|S # t&        $ r Y |S w xY w)zHk = child link index (1..5); connector built in child link k frame (mm).r   r   r   )r   r   r   r   )r   r
   r	   applyHOLDER_Cr;   COLLAR_RCOLLAR_HBORE_Rr6   r"   ROD_Rr   r   BOSS_RBOSS_Hr   edgesFILLET_R	Exception)k_xyzrpyr9   lohipaR_st_sBAcollarbeamubossr#   s                    r)   buildrW   .   s	   &,Qi#Aq!S#tR	Aq	B#sD%(3HC	8	s	"f,AAQHh/'!RTU2VVF58U#D
A58U1Xvv6DTMD Eu{{}h/ L  Ls   (D 	DD__main__so100_conn_z.stlzwrote z  (validINVALID))$__doc__r   numpynp	build123dr   r   r   r   r   
so100_parar   r	   r
   arrayr>   rB   r?   r@   rC   rD   rA   rF   CHILD_OFr*   r6   r;   rW   __name__itemsrH   childr#   fprintis_valid r+   r)   <module>rk      s      @ @ 0 0288$%.,G )x66	kkg)T9TB& zNN$5a%%5!qcWIFaHI	 % r+   