Skip to content. | Skip to navigation

Personal tools

mtpin.cpp

mtpin.cpp

mtpin.cpp

/////////////////////////////////////////////////////////////////////////////
// MTPIN.CPP
//
//  Last updated: 10/30/2003
//
//  Part of the source code for the M3 Program
//
//  Contains routines for locking and unlocking the M3 turret pin
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CM3TurretPin::Init - Initialize object
void CM3TurretPin::Init()
{
	Limit = MTPLNone;
  Motion = MTPMStop;
	MotionStep = MTPSNoLimit;
	// MotionTimeout constant is initialized from M3.INI
  // Start with lockpin engaged
	ClrDigBit(42);
}

/////////////////////////////////////////////////////////////////////////////
// CM3TurretPin::Update - Update all motion and status
void CM3TurretPin::Update()
{
	int OldLimit = Limit;		// Record old status

	Limit = 2 * GetDigBit(41) + GetDigBit(43);  // Read limit
	Command = GetDigBit(42);                    // Read commanded status

  if (MotionStep == MTPSGoLLimit)
  {
	  // if we've just hit a limit, mark pin motion stopped and status locked
	  if ((Command == 0) && (Limit & MTPLLock))
	  {
      OldMotion = Motion;
      Motion = MTPMStop;
      MotionStep = MTPSHitLimit;
      EDSLog.Add(960,"M3 Turret Pin: Pin locked");
	  }
  }
  else if (MotionStep == MTPSWaitLoosePin)
  {
		if ((msTimer - MotionTimer) > TimePinUnlock)
			MotionStep = MTPSLoosenPin;
  }
  else if (MotionStep == MTPSLoosenPin)
  {
    M3Turret->MoveSteps(StepsToUnlock,1);
    MotionStep = MTPSGoULimit;
  }
  else if (MotionStep == MTPSGoULimit)
  {
	  // if we've just hit a limit, mark pin motion stopped and status unlocked
    if ((Command == 1) && (Limit & MTPLUnlock))
    {
      OldMotion = Motion;
      Motion = MTPMStop;
      MotionStep = MTPSHitLimit;
      EDSLog.Add(961,"M3 Turret Pin: Pin unlocked");
    }
  }

	// Flag error when lock pin motion times out
	if ((Motion != MTPMStop) && (msTimer - MotionTimer > MotionTimeout))
	{
    OldMotion = Motion;
    Motion = MTPMStop;
  	EDSLog.Add(4,"M3 Turret Pin: Lock pin timeout");
  }

  Moving = Motion;
	// Display motion and limit status if they've changed
	if (OldMotion != Motion)
		DisplayMotion();
	if (OldLimit != Limit)
		DisplayLimit();
}

/////////////////////////////////////////////////////////////////////////////
// CM3TurretPin::DisplayAll - Display motion and limit status
void CM3TurretPin::DisplayAll()
{
	DisplayMotion();
	DisplayLimit();
}

/////////////////////////////////////////////////////////////////////////////
// CM3TurretPin::DisplayMotion - Display motion status
void CM3TurretPin::DisplayMotion()
{
	int x = 148,y = 216;

	switch (Motion)
	{
		case MTPMLock:
			PutChar16(CDown,x,y,SHECGREEN,SHECMEDGRAY);break;
		case MTPMUnlock:
			PutChar16(CUp,x,y,SHECGREEN,SHECMEDGRAY);break;
		case MTPMStop:
			PutChar16(CUpDown,x,y,BLACK,SHECMEDGRAY);break;
		default:
			PutChar16(CUpDown,x,y,SHECRED,SHECMEDGRAY);break;
	}
}

/////////////////////////////////////////////////////////////////////////////
// CM3TurretPin::DisplayLimit - Display limit status
void CM3TurretPin::DisplayLimit()
{
	int x = 188,y = 216,x1 = 260,x2 = 340;

	switch (Limit)
	{
		case MTPLNone:
			PutChar16(CUpDown,x,y,BLACK,SHECMEDGRAY);
			PutString16("Midway",x1,x2,y,BLACK,SHECMEDGRAY);
		break;
		case MTPLLock:
			PutChar16(CDown,x,y,SHECGREEN,SHECMEDGRAY);
			PutString16("Locked",x1,x2,y,BLACK,SHECMEDGRAY);
		break;
		case MTPLUnlock:
			PutChar16(CUp,x,y,SHECGREEN,SHECMEDGRAY);
			PutString16("Unlocked",x1,x2,y,BLACK,SHECMEDGRAY);
		break;
		default:
			PutChar16(CUpDown,x,y,SHECRED,SHECMEDGRAY);
			PutString16("Error",x1,x2,y,BLACK,SHECMEDGRAY);
	}
}

