Skip to content. | Skip to navigation

Personal tools

atpin.cpp

atpin.cpp

atpin.cpp

/////////////////////////////////////////////////////////////////////////////
// ATPIN.CPP
//
//  Last updated: 5/2/2007
//
//  Part of the source code for the M3 Program
//
//  Contains routines for locking and unlocking the ADC turret pin
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CADCTurretPin::Init - Initialize all object variables
void CADCTurretPin::Init()
{
  Motion = ATPMStop;
  Moving = 0;
  Limit = ATPLNone;
  MotionStep = ATPSNoLimit;
  LimitTimeout = 2000; // 2 seconds to complete a lock/unlock after seeing a limit
  // MotionTimeout is initialized from M3.INI
}

/////////////////////////////////////////////////////////////////////////////
// CADCTurretPin::Update -Update all motion and status
void CADCTurretPin::Update()
{
  // Record previous status
  int OldMotion = Motion,OldLimit = Limit;

  // Read limit and motion status
  Limit = 2 * !GetDigBit(37) + !GetDigBit(39);
  Motion = 2 * GetDigBit(38) + GetDigBit(40);
  Moving = (Motion > 0);

  // Halt motions if a limit is reached and the LockTimer has expired
  if ((MotionStep == ATPSHitLimit) && (msTimer - LimitTimer > LimitTimeout))
    Stop();
  // Check for a lock limit during locking motion
  if ((MotionStep == ATPSNoLimit) && (Motion & ATPMLock) && (Limit & ATPLLock))
  {
    MotionStep = ATPSHitLimit;
    LimitTimer = msTimer;
  }
  // Check for an unlock limit during unlocking motion
  if ((MotionStep == ATPSNoLimit) && (Motion & ATPMUnlock) && (Limit & ATPLUnlock))
  {
    MotionStep = ATPSHitLimit;
    LimitTimer = msTimer;
  }
  // Halt motion if the lock pin times out
  if (Motion && (msTimer - MotionTimer > MotionTimeout))
  {
    Stop();
    EDSLog.Add(20,"ADC Turret: Lock pin timeout");
  }

  // Display any status changes
  if (OldMotion != Motion)
    DisplayMotion();
  if (OldLimit != Limit)
    DisplayLimit();
}

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

/////////////////////////////////////////////////////////////////////////////
// CADCTurretPin::DisplayMotion - Display motion status on-screen
void CADCTurretPin::DisplayMotion()
{
  int x = 148,y = 248;
  switch (Motion)
  {
    case ATPMStop:
      PutChar16(CUpDown,x,y,BLACK,SHECMEDGRAY);break;
    case ATPMLock:
      PutChar16(CDown,x,y,SHECGREEN,SHECMEDGRAY);break;
    case ATPMUnlock:
      PutChar16(CUp,x,y,SHECGREEN,SHECMEDGRAY);break;
    default:
      PutChar16(CUpDown,x,y,SHECRED,SHECMEDGRAY);
  }
}

/////////////////////////////////////////////////////////////////////////////
// CADCTurretPin::DisplayLimit - Display limit status on-screen
void CADCTurretPin::DisplayLimit()
{
  int x = 188,y = 248;

  switch (Limit)
  {
    case ATPLNone:
      PutChar16(CUpDown,x,y,BLACK,SHECMEDGRAY);
      PutString16("Midway",260,340,y,BLACK,SHECMEDGRAY);
    break;
    case ATPLLock:
      PutChar16(CDown,x,y,SHECGREEN,SHECMEDGRAY);
      PutString16("Locked",260,340,y,BLACK,SHECMEDGRAY);
    break;
    case ATPLUnlock:
      PutChar16(CUp,x,y,SHECGREEN,SHECMEDGRAY);
      PutString16("Unlocked",260,340,y,BLACK,SHECMEDGRAY);
    break;
    default:
      PutChar16(CUpDown,x,y,SHECRED,SHECMEDGRAY);
      PutString16("Error",260,340,y,BLACK,SHECMEDGRAY);
  }
}

/////////////////////////////////////////////////////////////////////////////
// CADCTurretPin::Lock - Start lock pin locking
void CADCTurretPin::Lock(int MotionOK)
// Don't lock if something's moving, unless MotionOK = 1
{
  // Don't lock if there are any other moves taking place
  if (!MotionOK && (M3Turret->Moving || ADCTurret->Moving ||
                    Mirror.MMoving || Mirror.LMoving || M3TurretPin.Moving))
    return;

  // Only lock if the ADC turret is in the "ADC" position,
  // unless motion forced with MotionOK = 1
  if (!MotionOK && (ADCTurret->Position != ATPIndex) || (ADCTurret->Index != 1))
    return;

  // Only lock if the ADC turret is stopped and is not already locked
  if ((ADCTurret->Motion == ATMStop) && !(Limit & ATPLLock) )
  {
    SetDigBit(40);
    ClrDigBit(38);
    MotionStep = ATPSNoLimit;
    MotionTimer = msTimer;
  }
}

/////////////////////////////////////////////////////////////////////////////
// CADCTurretPin::Unlock - Start lock pin unlocking
void CADCTurretPin::Unlock(int MotionOK)
// Don't unlock if something's moving, unless MotionOK = 1
{
  // Don't unlock if there are any other moves taking place
  if (!MotionOK && (M3Turret->Moving || ADCTurret->Moving ||
                    Mirror.MMoving || Mirror.LMoving || M3TurretPin.Moving))
    return;

  // Only unlock if it's not already unlocked
  if (!(Limit & ATPLUnlock))
  {
    SetDigBit(38);
    ClrDigBit(40);
    MotionStep = ATPSNoLimit;
    MotionTimer = msTimer;
  }
}

/////////////////////////////////////////////////////////////////////////////
// CADCTurretPin::Stop - Halt lock pin motion
void CADCTurretPin::Stop()
{
  ClrDigBit(40);
  ClrDigBit(38);
  MotionStep = ATPSNoLimit;
}


Generated by GNU Enscript 1.6.5.2.
Document Actions