Skip to content. | Skip to navigation

Personal tools




//  Last updated: 4/24/2005
//  Part of the source code for the Remote 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   200

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

// Tilt Stepper Bits (For A,B,C)
int TBitMon[3] = {8,9,10};
int TBitDir[3] = {0,1,2};
int TBitStep[3] = {16,17,18};
int TBitCur[3] = {3,3,3};
int TBitPwr[3] = {4,4,4};
int TBitBrk[3] = {5,5,5};

// Tilt setpoints for observing ports, in volts
float TNASW[3] = {0,0,0};
float TNASE[3] = {0,0,0};
float TAUX1[3] = {0,0,0};
float TAUX2[3] = {0,0,0};
float TAUX3[3] = {0,0,0};
float TNaswA[100],TNaswB[100],TNaswC[100];

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

// CTilt - An object that represents the three Tilt motors
class CTilt {
  volatile int Motion[3];
  // Current 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],Brk[3];
  // Stepper status bits
  volatile int MonStep[3];
  // Motor phases
  int InitialPulse;
  // Initial pulse in ms for the motion profile
  float Acceleration;
  // Acceleration/Deceleration in steps/sec/sec
  float MaxVelocity;
  // Maximum velocity in steps/sec
  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)
  float KKA,KKB,KKC;
  // Constants given by the geometry of the M3 cell in millimeters
  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
  unsigned long BrakeTimer[3];		// Time brake release
  unsigned long StepperTimer[3];	// Time stepper power up
  // Servo variables
  unsigned long ServoTimer[3];		// Time the servo to a commanded position (msecs)
  unsigned long ServoStepTimer;   // Times consecutive tilt step commands (msecs)
  int ServoFlag[3];			// Flags if the tilt servo is active
  int ServoAllFlag;			// Flags when all three tilts are being servoed
  unsigned long ServoAllTimer;		// Times after an all servo command issued (msecs)
  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)

  // Methods
  void Init();
  // Initialize all variables, perform timed motion test
  void Update();
  // Update all motion, positions, status, etc.
	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
  int BrakeFlag;  // Counts how many tilts are keeping brakes off
} Tilt;

Generated by GNU Enscript
Document Actions