Skip to content. | Skip to navigation

Personal tools

tilt.h

tilt.h

tilt.h

/////////////////////////////////////////////////////////////////////////////
// TILT.H
//
//  Last updated: 10/16/2003
//
//  Part of the source code for the M3 Program
//
//  Contains routines for motion and status of M3 Mirror Tilt motors and LVDTs
/////////////////////////////////////////////////////////////////////////////

// Tilt Stepper Motions
#define TMStop 		0
#define TMOut	       	1		// "Out" = pushing the mirror away from the frame
#define TMIn	      	2		// "In"  = pulling the mirror back to the frame

// Tilt Move Results
#define TRSuccess      	0
#define TRUserAbort  	1

// Largest number of tilt steps allowed per move
//#define TiltMax      	100

///////////////////
// Servo Constants
//
// Maximum position error: once the position servo does better than
// this error (in V), the servo turns off.
#define TiltServoError		0.02
// Steps to go for an error of 1.0 V  ... this should be lower than reality
// to insure the servo converges
#define TiltServoRatio		20
// Servo should try for this long (in seconds) and then give up
#define TiltServoTimeout  60

// Tilt Stepper Bits (for A,C,B)
// Tilt stepper drivers are wired in the following order from left to right:
// A - C - B
int TBitMon[3] = {22,16,19};
int TBitDir[3] = {23,17,20};
int TBitStep[3] = {24,18,21};

// TiltInterrupt is used for background motion (called by clock interrupt)
void TiltInterrupt();

/////////////////////////////////////////////////////////////////////////////
// CTilt - An object that represents the three Tilt motors
class CTilt {
 public:
  volatile int Motion[3],OldMotion[3];
  // Current and previous motion status (see TM bits)
  int Moving[3];
  // Flag, 1 if there's any motion at all
  int MoveStep[3];
  // Current step in move process
  int ServoAllStep;
  // Current step in servo all tilts routine
  int Dir[3],Stp[3],Mon[3],Pwr[3],Cur[3];
  // Stepper status bits
  volatile int MonStep[3];
  // Motor phases
  int InitialPulse;
  // Initial pulse in ms for the motion profile
  int TiltMax;
  // Initial pulse in ms for the motion profile
  // Defined in M3.INI file
  float Acceleration;
  // Acceleration/Deceleration in steps/sec/sec
  // Defined in M3.INI file
  float MaxVelocity;
  // Maximum velocity in steps/sec
  // Defined in M3.INI file
  float FastestStep;
  // The shortest pulse in ms the computer can generate (found by a timed test move)
  float Kstepmm;
  // Steps per millimeter ratio for each stepper motor (steps/mm)
  // (all 3 considered the same)
  // Read from INI file
  float KKA,KKB,KKC;
  // Constants given by the geometry of the M3 cell in millimeters
  // Read from INI file
  int *Profile;
  // Array describing the acceleration profile, with each array element
  // being a number of FastestSteps.
  int MaxProfile;
  // Index of highest (last) profile in the Profile array
  int BrakeTimer[3];		// Time brake release
  int StepperTimer[3];	// Time stepper power up
  // Servo variables
  int ServoTimer[3];		// Time the servo to a commanded position
  int ServoStepTimer;   // Times consecutive tilt step commands
  int ServoFlag[3];			// Flags if the tilt servo is active
  int ServoAllFlag;			// Flags when all three tilts are being servoed
  int ServoAllTimer;		// Times after an all servo command issued
  float ServoTarget[3];	// Target servo positions

  //////////////////
  // Variables for communication with the interrupt routine
  int direction[3];							// Direction of motion
  volatile int movesteps[3];		// Steps left to move
  volatile int tempsteps[3];		// Used to store step count until stepper power is ready
  volatile int pulsecount[3];		// Counts clock ticks, to set output bit appropriately
  volatile int profileindex[3];	// Position in motion profile
  volatile int tempresult[3];		// Temporary storage for return code
  volatile int moveresult[3];		// Result of motion
  volatile int abortmove[3];		// Flag to abort motion (due to user interrupt or limit)

  //////////////////
  // Tilt adjusts for ports
  float TNASW[3],TNASE[3],TAUX1[3],TAUX2[3],TAUX3[3];
  float TNaswA[100],TNaswB[100],TNaswC[100];
  //////////////////
  // Methods
  void Init();
  // Initialize all variables, perform timed motion test
  void Update();
  // Update all motion, positions, status, etc.
  void DisplayAll();
  // Display all variable information on-screen
  void DisplayBrake();
  // Display brake status on-screen
  void DisplayAnalogData();
  // Display analog tilt data on-screen
  void DisplayMotion(int tilt);
  // Display motion status on-screen
  void DisplayStepper(int tilt);
  // Display stepper status bits on-screen
  int MoveSteps(int steps,int tilt,int ServoOK);
  // Move given number of steps on tilt motor specified
  void AbortMove();
  // Abort any move in progress
  int ReleaseBrakes();
  // Releases tilt brakes
  int EngageBrakes(int MotionOK);
  // Engages tilt brakes if no tilts are moving
  int Servo(int tilt,float position);
  // Servo the tilt to the given LVDT position
  int ServoAll(float positionA,float positionB,float positionC);
  // Servo the tilts to the given LVDTs positions
 private:
  int analogcount;  				// Current analog channel (LVDT) being displayed
  int CurrentDGH;						// Current DGH module being queried/displayed
  double OldAnalogData[4];	// Previous analog LVDT data displayed
  int BrakeFlag;						// Counts how many tilts are keeping brakes off
  int OldBrake;             // Previous brake status
} Tilt;

Generated by GNU Enscript 1.6.5.2.
Document Actions