Skip to content. | Skip to navigation

Personal tools

adc.h

adc.h

adc.h

/////////////////////////////////////////////////////////////////////////////
// ADC.H
//
//  Last updated: 6/29/2006
//
//  Part of the source code for the M3 Program
//
//  Contains routines for motion and status of the ADC Rotators
/////////////////////////////////////////////////////////////////////////////

// ADC Motions
#define ADCMStop    0
#define ADCMForward 1
#define ADCMReverse 2

// ADC Motion Types
#define ADCMTNone     0
#define ADCMTSteps    1
#define ADCMTHome     2
#define ADCMTPosition 3

// ADC subMove Types
#define ADCSSteps       0
#define ADCSStopOnIndex 1

// ADC Move Results
#define ADCRSuccess   0
#define ADCRUserAbort 1
#define ADCRNoIndex   2

// ADC A Stepper Bits
#define ADCABitMon 7
#define ADCABitDir 8
#define ADCABitStep 9
#define ADCABitIndex 29
// ADC B Stepper Bits
#define ADCBBitMon 4
#define ADCBBitDir 5
#define ADCBBitStep 6
#define ADCBBitIndex 30

// Minimum number of steps to get to the index
#define ADCMinDistance 25000

// Minimum distance in steps to move pass the index
#define ADCIndexMoveOff 1000

// Two modes of operation for ADC Rotators A and B
// Auto when elevation from telescope determines their position
#define ADCSManual 0
#define ADCSAuto 1

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

// Elevation coming from TCS using eds message J5
double telel = 0.0;

// Move both ADCs to the given position (in degrees)
int MovePositionCombined(double targetposition);

// One of the two operation modes above
int ADCRotatorsMode,OldADCRotatorsMode;
// Calculate ADC rotators angle as a function of telescope elevation angle
int ADCRotatorsAngle();

/////////////////////////////////////////////////////////////////////////////
// CADC - an object that represents one of the two ADC rotators
class CADC {
  public:
  volatile int Motion,OldMotion;
  volatile int Index,OldIndex;
  // Current and previous motion and index states
  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
  int Dir,Stp,Mon,Pwr,Cur;
  // Stepper status bits
  int DirBit,StpBit,MonBit,IndexBit;
  // Identifies which digital I/O bits to use for this rotator's stepper
  int StepsPerRevolution;
  // Number of steps for exactly one revolution
  int ADCHomeExpectedSteps;
  // Number of Steps the software thinks are left to trigger the home sensor
  // Created to check if there are steps lost when positioning the rotators
  int Y1,Y2;
  // Y1 is the Y coordinate for the index/position on-screen,
  // Y2 is the Y coordinate for the stepper bits on-screen
  int CW;
  // Tells whether a forward step produces a clockwise rotation on
  // this rotator.
  int R1,R2;
  // Inner and outer radii for the index cartoon
  float IndexAngle;
  // Angle in degrees from +X axis onscreen to ADC Index mark
  volatile int MonStep;
  // Keeps track of motor phase
  int Homed,OldHomed;
  // Current and previous flags for whether or not we've passed an index
  int Position,OldPosition;
  // Current and previous position in steps from the index
  int InitialPulse;
  // Initial pulse in motion profile in ms
  float Acceleration;
  // Acceleration for motion profile in steps/s/s
  float MaxVelocity;
  // Maximum veocity in steps/s
  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

  //////////////////
  // Variables for communication with the interrupt routine
  int direction;             // Direction of motion
  int sign;                  // Sign of direction to move for homing
  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 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)
  volatile int position;            // stores relative position
  volatile int positionbeforeindex; // debug variable, to calculate count/rev factor and
                                     // to check if we are loosing steps
  volatile int adchomereadsteps; // Number of Steps actually taken to trigger the home sensor
                                  // Created to check if there are steps lost when positioning the rotators

  //////////////////
  // Methods
  void Init(int dirBit,int stpBit,int monBit,
            int indexBit,int y1,int y2,int cw,int r1,int r2,float indexAngle);
  // Initialize all variables, perform timed motion test.
  // See ADC class variable descriptions for argument descriptions.
  void Update();
  // Update all motion and status
  void DisplayAll();
  // Display all status on-screen
  void DisplayMotion();
  // Display motion status on-screen
  void DisplayIndex();
  // Display index status on-screen
  void DisplayPosition();
  // Display position on-screen
  void DisplayMode();
  // Display motion mode on-screen
  void DisplayStepper();
  // Display Stepper bits on-screen
  void DrawCartoon(int Angle,int Color);
  // Draw cartoon at given angle and color on-screen
  int Home();
  // Move ADC until the index is hit (-> home it).
  int MoveSteps(int steps,int StopOnIndex);
  // Move given steps.  Set StopOnIndex to 1 to have routine stop after
  // passing the index mark.
  int MovePosition(double targetposition);
  // Move to the given position (in degrees)
  void AbortMove();
  // Abort any move in progress

  private:
  // These are Home/MoveSteps/MovePosition subroutines
  void subMoveSteps(int steps,int StopOnIndex);
  // Move given number of steps, sign determines direction
} ADCA,ADCB;
// ADCA represents the inner (closer to the beam) ADC,
// ADCB is the outer (outside of the ADC turret) ADC.


Generated by GNU Enscript 1.6.5.2.
Document Actions