Skip to content. | Skip to navigation

Personal tools

mturret.h

mturret.h

mturret.h

/////////////////////////////////////////////////////////////////////////////
// MTURRET.H
//
//  Last updated: 10/31/2003
//
//  Part of the source code for the M3 Program
//
//  Contains routines for motion and status of the M3 (inner) turret
/////////////////////////////////////////////////////////////////////////////

// M3 Turret Motions
#define MTMStop 		0
#define MTMForward 	1
#define MTMReverse	2

// M3 Turret Move Types
#define MTMTNone			0
#define MTMTSteps			1
#define MTMTHome			2
#define MTMTPosition	3

// M3 Turret subMove Types
#define MTSSteps    				0
#define MTSSlowIndex  			1
#define MTSStopOnIndex			2
#define MTSStepsPastIndex		3

// M3 Move Results
#define MTRSuccess			0
#define MTRUserAbort  	1
#define MTRHitLimit			2
#define MTRNoIndex			3

// M3 Turret Limits
#define MTLNone 				0
#define MTLForward 			1
#define MTLReverse  		2
#define MTLBoth 				3

// Cycles a limit must be active to be reported as active
//#define MTDebounceLimit 5

// M3 Turret Positions
#define MTPUnknown  		0
#define MTPMidway  			1
#define MTPReverse  		2  // NAS E
#define MTPReverseAux		3  // AUX 1
#define MTPMiddleAux   	4  // AUX 2
#define MTPForwardAux   5  // AUX 3
#define MTPForward  		6  // NAS W

// M3 Turret Cartoon Positions
#define MTCPNone				0
#define MTCPNasWDown		1
#define MTCPAux1Down		2
#define MTCPAux2Down		3
#define MTCPAux3Down		4
#define MTCPNasEDown		5
#define MTCPNasWUp			11
#define MTCPAux1Up			12
#define MTCPAux2Up			13
#define MTCPAux3Up			14
#define MTCPNasEUp			15

// M3 Turret Stepper Bits
// MTBitForward (31) and MTBitReverse (32) rewired during 8/03 engineering
#define MTBitMon 13
#define MTBitDir 14
#define MTBitStep 15
#define MTBitIndexA 25
#define MTBitIndexB 26
#define MTBitIndexC 27

/*
// Are read from M3.INI
// These were all changed from the original values since the pulleys
// that drive the M3 turret were changed and the ratio went from
// 1:1 to 8:3. That means that original values had to be multiplied by 2.7.
// Minimum number of steps necessary to always get to the next M3 Turret index
#define MTMinIndexDistance 40500
// The approximate number of steps between an Aux index and a Nas index
#define MTAuxToNasDistance 32400
// The approximate number of steps between two Aux indices
#define MTAuxToAuxDistance 14850
// The minimum number of extra steps needed to actually get to an index
#define MTExtraDistance 8100
// Distance from the edge of an index to the center
#define MTHalfIndexWidth 320
*/

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

/////////////////////////////////////////////////////////////////////////////
// CM3Turret - An object representing the inner rotating turret
class CM3Turret {
	public:
	int Motion,OldMotion;
	// Current and previous turret motions (see MTM bits)
  int Moving;
  // Flag, 1 if there's any motion at all
  int MoveType;
  // Type of any current high level motion
  int MoveStep;
  // Current step in high level move process
  int SubStep;
  // Current step in a low level process
	volatile int Limit,OldLimit;
	// Limit switches (see MTL bits)
	volatile int Index,OldIndex;
	// Current and previous state of all index bits
	int IndexA,IndexB,IndexC;
	// States of each index bit
	int Dir,Stp,Mon,Pwr,Cur;
	// Stepper motor controller bits
	volatile int MonStep;
	// Steps since stepper last flagged Moni bit
  int FwdLimitCount;
  int RevLimitCount;
	// Count how many times we've seen a limit high, to debounce
	int Position,OldPosition;
	// Current and previous turret positions (see MTP bits)
	int CartoonPosition,OldCartoonPosition;
	// Current and previous turret cartoon positions (see MTCP bits)
	int InitialPulse;
	// Duration of first stepper pulse in ms, usually 50 ms
	int EmergencyStopDistance;
	// Maximum number of steps to allow during an emergency stop deceleration
	float Acceleration;
	// Acceleration/Deceleration in steps/sec/sec
	float MaxVelocity;
	// Maximum velocity in steps/sec
	float FastestStep;
	// The shortest pulse in seconds the computer can generate
	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

  // Minimum number of steps necessary to always get to the next M3 Turret index
  int MTMinIndexDistance;
  // The approximate number of steps between an Aux index and a Nas index
  int MTAuxToNasDistance;
  // The approximate number of steps between two Aux indices
  int MTAuxToAuxDistance;
  // The minimum number of extra steps needed to actually get to an index
  int MTExtraDistance;
  // Distance from the edge of an index to the center in the forward dir
  int MTHalfIndexWidthFwd;
  // Distance from the edge of an index to the center in the reverse dir
  int MTHalfIndexWidthRev;

  int GroupFlag; // tells if we are doing a combined move (m3-tilts)

  //////////////////
  // Variables for communication with the interrupt routine
  int direction;		// Direction of motion
  int submove;			// Motion type we want interrupt to provide
  volatile int movesteps;		// Steps left to move
  volatile int tempsteps;		// Used to store step count until stepper power is ready
  volatile int extrasteps;		// Steps to move beyond the last index
  volatile int indexflag;		// Mark when we first see an index
  volatile int indexleft;		// Indexes left we want to pass
  volatile int pulsecount;		// Counts clock ticks, to set output bit appropriately
	volatile int profileindex;	// Position in motion profile
  volatile int tempresult;		// Temporary storage for return code
  volatile int moveresult;		// Result of motion
  volatile int abortmove;		// Flag to abort motion (due to user interrupt or limit)
  // Variables just for MovePosition
	int indexnum;		 	// Number of indices we have to pass on the way to the target
	int distance; 		// Steps at full speed past the last index towards our target
	int extradistance;// Slow steps to get to our final target

  //////////////////
  // 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 DisplayMotion();
	// Display turret motion on-screen
	void DisplayLimit();
	// Display limit switch status on-screen
	void DisplayIndex();
	// Display index switch status on-screen
	void DisplayPosition();
	// Display turret position on-screen
	void DisplayStepper();
	// Display motor stepper status bits on-screen
	void DisplayCartoon();
	// Display turret cartoon on-screen
	void DrawCartoon(int Position,int Color);
	// Draw the turret cartoon for Position in Color.. used to erase last
	// cartoon and draw the new cartoon
	int Home();
	// Home the turret
	int MoveSteps(int steps,int MotionOK);
	// Move given number of steps, sign determines direction
	int MovePosition(int position);
	// Move turret to given position
  void AbortMove();
  // Abort any move in progress
	int CheckLimit(int limitbit);
	// Returns a 0 on limit not hit, 1 on limit hit

  private:
  // These are Home/MoveSteps/MovePosition subroutines
	int subMoveSteps(int steps);
	// Move given number of steps, sign determines direction
	int subMoveAndStopOnIndex(int indexcount);
	// Move given number of indexes and stop, sign determines direction
	int subMoveSlowToIndex(int steps);
	// Move towards an index at a slow enough speed to stop right in the middle
	// of the index mark.
	int subMoveStepsPastIndex(int indexcount,int Extrasteps);
	// Move given number of indexes, and then move extrasteps further
};


Generated by GNU Enscript 1.6.5.2.
Document Actions