The Jog buttons: jog motion
Two jog buttons are used for jog motion. One for jog forward and the other jog backward. The behavior of the buttons can be customized. In this sample, the buttons are used this way:
- Jog: press and hold the left mouse button. The signal is pressed.
- Stop jogging: release the left mouse button. The signal is released.
These two buttons' names are btnJogForward and btnJogBackward, respectively. They have the signals pressed and released, in which we emit the signal commandJog, which is connected to the slot actionJog, in which we use a switch statement to test command against JogForward, JogBackward, and Stop
. When Jog Forward or Jog Backward is pressed, JogAxis is run. When Jog Forward or Jog Backward is released, HaltAxis is run.
The following code is in 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);
});
The following code is in 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;
}
}