Skip to content. | Skip to navigation

Personal tools

cell.h

cell.h

cell.h

/////////////////////////////////////////////////////////////////////////////
// CELL.H
//
//  Last updated: 6/24/2000
//
//  Part of the source code for the Vane End Actuator Control System
//
//  This file contains all variables/constants/functions for updating
//  the mirror cell.
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Physical Constants

// Correction factor for global XY positioning (should be ~1.175)
float FixXY;
// Correction factor for global Z positioning
float FixZ;
float FixH;
float FixV;
// Number of microns to move vane ends in from zero point to tension them
int TensionAmount;

// Backlash constants
int BacklashMove; 		// Number of microns at the encoder to move on each backlash
											//  removal attempt
int BacklashTime; 		// Time in ms to accomplish the move in
int BacklashTimeout;  // Time in ms to wait for the move to complete before
											//  flagging an error
int BacklashDelay;		// Time in ms to wait after the move is complete
int BacklashTarget;		// Minimum number of microns of motion at the encoder
											// required for backlash to be considered removed

// Macro move constants
int MacroMove;	 	// Number of microns at the encoder to move in each macro
									//  movement
int MacroTime;   	// Time in ms to accomplish the move in
int MacroTimeout; // Time in ms to wait for the move to complete before
									//  flagging an error
int MacroDelay;		// Time in ms to wait after the move is complete

// Micro move constants
int MicroTime;		// Time in ms to accomplish the move in
int MicroTimeout; // Time in ms to wait for the move to complete before
									//  flagging an error
int MicroDelay;   // Time in ms to wait after the move is complete

// Movement thresholds
int BacklashThreshold;  // Minimum number of microns between current and
												//  target locations for attempting backlash removal
int MacroThreshold;     // Minimum number of microns between current and
												//  target locations to trigger a macro move
float MacroError;				// Minimum fraction (0.0 to 1.0) of the commanded
												// 	macro move that the encoders must actually move
												//  byto avoid an error

// Distance in microns from center of secondary mirror to vane end
// to actuator attachment point (center of the vane end pivot)
//double Radius = 3403651.0;
double Radius = 3403694.0;
double Radius2 = Radius * Radius;
double RadiusXY = Radius / sqrt(2.0);
// Distance in microns from vane attachment point on cage to the
// actuator attachment point
double VaneRadius = 2391130.6;
double VaneRadius2 = VaneRadius * VaneRadius;

// Angle from horizontal (x) axis to the vanes
double Angle = 45 * PI / 180;

// Global X and Y coordinates of the cage corners
double CageX = 34.9 * 25400;
double CageY = 20.958 * 25400;

// Global X and Y coordinates of the vane ends
double VaneX = 101.47 * 25400;
double VaneY = 87.524 * 25400;

// X and Y offset from Cage Corner to Vane End
double VaneXY = 1690784.662;

// Current number of encoder errors and max number of encoder errors
int EncoderErrors = 0; 			// Counts the number of failed encoder reads
														// since the last successful read
int MaxEncoderErrors = 4;		// Maximum number of consecutive encoder errors
														// before suspending error messages
int FatalEncoderErrors = 1; // Maximum number of consecutive encoder errors
														// before flagging a fatal error

/////////////////////////////////////////////////////////////////////////////
// Vector/Matrix Type Definitions

typedef float vector[3]; 			/* vector and matrix are used to calculate */
typedef double matrix[3][3];	/* destination vane-end positions */

////////////////////////////////////////////////////////////////////////////
// Calculation Functions -
//	Encoders -> Global Coordinates, Global Coordinates -> Encoder Values
////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
// mmult: Multiply a vector by a matrix
void mmult(matrix m,vector v);
// Multiplies the vector v by matrix m.
// The result is returned in vector v.

/////////////////////////////////////////////////////////////////////////////
// AERAtoXY: Convert encoder readings to local XY coordinates
void AEREtoXY(int AE,int RE,float* X,float* Y);
// Pass this encoder values in AE and RE (in microns).
// Note that the encoder values should have had their zero positions
// subtracted off, i.e. call AEREtoXY(AE[0]-ZAE[0],RE[0]-ZRE[0],X,Y).
// It will return the position of the vane end in the actuator's
// plane of motion in X and Y (in inches), X = radial, Y = axial,
// where X=0,Y=0 is the actuator's zeroed location (at ZAE[],ZRE[]).

