Skip to content. | Skip to navigation

Personal tools




//  Last updated: 3/16/2007
//  Part of the source code for the M3 Program
//  Contains routines for motion and status of the ADC (outer) turret

// ADC Turret Motions
#define ATMStop    0
#define ATMForward 1
#define ATMReverse 2

// ADC Turret Move Types
#define ATMTNone     0
#define ATMTSteps    1
#define ATMTHome     2
#define ATMTPosition 3

// ADC Turret subMove Types
#define ATSSteps     0
#define ATSSlowIndex 1

// ADC Move Results
#define ATRSuccess       0
#define ATRUserAbort     1
#define ATRHitLimit      2
#define ATRNoIndex       3
#define ATRHitLimitIndex 4

// ADC Turret Limits
#define ATLNone    0
#define ATLForward 1 // "ADC"    - ADC in-line with mirror
#define ATLReverse 2 // "No ADC" - ADC not in-line with mirror
#define ATLBoth    3

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

// ADC Turret Positions
#define ATPUnknown 0
#define ATPMidway  1
#define ATPForward 2
#define ATPReverse 3
#define ATPIndex   4

// ADC Turret Cartoon Positions:
//  0 = None
//  1 = No ADC Nas W
//  2 = No ADC Aux 1
//  3 = No ADC Aux 2 or ADC Nas W
//  4 = No ADC Aux 3 or ADC Aux 1
//  5 = No ADC Nas E or ADC Aux 2
//  6 = ADC Aux 3
//  7 = ADC Nas E

// ADC Turret Stepper Bits
// ATBitForward (34) was rewired during 8/03
// engineering as part of the latches sensing circutry.
// ADC Turret then, does not have end of travel limit in the forward dir.
#define ATBitMon 10
#define ATBitDir 11
#define ATBitStep 12
#define ATBitReverse 33
#define ATBitIndex 28

// Minimum number of steps to go between the two ADC positions
#define ATMinDistance -60000
// Slighlty fewer steps than necessary to go from one position to the next
#define ATPosToPosDistance 54000
// The number of extra steps needed to actually get to a position
#define ATExtraDistance 6000
//Number of extra steps to move out of reverse limit
#define ATExtraDistanceNoADC -500
// Distance from the edge of an index to the center
#define ATHalfIndexWidth 200

// CADCTurret - Object representing the outer turret of the M3
class CADCTurret {
        int Motion,OldMotion;
        // Current and previous motions (see ATM bits)
  int Moving;
        // Flag, 1 if there's any motion
  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;
        // Current limit status (see ATL bits)
        volatile int Index,OldIndex;
        // Current index status
        int Dir,Stp,Mon,Pwr,Cur;
        // Current motor stepper status bits
        volatile int MonStep;
        // Current motor stepper phase (+/- counts from when Mon bit is on)
  int FwdLimitCount;
  int RevLimitCount;
        // Count how many times we've seen a limit high, to debounce
        int Position,OldPosition;
        // Current and previous position (see ATP bits)
        int CartoonPosition,OldCartoonPosition;
        // Current and previous cartoon position
        int InitialPulse;
        // Size of initial pulse in motion profile in ms
        int EmergencyStopDistance;
        // Distance in steps to go on an emergency stop of a move
        float Acceleration;
        // Acceleration for motion profile in steps/s/s
        float MaxVelocity;
        // Maximum velocity in steps/s
        float FastestStep;
        // The shortest pulse in ms the computer can generate (found by a timed test move)
        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

  // Variables for communication with the interrupt routine
  int limitbit;                                                         // Limit bit to watch for
  int direction;                                                        // Direction of motion
  int tempsteps;                                                        // Used to store step count until stepper power is ready
  int submove;                                                          // Motion type we want interrupt to provide
  volatile int movesteps;                       // Steps left to move
  volatile int indexflag;                       // Mark when we first see an index
  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)

  // 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
        int Home();
        // Home the turret
        int MoveSteps(int steps);
        // Move the turret the given number of steps
        int MovePosition(int position);
        // Move the turret to the commanded position
  void AbortMove();
  // Abort any move in progress
        int CheckLimit(int limitbit);
        // Returns a 0 on limit not hit, 1 on limit hit

  // These are Home/MoveSteps/MovePosition subroutines
        int subMoveSteps(int steps);
        // Move given number of steps, 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.

Generated by GNU Enscript
Document Actions