/////////////////////////////////////////////////////////////////////////////
// CM3TurretPin::Lock - Start M3 Turret pin locking
void CM3TurretPin::Lock(int MotionOK)
{
  // Don't lock if there are any other moves taking place
  if (!MotionOK && (M3Turret->Moving || ADCTurret->Moving ||
			Mirror.MMoving || Mirror.LMoving || ADCTurretPin.Moving))
	{
		EDSLog.Add(67,"M3 Turret Pin: Unable to lock, other moves taking place");
  	return;
  }
	// Don't lock if M3 Turret is not in one of the five lockable positions
  if (!MotionOK && ((M3Turret->Position < MTPForward) ||
									  (M3Turret->Position > MTPReverse)))
	{
		EDSLog.Add(68,"M3 Turret Pin: Unable to lock, no lockable position");
  	return;
  }

  // Only lock the pin if the M3 Turret is at rest
	if (!(Limit & MTPLLock) && (M3Turret->Motion == MTMStop))
	{
		ClrDigBit(42);
		MotionStep = MTPSGoLLimit;
		MotionTimer = msTimer;
    OldMotion = Motion;
    Motion = MTPMLock;
		EDSLog.Add(962,"M3 Turret Pin: locking pin...");
	}
  else if (M3Turret->Motion != MTMStop)
		EDSLog.Add(69,"M3 Turret Pin: Unable to lock, M3 Turret in motion");
  else if (Limit & MTPLLock)
		EDSLog.Add(963,"M3 Turret Pin: Locked limit already triggered");
}

/////////////////////////////////////////////////////////////////////////////
// CM3TurretPin::Unlock - Start M3 Turret pin unlocking
void CM3TurretPin::Unlock(int MotionOK)
{
  // Don't unlock if there are any other moves taking place
  if (!MotionOK && (M3Turret->Moving || ADCTurret->Moving ||
			Mirror.MMoving || Mirror.LMoving || ADCTurretPin.Moving))
	{
		EDSLog.Add(70,"M3 Turret Pin: Unable to unlock, other moves taking place");
  	return;
  }

  // Only unlock if mirror is down
	if (!(Limit & MTPLUnlock) && (Mirror.Limit & MLDown))
	{
		SetDigBit(42);
		MotionStep = MTPSWaitLoosePin;
		MotionTimer = msTimer;
    OldMotion = Motion;
    Motion = MTPMUnlock;
		EDSLog.Add(964,"M3 Turret Pin: unlocking pin...");
  }
  else if (!(Mirror.Limit & MLDown))
		EDSLog.Add(71,"M3 Turret Pin: Unable to unlock, mirror not down");
  else if (Limit & MTPLUnlock)
		EDSLog.Add(965,"M3 Turret Pin: Unlocked limit already triggered");
}

/////////////////////////////////////////////////////////////////////////////
// CM3TurretPin::ForcedUnlock - Unlock M3 Turret pin
void CM3TurretPin::ForcedUnlock()
{
  // Only unlock if mirror is down
	if (!(Limit & MTPLUnlock) && (Mirror.Limit & MLDown))
	{
		SetDigBit(42);
		MotionStep = MTPSGoULimit;
		MotionTimer = msTimer;
    OldMotion = Motion;
    Motion = MTPMUnlock;
		EDSLog.Add(964,"M3 Turret Pin: unlocking pin...");
  }
  else if (!(Mirror.Limit & MLDown))
		EDSLog.Add(71,"M3 Turret Pin: Unable to unlock, mirror not down");
  else if (Limit & MTPLUnlock)
		EDSLog.Add(965,"M3 Turret Pin: Unlocked limit already triggered");
}

Generated by GNU Enscript 1.6.5.2.
Document Actions