B
    ÚaÎ]ñ  ã               @   s0   d dl mZ d dlZd dlZG dd„ deƒZdS )é    )Ú	SubsystemNc               @   sV   e Zd Zdd„ Zdd„ Zdd„ Zddd	„Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚFocusc       	      C   sª   |d }|d }|d }t | j ¡ ƒ}|dkrh|dkr@t|ƒ| _|  | j|||¡}|  |¡ | j ¡ }n(|  d|||¡}| j ¡ }t 	d| ¡ | 
| j|||dœ¡ d S )	NZ	FOCOFFSETÚFILTERZTARGETÚIDLEZADJUSTr   z(Not moving focus (current position : %d))ZFOCOFFSTÚMOUNTEMPZFOCUSMODÚFOCUSENC)ÚfloatÚserverÚget_temperatureÚintÚcurrent_offsetÚfocus_modelÚmoveÚcurrent_positionÚloggingÚinfoÚappend)	ÚselfÚexposureÚfitsbuilderZ	focoffsetÚbandÚtargetr   ÚfocusZfocusenc© r   ú)/home/dice/stardice/scheduler/focusers.pyÚbefore_exposure   s"    


zFocus.before_exposurec             C   s@   | j d| | j  }|| j |d¡7 }|| j |d¡7 }|| S )Né   g        )Úfocus20Ú
temp_coeffÚdelta_filterÚgetÚdelta_targets)r   Úxr   Útempr   Zfocr   r   r   r      s    zFocus.focus_modelc             C   s†   | j  ¡ }| jjj| _| jjj| _| jjj| _| j  ¡ | _| jjj	| _
| jjj| _| jjj| _| jjj| _d| _| j  ¡ s‚tdƒ‚d S )Nr   zfocuser not correctly started)r	   Zget_allinfoÚconfigr   ÚbacklashÚinfstopÚnearstopr   ÚpositionZFOCUS20r   ZDELTA_FILTERr   ZDELTA_TARGETSr!   Z
TEMP_COEFFr   r   Zis_okÚ	Exception)r   Zallinfor   r   r   Ú_config#   s    

zFocus._configTc             C   sL   |dkrd S | j  t|ƒ¡ t d¡ |dkrHx| j  ¡ rFt d¡ q0W d S )Nr   gš™™™™™¹?T)r	   Úgor   ÚtimeÚsleepZis_stepping)r   ÚoffsetÚblockr   r   r   Ú_go2   s    
z	Focus._goc             C   s¼   | j }t d| ¡ || jks(|| jk rBt d| j| jg ¡ dS ||k rp|| j | }|  |¡ |  | j¡ n|| }|  |¡ | j 	¡ }||kr¤t
d||f ƒ‚|| _ t d| ¡ dS )z1 Move focus to given position (absolute)
        zFocuser current position : %dz&Focus position outside range: [%d, %d]z
Not movingz<expected focus position %d different from actual position %dzNew focus position: %dzFocus adjusted)r(   r   r   r&   r'   Úerrorr%   r0   r	   r   r)   )r   r(   Úcurrentr.   Únew_positionr   r   r   r   ;   s"    


z
Focus.movec             C   s0   || _ t| j ¡ ƒ}|  | j |||¡}|  |¡S )z" Adjust focal plane focus
        )r   r   r	   r
   r   r   )r   r   r   r.   r   r(   r   r   r   ÚadjustR   s    zFocus.adjustc             C   s   |   ||| jd ¡S )z? Adjust focal plane offset toward infinity by 10 steps
        é
   )r4   r   )r   r   r   r   r   r   ÚplusZ   s    z
Focus.plusc             C   s   |   ||| jd ¡S )zG Adjust focal plane offset toward nearby direction by 10 steps
        r5   )r4   r   )r   r   r   r   r   r   Úminus_   s    zFocus.minusc             C   s0   i }t | j ¡ ƒ|d< | j ¡ | _| j|d< |S )Nr   r   )r   r	   r
   r   r(   )r   Úretr   r   r   Ústatusd   s
    
zFocus.statusN)T)Ú__name__Ú
__module__Ú__qualname__r   r   r*   r0   r   r4   r6   r7   r9   r   r   r   r   r      s   
	r   )Ú
subsystemsr   r   r,   r   r   r   r   r   Ú<module>   s   