寸動 (Jog) 鈕:寸動運動

寸動運動使用的寸動鈕有兩個,一個為向前寸動,另一個為向後寸動,鈕的行為可自訂,此範例使用方式如下:

兩個鈕的名稱分別為 btnJogForwardbtnJogBackward,含 pressedreleased 信號,其中我們發送連接至位置 actionJog 的信號 commandJog,當中使用 switch 陳述式來對 JogForwardJogBackwardStop 測試 command。按住 Jog ForwardJog Backward 時將執行 JogAxis;而放開 Jog Forward Jog Backward 時將執行 HaltAxis

以下代碼在 QtGui.cpp 中:

QObject::connect(this, &QtGui::commandJog, ks, &ksWorker::actionJog);
.........
QObject::connect(ui->btnJogForward, &QPushButton::pressed, [this]() 
{
   emit commandJog(JogForward);
});
QObject::connect(ui->btnJogForward, &QPushButton::released, [this]()
{
   emit commandJog(stop);
});
QObject::connect(ui->btnJogBackward, &QPushButton::pressed, [this]()
{
   emit commandJog(JogBackward);
});
QObject::connect(ui->btnJogBackward, &QPushButton::released, [this]()
{
   emit commandJog(stop);
});

以下代碼在 ksworker.cpp 中:

void ksWorker::actionJog(kscommand command)
{
   switch (command)
   {
      case JogForward:
         JogAxis(currentIndex, commandVelocity, commandVelocity * 10, commandVelocity * 10, commandVelocity * 1000, McDirection::mcPositiveDirection);
         break;

      case JogBackward:
         JogAxis(currentIndex, commandVelocity, commandVelocity * 10, commandVelocity * 10, commandVelocity * 1000, McDirection::mcNegativeDirection);
         break;

      case stop:
         HaltAxis(currentIndex, 50000, 5000000, McBufferMode::mcAborting);
         break;
      default:
      break;
   }
}