Skip to content. | Skip to navigation

Personal tools

ir.h

ir.h

ir.h

/////////////////////////////////////////////////////////////////////////////
// IR.H
//
//  Last updated: 7/29/2005
//
//  Part of the source code for the Vane End Actuator Control System
//
//  This file contains all variables/constants/functions for updating
//  the instrument rotators.
/////////////////////////////////////////////////////////////////////////////

// The IRs (so far) are connected to the Vane End computer according to:
// NASW-COM3, NASE-COM4, CASS-COM5, AUX1/AUX2/AUX3-COM6
// Each is a Galil motion controller.
#define NASWIRPORT 2
#define NASEIRPORT 3
#define CASSIRPORT 4
#define AUX1IRPORT 5
#define AUX2IRPORT 5
#define AUX3IRPORT 5

// Instrument rotator indices (also their Galil address)
#define IRNASW 0
#define IRNASE 1
#define IRCASS 2
#define IRAUX1 3
#define IRAUX2 4
#define IRAUX3 5

// Limit definitions
#define IRLNone 0		// No limit
#define IRLCW   1		// Clockwise limit
#define IRLCCW  2		// Counterclockwise limit
#define IRLBoth 3		// Both limits (error)

// Motion defintions
#define IRMNone	0		// No motion
#define IRMCW   1		// Clockwise motion
#define IRMCCW  2		// Counterclockwise

// Zone definitions
#define IRZCW   0		// Clockwise half
#define IRZCCW  1		// Counterclockwise half

// Commands to send to the active IR before going to the next enabled IR
#define ActiveCommandCount 6
// Commands to send to inactive but enabled IRs before going to the next IR
#define InactiveCommandCount 3

// Number of instrument rotators
#define NumberIRs 6

// Line number of main loop in IRSERVO.DMC (speed servo code)
#define IRServoMain 11

// Allowable error for the ineternal servo in encoder counts
// For now the equivalent to 0.0056 degrees or 20 arcsecs
#define ErrorTolerance 457
// Time in msecs the internal servo has been within the ErrorTolerance
#define TimeTolerance 3000

// Renishaw encoder levels of reading.
// The analog signal Set-Up tells how good is the readhead allignment with the tape.
// Two thresholds: good (reading reliable), bad (needs calibration)
#define EncoderOK  3.5
#define EncoderBad 0.75

#define M2CPRRel 16000  // Cass-Mag2 relative move to release clamp dog (cnts)
#define M2CTime 4000   // Time in msecs to wait before loosing the clamp dog

// Observing ports (CASS position) according to index signals
// 4C+2B+A
#define M3NASW 1
#define M3NASE 5
#define M3AUX1 3
#define M3AUX2 4
#define M3AUX3 2

char IRNames[NumberIRs][10] = {"NASW","NASE","CASS","AUX1","AUX2","AUX3"};
int IRSelect = -1;		// Records which IR is selected (0-5,-1 = none)
int CurrentIR = 0;		// Current IR being queried (0-5)
int ActiveIR = -1; 		// IR to be commanded/displayed on
											// err/volt/vel charts (0-5,-1=none)

// Error, voltage, and velocity charts
TChart IRErrChart;
TChart IRErr2Chart;
TChart IRVoltChart;
TChart IRVelChart;
TChart IRVel2Chart;