/////////////////////////////////////////////////////////////////////////////
// XYtoAERE: Convert local XY coordinates to encoder readings
void XYtoAERE(float X,float Y,int* R1,int* R2);
// Pass it the destination X and Y (in inches) in the actuators plane
// of motion, and it returns the needed values of AE and RE (encoder values)
// X is radial motion, and Y is axial motion.  Note that you'll have to add
// the zeroed encoder values to the AE and RE this routine returns.
// ie, call XYtoAERE(X,Y,AE[0],RE[0]) and then AE[0]+=ZAE[0],RE[0]+=ZRE[0].

/////////////////////////////////////////////////////////////////////////////
// VaneCalc: Convert global xy coordinates to a local vane end x coordinate
float VaneCalc(float dx,float dy,int corner);
// Returns the necessary radial vane end position (X value) for the cell
// to move by dx,dy (in global coordinates, in microns).
// corner should be 0 = NW,1 = SW,2 = SE,3 = NE

/////////////////////////////////////////////////////////////////////////////
// CCell: An object representing the entire mirror cell
class CCell
{
	public:

	float x,y,z,h,v;
	// These represent the five degrees of freedom for secondary mirror,
	// and store its current location.
	// Assuming the telescope is pointed at the horizon:
	// x: displacement of mirror from dead center parallel to the ground (in microns)
	// y: displacement of mirror from dead center perpendicular to ground (in microns)
	// z: displacement of mirror from dead center axially (in microns)
	// h: rotation of mirror about an axis horizontal to the ground (in arc-seconds)
	// v: rotation of mirror about an axis vertical to the ground (in arc-seconds)
	float dx,dy,dz,dh,dv;
	// Same as x,y,z,h,v, except these store the current destination coordinates
	// the mirror is headed for.
	int AE[4],RE[4];
	// Current axial (AE) and radial (RE) encoder readings in microns.
	// AE[0] and RE[0]: Northwest corner
	// AE[1] and RE[1]: Southwest corner
	// AE[2] and RE[2]: Southeast corner
	// AE[3] and RE[3]: Northeast corner
	// These array index:cell corner mappings are consistent throughout the
	// program.
	int AEOK[4],REOK[4];
	// Flags for the status of the axial and radial encoder readings..
	// 0 = OK (green), 1 = near limits (yellow), 2 = beyond limits (red)
	int DAE[4],DRE[4];
	// These arrays hold the destination (Target) axial and radial
	// encoder readings in microns, required for us to get to the target
	// dx,dy,dz,dh,dv coordinates.
	int DAEOK[4],DREOK[4];
	// Flags for the status of the target axial and radial encoder readings..
	// 0 = OK (green), 1 = near limits (yellow), 2 = beyond limits (red)
	int ZAE[4],ZRE[4];
	// These are the zero locations of the encoders, read from VANE.INI,
	// which correspond to the global location x=0,y=0,z=0,h=0,v=0.
	int MaxAE[4],MaxRE[4];
	// These are the maximum allowable readings the encoders can have
	// before the software halts further motion
	int MinAE[4],MinRE[4];
	// These are the minimum allowable readings the encoders can have
	// before the software halts further motion
	int AS[4],RS[4];
	// Current axial (AS) and radial (RS) switch readings.
	// AS[0] and RS[0]: Northwest corner
	// AS[1] and RS[1]: Southwest corner
	// AS[2] and RS[2]: Southeast corner
	// AS[3] and RS[3]: Northeast corner
	int AM[4],RM[4];
	// Current axial and radial motion flags. 0 = none, 1 = up, 2 = down
	// AM[0] and RM[0]: Northwest corner
	// AM[1] and RM[1]: Southwest corner
	// AM[2] and RM[2]: Southeast corner
	// AM[3] and RM[3]: Northeast corner
	int CornerX[4],CornerY[4];
	// These hold screen X,Y coordinates for the display of each vane end's
	// current information on-screen
	int DGHIndex;
	// Holds the index of the current DGH being polled for its tension.
	// The DGHs read out relatively slowly, so only one is queried during
	// each loop of Cell.Update.

