Main Page | Data Structures | File List | Data Fields | Globals

clientutils.c File Reference

Client application utility functions. More...

#include "client.h"

Functions

int FWPos (int encpos, int npos, int offset)
 convert the current filter wheel encoder position into beam and load positions.


Detailed Description

Client application utility functions.

Because they have to go somewhere...

Author:
R. Pogge, OSU Astronomy Dept. (pogge@astronomy.ohio-state.edu)
Date:
2004 Mar 13

Function Documentation

int FWPos int  encpos,
int  npos,
int  offset
 

convert the current filter wheel encoder position into beam and load positions.

Parameters:
encpos Current encoder position
npos Number of valid positions, number 1-N
offset Offset between the beam/load and encoder position
Returns:
The filter position corresponding to encpos, or -1 if the encpos is invalid (e.g., out-of-range).
On various filter wheels, the location of the position encoders does not exactly align with the beam or load positions, depending on the device packaging details. FWPos() converts the current position into the specified offset position (beam or load, typically), performing the correct modular arithmetic. This operation is sufficiently common (and sufficiently easy to get wrong) that we encapsulate it in a separate client utility function.

Algorithm:

if (offset < 0) offset += npos; pos = 1 + (encpos + offset) % npos ; return pos;
Key features are that all rotary-indexed mechanisms we build have fixed positions that are numbered 1-relative (i.e., 1..npos, not 0..npos-1). A negative offset has to be "wrapped" using the number of positions.

You'd be very surprised how long it took to get this right. Modular arithmetic in a rotary (cyclic) mechanism makes my head hurt.


Generated on Thu Jul 22 19:58:41 2004 for Filter Wheel Agent by doxygen 1.3.7