/////////////////////////////////////////////////////////////////////////////
// CIR: An object representing each instrument rotator
class CIR
{
  public:
  float P,I,D;          // PID controls for Galil itself
  float SpdP,SpdI,SpdD; // PID values for speed servo (program running on Galil)
  float SpdIL;          // Integral limit.. a fraction of top speed
  int Acc,Dec,Spd;      // Acceleration, deceleration, speed
  int ErrorLimit;       // Internal DMC error limit
  float VelocProfFilter;// Level of somoothing in Galil's velocty profile
  float TorqueLimit;    // Maximum torque output to amplifier
  int Address;          // DMC address (0-5)
  int Enabled;          // Flag: 1 = communication on
  unsigned DMCTime;			// Watch for timeouts
  int UpdateStep;				// Step through update routine
  int DMCCommandStep;		// Step through command send
  int DMCReceiveStep;		// Step through command receive
  int ResponseLength;		// Length of DMC response
  int ResponsesNeeded;	// Number of :'s needed to complete command
  int ResponsesGotten;	// Number of :'s received
  char Response[100];		// DMC response
  int ErrorCount;				// Number of consecutive com errors
  int CommandCount;			// Number of commands this IR has processed
  int Homed;						// Flag if IR has been homed (0=no,1=yes)
  int Homing;						// Flag if IR is currently homing (0=no,1=yes)
  int HomeStep;					// Current step in homing process
  int HomeEncStart;			// Encoder reading at beginning of homing
  int StableCount;			// Used to watch for zero velocity in homing routine
  int Revolution;				// Encoder counts for one revolution
  int HomeJogSpeed;			// Speed for finding the index mark in a home operation cnts/sec
  int CCWHome;					// Encoder readings at CW and CCW home
											  // (define encoder reading of 0 = IR up with
											  // telescope parked at 89.7 degrees elevation)
  int MinHomeDistance;	// Minimum distance to ALWAYS reach an index
  int MinBackOffLimitDistance;	// Minimum distance to ALWAYS back off a limit
															  // and pass index
  int NewMove;					// Flags that a move has been requested.
											  // 0 = no move,1 = GoA/GoR, 2 = Jog, 3 = Home, 4 = GoS
  int LastCommand;			// Records last successful move command type,
											  // 1 = Go, 2 = Jog
  // Hard movement limits, in degrees;
  int CWLimit;
  int CCWLimit;

  // Distance to stop from the hard limits, in degrees.
  // Defines soft limits.
  float SLDist;

  // Soft limits status
  int CWSLimitS;
  int CCWSLimitS;

  int Encoder;					// Encoder reading
  int prevEncoder;			// previous encoder reading
  int Command;					// Commanded encoder reading (absolute)
  int JogCommand;				// Commanded jog speed
  int Error;						// Error (target encoder-current encoder)
  int ErrorFlag;				// DMC error flag
  int Motion;           // Current motor motion (CW/CCW)
  int DMCMoving;				// Flag if DMC is actually moving
  int MotorPower;				// Flag if motors have power (SH/MO commands)
  int Limit;						// Limit switches (CW/CCW)
  int LockPin;					// Lockpin status
  int Brake;            // Pressure switch status (controls air to brake)
  int IndexLatched;			// Index latched status
  int LatchedEncoder;		// Latched index encoder reading
  int Zone;							// Current zone (CW/CCW)
  int Velocity;					// Current velocity (encoder counts/sec)
  int Profile;					// Current DMC internal commanded position (encoder counts)
  int Volts;						// Current voltage (*10)
  int Req;							// Current command in deg * 1000 or deg/sec * 1000
  int Val;							// Current position in deg * 1000
  int Vel;							// Current velocity in deg/sec * 1000
  int zoneflag; 				// Temporarily stores zone (CW/CCW) for Home oper.
  int IRPort;						// COM port the Galil is attached to
  float MasterEncErr;   // Master Renishaw encoder set-up signal status
  float SlaveEncErr;    // Slave Renishaw encoder set-up signal status
  int AmplifierPower;   // State of Glentek amplifier (on/off)
  float MotorCurrent;   // Current drawn by the rotator motor
  int DisplayMCurrent;  // Flag to display motor current in error graph
  int DisplayMEStatus;  // Flag to display master encoder setup signal in error graph
  int DisplaySEStatus;  // Flag to display slave encoder setup signal in error graph

  // GoS servo variables
  int GoSFlag;					// >=0 if IR servo program is running
  int GoSPosition;			// GoS commanded position
  int GoSVelocity;			// GoS commanded velocity
  int GoSTimer;					// Watch for a timeout
  int GoSStarting;			// Flag if servo program is being started
  float GoSError;				// Current speed servo error
  float GoSIntError;	// Current integral error
  float GoSOldError;	// Previous speed error
  float GoSTVel;
  float GoSTPos;
  int GoSDisplayError;	// Flag to display servo error instead of Galil error
  int GoSCmdTime;				// Reference time when we received the GoS command
  										  // (Used for time jitter correction)
  int TCSUTTime;				// UT Time in TCS
  int VaneUTTime;				// UT Time in Vane
  int inTol;						// Flag if internal servo has reached the desired
											  // tolerance (ErrorTolerance)
  int inTolTime;				// Flags that servo has been within certain
											  // tolerance (ErrorTolerance) for certain
											  // amount of time (TimeTolerance)
  int TolTime;					// Times how long the servo has been within
											  // certain tolerance (ErrorTolerance)
  int dispflag;	        // Tells when I want the servo variables displayed

