Skip to content. | Skip to navigation

Personal tools

mirror.cpp

mirror.cpp

mirror.cpp

/////////////////////////////////////////////////////////////////////////////
// MIRROR.CPP
//
//  Last updated: 10/17/2003
//
//  Part of the source code for the M3 Program
//
//  Contains routines for flipping the M3 Mirror up and down
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CMirror::Init - Initialize mirror class
void CMirror::Init()
{
  // Start mirror motion stopped (default)
  Stop();
	Motion = MMStop;
	Limit = MLNone;
  Latch = MLaUnknown; // Latch position is initially unknown (no status bit)
  // Start the mirror latches closing (our default position)
  CloseLatches();
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::Update - Update mirror motion/limit status
void CMirror::Update()
{
	int OldMotion = Motion,OldLimit = Limit;			// Save previous status

	Motion = 2 * GetDigBit(48) + GetDigBit(46);		// Read motion bits
	Limit = 2 * !GetDigBit(47) + !GetDigBit(45);  // Read limit bits

  // Update mirror motions
  if (MMotionStep == MMSOpenThenUp)
  {
  	// See if we've opened the latches
  	if (Latch == MLaOpen)
    {
      // Now move mirror up
		  SetDigBit(48);
		  ClrDigBit(46);
		  MotionTimer = msTimer;
      MMotionStep = MMSNone;
      MMoving = 1;
    }
  }
  else if (MMotionStep == MMSOpenThenDown)
  {
  	// See if we've opened the latches
  	if (Latch == MLaOpen)
    {
      // Now move mirror down
		  SetDigBit(46);
		  ClrDigBit(48);
		  MotionTimer = msTimer;
      MMotionStep = MMSNone;
      MMoving = 1;
    }
  }

  // Update latch motions
  if (LMotionStep == LMSClose)
  {
  	// See if we've closed the latches
  	if (msTimer - LatchTimer > FullLatchMove)
    {
	  	Latch = MLaClosed;
  		DisplayLatch();
      LMotionStep = LMSNone;
      LMoving = 0;
      EDSLog.Add(911,"Mirror latches are closed");
    }
  }
  else if (LMotionStep == LMSOpen)
  {
  	// See if we've opened the latches
  	if (msTimer - LatchTimer > FullLatchMove)
    {
	  	Latch = MLaOpen;
  		DisplayLatch();
      LMotionStep = LMSNone;
      LMoving = 0;
      EDSLog.Add(910,"Mirror latches are opened");
    }
  }

	// Halt motions if a limit is reached
	if ((Motion & MMUp) && (Limit & MLUp))
  {
		Stop();
    EDSLog.Add(912,"Mirror is up");
  }
	if ((Motion & MMDown) && (Limit & MLDown))
	{
		Stop();
    EDSLog.Add(913,"Mirror is down");
    // Start the mirror latches closing
    CloseLatches();
  }

  // Double check to avoid pushing the mirror against the latches
  if (((Latch == MLaUnknown) || (Latch == MLaClosed) || (Latch == MLaClosing))
			&& (Motion & MMUp))
  {
  	Stop();
    EDSLog.Add(4,"Mirror up motion attempted with latches closed");
  }

	// Halt motion if the mirror motion times out (no limit reached)
	if (Motion && (msTimer - MotionTimer > MotionTimeout))
	{
		Stop();
		EDSLog.Add(2,"Mirror motion timeout");
	}

	// Update on-screen display if necessary
	if (OldMotion != Motion)
		DisplayMotion();
	if (OldLimit != Limit)
		DisplayLimit();
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::DisplayAll - Display all mirror status on-screen
void CMirror::DisplayAll()
{
	DisplayMotion();
	DisplayLimit();
	DisplayLatch();
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::DisplayMotion - Display mirror motion status on-screen
void CMirror::DisplayMotion()
{
	int x = 148,y = 168;

	switch (Motion)
	{
		case MMStop:
			PutChar16(CUpDown,x,y,BLACK,SHECMEDGRAY);break;
		case MMUp:
			PutChar16(CUp,x,y,SHECGREEN,SHECMEDGRAY);break;
		case MMDown:
			PutChar16(CDown,x,y,SHECGREEN,SHECMEDGRAY);break;
		default:
			PutChar16(CUpDown,x,y,SHECRED,SHECMEDGRAY);break;
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::DisplayLimit - Display mirror limit status on-screen
void CMirror::DisplayLimit()
{
	int x = 188,x1 = 260,x2 = 340,y = 168;

	switch (Limit)
	{
		case MLNone:
			PutChar16(CUpDown,x,y,BLACK,SHECMEDGRAY);
			PutString16("Midway",x1,x2,y,BLACK,SHECMEDGRAY);
		break;
		case MLUp:
			PutChar16(CUp,x,y,SHECGREEN,SHECMEDGRAY);
			PutString16("Up",x1,x2,y,BLACK,SHECMEDGRAY);
		break;
		case MLDown:
			PutChar16(CDown,x,y,SHECGREEN,SHECMEDGRAY);
			PutString16("Down",x1,x2,y,BLACK,SHECMEDGRAY);
		break;
		default:
			PutChar16(CUpDown,x,y,SHECRED,SHECMEDGRAY);
			PutString16("Error",x1,x2,y,BLACK,SHECMEDGRAY);
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::DisplayLatch - Display mirror latch status on screen
void CMirror::DisplayLatch()
{
	int x = 12 + 31 * 8, x2 = 12 + 17 * 8, y = 184;
  switch (Latch)
  {
		case MLaOpen:
    {
    	PutChar16(CUpDown,x2,y,BLACK,SHECMEDGRAY);
      PutString16("Unlocked",x,x+10*8,y,BLACK,SHECMEDGRAY);
		} break;
    case MLaClosed:
    {
    	PutChar16(CUpDown,x2,y,BLACK,SHECMEDGRAY);
    	PutString16("Locked",x,x+10*8,y,BLACK,SHECMEDGRAY);
		} break;
		case MLaOpening:
    {
    	PutChar16(CUp,x2,y,SHECGREEN,SHECMEDGRAY);
    	PutString16("Unlocking",x,x+10*8,y,BLACK,SHECMEDGRAY);
		} break;
    case MLaClosing:
    {
    	PutChar16(CDown,x2,y,SHECGREEN,SHECMEDGRAY);
    	PutString16("Locking",x,x+10*8,y,BLACK,SHECMEDGRAY);
		} break;
    default:
    {
    	PutChar16(CUpDown,x2,y,BLACK,SHECMEDGRAY);
    	PutString16("Unknown",x,x+10*8,y,SHECRED,SHECMEDGRAY);
		} break;
  }
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::Up - Start mirror moving up
void CMirror::Up(int force)
// Set force to 1 to force mirror up even if ADC turret is in
// the wrong position.  Note that you could damage the mirror if you
// don't stop the mirror manually in time!!
// force should be 0 for normal operation.
{
	// Don't move if there are any other moves taking place
  if (MMoving || LMoving || (ADCTurret->Moving) || (M3Turret->Moving) ||
  	  (ADCTurretPin.Moving) || (M3TurretPin.Moving))
	{
  	EDSLog.Add(500,"M3 Mirror: Move aborted, other moves in progress");
    return;
  }

	// Check to make sure the ADC Turret is in the "no-adc" position,
	// which leaves room for the mirror to flip all the way up.
	if ((force != 1) && (ADCTurret->Position != ATPForward))
	{
		EDSLog.Add(3,"Can't move mirror up: ADC Turret not in NO-ADC position");
		return;
	}

  // Don't move if M3 Turret pin not locked (pin in)
  if ((force != 1) && !(M3TurretPin.Limit & MTPLLock))
	{
		EDSLog.Add(74,"M3 Mirror: Flip aborted, M3 Turret pin not engaged");
		return;
	}

	// Start mirror moving, and record time to check for a timeout later
	if (!(Limit & MLUp))
	{
  	// Start opening latches.. mirror motion begins after that
    OpenLatches();
    MMotionStep = MMSOpenThenUp; 	// Move mirror up after latches are open later
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::Down - Start mirror moving down
void CMirror::Down()
{
  // Don't move if M3 or ADC Turret pins not locked (pins in)
  if (!(M3TurretPin.Limit & MTPLLock))
	{
		EDSLog.Add(74,"M3 Mirror: Flip down aborted, M3 Turret pin not engaged");
		return;
	}

	// Start mirror moving, and record time to check for a timeout later
	if (!(Limit & MLDown))
	{
    if (Latch != MLaOpen)
    {
      OpenLatches();
  	  MMotionStep = MMSOpenThenDown; // Move mirror down after latches are open later
    }
    else
    {
			// Mirror down
			SetDigBit(46);
			ClrDigBit(48);
			MotionTimer = msTimer;
      MMoving = 1;
    }
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::Down - Stop any mirror motion
void CMirror::Stop()
{
	ClrDigBit(48);
	ClrDigBit(46);
  MMoving = 0;
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::CloseLatches - Close mirror latches
void CMirror::CloseLatches()
{
  LMotionStep = LMSClose;
  ClrParBit(7);		// Close latches
  LatchTimer = msTimer;
  Latch = MLaClosing;
  DisplayLatch();
  LMoving = 1;
}

/////////////////////////////////////////////////////////////////////////////
// CMirror::OpenLatches - Open mirror latches
void CMirror::OpenLatches()
{
  LMotionStep = LMSOpen;
  SetParBit(7);								// Open latches regardless of previous state
  LatchTimer = msTimer;				// Record time to check for latch timeout later
  Latch = MLaOpening;					// Update display
  DisplayLatch();
  LMoving = 1;
}

Generated by GNU Enscript 1.6.5.2.
Document Actions