	CDGH DGHs[17];

	// The 8 vane DGHs for axial and radial tensions
	// DGHs[0]: NW Axial, address = 'a'
	// DGHs[1]: SW Axial, address = 'b'
	// DGHs[2]: SE Axial, address = 'c'
	// DGHs[3]: NE Axial, address = 'd'
	// DGHs[4]: NW Radial, address = 'e'
	// DGHs[5]: SW Radial, address = 'f'
	// DGHs[6]: SE Radial, address = 'g'
	// DGHs[7]: NE Radial, address = 'h'

	// The 3 F11 DGHs, all three for axial weight readings
	// DGHs[8]: F11 load cell, address = 'i'
	// DGHs[9]: F11 load cell, address = 'j'
	// DGHs[10[: F11 load cell, address = 'k'

	// The 6 F5 DGHs, three for axial and three for lateral weight
	// readings
	// DGHs[11]: F5 axial load cell, address = 'l'
	// DGHs[12]: F5 lateral load cell, address = 'm'
	// DGHs[13]: F5 axial load cell, address = 'n'
	// DGHs[14]: F5 lateral load cell, address = 'o'
	// DGHs[15]: F5 axial load cell, address = 'p'
	// DGHs[16]: F5 lateral load cell, address = 'q'

	void Init(); // Initializes all CCell variables and the DGHs
	void Update();
	// Update does a number of things. It:
	// - Reads the tensions
	// - Reads the encoders
	// - Checks for any fatal errors
	// - Executes move commands if a move is in progress
	void AllVacOffPresOn();
	// Turns all vacuum off vacuum and pressure on all four corners
	int Home();
	// Home homes the encoders (using the vacuum retraction system),
	// which is necessary before normal program operation.  Homing sets
	// the encoder readings at 0 for their fully retracted position.
	// Returns a 0 on success, 1 on failure
	int HomeEncoders();
	// Homes the vane end encoders, returns a 0 on success
	void DisplayAll();
	// Re-displays all encoder, tension, and global coordinate readings
	void DisplayGlobal();
	// Displays current global coordinates
	void DisplayDestination();
	// Displays destination axial, radial, and global coordinates
	void DisplayAxialMove(int Moves[4]);
	// Displays axial movement flags onscreen for all four corners
	void DisplayRadialMove(int Moves[4]);
	// Displays radial movement flags onscreen for all four corners
	void UpdateTensions();
	// Read and display tensions, returns a 0 on success
	int UpdateEncoders();
	int BUpdateEncoders();
	// Reads all current encoder positions, returns a 0 on success
	void GetXYZHVFromEncoders();
	// Converts current encoder readings to current global coordinates

	private:

	void DisplayAxialEncoder(int Corner);
	// Displays one current axial encoder reading
	void DisplayRadialEncoder(int Corner);
	// Displays one current radial encoder reading
	void DisplayAxialSwitch(int Corner);
	// Displays current axial limit switches
	void DisplayRadialSwitch(int Corner);
	// Displays current radial limit switches
	int RemoveBacklash(int A[4],int R[4]);
	// Removes backlash if necessary on the commanded axes
	int CheckFatal();
	// CheckFatal checks for fatal errors. It does the folowing:
	// - Reads one of the DGH tensions
	// - Checks to see if tensions are within allowable limits
	// - Checks to see if encoder readings are within allowable limits
	// - Checks to see if the emergency stop card was triggered
	// - Checks to see if motor controllers are overheating
	// CheckFatal returns a 0 if it communicated successfully with all devices,
	// or a 1 if an error occurred in communication.
	// CheckFatal sets any appropriate fatal flags if they occurred.
	int Move();
	// Gives the DMCs the necessary commands to move towards the current
	// destination.  Returns a 0 on success
	void GetDestination(float newx,float newy,float newz,float newh,float newv,
											int NewDAE[4],int NewDRE[4]);
	// Converts global coordinates newx, newy,etc to the associated encoder
	// readings NewDAE,NewDRE
} Cell;

/////////////////////////////////////////////////////////////////////////////
// PauseUpdate - waits until Update has reached a safe pausing point
void PauseUpdate();

Generated by GNU Enscript 1.6.5.2.
Document Actions