  // Initialize all variables
  void Init(int address);
  // Update communication
  int Update();
  // Enable communication
  void Enable();
  // Disable communication
  void Disable();
  // Free instrument rotator motion (allow to be turned by hand)
  // Very dangerous!!
  //void Free();
  // Stop motion and enable brake
  void Stop();
  // Toggle motor power on/off
  void TogglePower();
  // Turn off gently Galil's built in servo
  void ServoOff();
  // Move given number of steps
  void MoveSteps(int steps);
  // Move given number of degrees
  void MoveAngle(float angle);
  // Go to given angle (in degrees) Set relative to 1 for a relative move
  void Go(float angle,int relative);
  // Jog at given speed (in degrees/sec)
  void Jog(float speed);
  // Go to given angle (in degrees) using the Galil servo program
  void GoS(float angle,float veloc,char *time);
  // Home IR (go to index and set encoders appropriately)
  void Home();
  // Reset communication and write all config info to DMCs (PID etc)
  void Reset();
  // Reset motion parameters
  void ResetParams();
  // Receive a response to a command
  int SerDMCReceive(char *rsp,int Timeout);
  // Blocking receive
  int BSerDMCReceive(char *rsp,int Timeout);
  // Send a command and receive the response
  int SerDMCCommand(char *Data,char *rsp,int Timeout);
  // Blocking command
  int BSerDMCCommand(char *Data,char *rsp,int Timeout);
  // Display all on-screen IR data
  void DisplayAll();
  // Display Enabled/Com status
  void DisplayStatus();
  // Display selection status
  void DisplaySelection();
  // Display encoder reading
  void DisplayEncoder();
  // Display current command
  void DisplayCommand();
  // Display switches
  void DisplaySwitches();
  // Display inputs
  void DisplayInputs();
  // Display angular velocity
  void DisplayVelocity();
  // Display torque (in volts)
  void DisplayVolts();
} IRs[NumberIRs];

/////////////////////////////////////////////////////////////////////////////
// Object with elements only present in CASS at Mag2
class CM2Cass
{
  public:
  // Cassegrain positions in deg\enc cnts for pointing M3 to observing ports.
  // Read from VANE.INI
  float CPNASW,CPNASE,CPAUX1,CPAUX2,CPAUX3;
  int CENASW,CENASE,CEAUX1,CEAUX2,CEAUX3;

  int LatchEngaged;  // Latch out status, measured through latch dog
  int LatchReleased; // Latch in status, measured through latch dog
  int IndexA;        // Indexes status for decoding CASS positions
  int IndexB;
  int IndexC;
  int ClampTimer; // Times msecs elapsed after applying air to clamps (unlock)
  int M3Position; // =4*IndexC+2*IndecB+1*IndexA

  int ChangeStep; // Steps in the Change Port routine
  int Changing; // Flags we're changing the observing port
  int Target; // CASS position (one of the M3XXXX values above)

  int ClampStep; // Clamping steps
  int Clamping;
  int ReleaseStep; // Releasing steps
  int Releasing;

  // Moves CASS IR to any observing port at Mag2
  void ChangePort(int pos,int tp);
  // Locks CASS IR position at Mag2
  void EngageClamp();
  // Frees CASS IR position at Mag2 in/out
  void ReleaseClamp();
  // Displays the port the tertiary is pointed at
  void DisplayPort();
} M2Cass;

/////////////////////////////////////////////////////////////////////////////
// UpdateIRs: Update instrument rotator communication
void UpdateIRs();

/////////////////////////////////////////////////////////////////////////////
// PauseIR: Pause IR communications
void PauseIR();

/////////////////////////////////////////////////////////////////////////////
// IRTerminal: opens a simple terminal with the instrument rotators
void IRTerminal(int IRPORT);
// This routine acts as a simple terminal to the IRs.
// It displays received characters, and transmits typed characters.
// Hitting ESC ends the terminal session.
// IRPORT is the COM port the rotator is attached to.

/////////////////////////////////////////////////////////////////////////////
// ProgIR: Downloads IR servo code to an instrument rotator
void ProgIR(int IR);
// This code reads IRSERVO.DMC, and downloads it to the commanded IR.
// IRSERVO.DMC should start with the DL (download) command, end the code
// with a "\", and finish with the BP (burn program) command.
// The IR should then be reset with the RS command using the IR terminal
// (TI), and then the download program should be checked with LS,
// since PROGIR does not verify the download.


Generated by GNU Enscript 1.6.5.2.
Document Actions