Skip to content
Snippets Groups Projects
Commit afa347df authored by Tobias Gröger's avatar Tobias Gröger
Browse files

Fix timeout for ss2 deactivation, button layout

parent cd0de683
No related branches found
No related tags found
1 merge request!99Fix rogue emergency stop button
......@@ -36,6 +36,7 @@ namespace armarx
mainWindow(mainWindow),
iconNormal(QPixmap::fromImage(QImage(QString::fromUtf8(":/icons/emergency-stop.png")))),
iconDark(QPixmap::fromImage(QImage(QString::fromUtf8(":/icons/emergency-stop-dark.png")))),
lastKnownEmergencyStopState(EmergencyStopState::eEmergencyStopInactive),
timer(new QTimer(this))
{
qRegisterMetaType<EmergencyStopState>("EmergencyStopState");
......@@ -61,6 +62,8 @@ namespace armarx
"EmergencyStop is active. Shortcut: Pause Key"));
button->setVisible(false);
QGridLayout* l = new QGridLayout(this->getWidget());
l->setMargin(0);
l->setContentsMargins(0, 0, 0, 0);
this->getWidget()->setLayout(l);
this->getWidget()->layout()->addWidget(button);
......@@ -174,57 +177,43 @@ namespace armarx
EmergencyStopState::eEmergencyStopInactive);
}
}
else
{
button->setChecked(true);
}
}
void
EmergencyStopWidget::clicked(bool checked)
{
if (emergencyStopMasterPrx)
if (!emergencyStopMasterPrx)
{
EmergencyStopState const state = emergencyStopMasterPrx->getEmergencyStopState();
bool success = true;
switch (state)
{
case EmergencyStopState::eEmergencyStopActive:
if (clock_t::now() > timeLastActivated + deactivationWaitPeriod)
{
if (emergencyStopMasterPrx)
{
// Only release SS2 if the state we received still is "Active". Fail
// otherwise.
bool const success =
emergencyStopMasterPrx->checkAndSetEmergencyStopState(
EmergencyStopState::eEmergencyStopInactive, state);
if (not success)
{
ARMARX_WARNING << "Toggling SS2 failed since it probably has "
"already been activated from another session. "
"This mechanism is to prevent two simultanous "
"toggles of the SS2 to cancel out.";
}
}
}
else
{
button->setChecked(true);
}
break;
case EmergencyStopState::eEmergencyStopInactive:
if (emergencyStopMasterPrx)
return;
}
EmergencyStopState const state = emergencyStopMasterPrx->getEmergencyStopState();
switch (state)
{
case EmergencyStopState::eEmergencyStopActive:
if (clock_t::now() > timeLastActivated + deactivationWaitPeriod)
{
// Only release SS2 if the state we received still is "Active". Fail
// otherwise.
bool const success = emergencyStopMasterPrx->checkAndSetEmergencyStopState(
EmergencyStopState::eEmergencyStopInactive, state);
if (not success)
{
// Always enable SS2 without checking.
enableSS2();
ARMARX_WARNING << "Toggling SS2 failed since it probably has "
"already been activated from another session. "
"This mechanism is to prevent two simultanous "
"toggles of the SS2 to cancel out.";
}
break;
}
if (not success)
{
ARMARX_WARNING << "Releasing SS2 failed.";
}
}
else
{
button->setChecked(true);
}
break;
case EmergencyStopState::eEmergencyStopInactive:
// Always enable SS2 without checking.
enableSS2();
break;
}
}
......@@ -243,14 +232,19 @@ namespace armarx
{
case EmergencyStopState::eEmergencyStopActive:
button->setChecked(true);
if (lastKnownEmergencyStopState != EmergencyStopState::eEmergencyStopActive)
{
timeLastActivated = clock_t::now();
}
break;
case EmergencyStopState::eEmergencyStopInactive:
button->setChecked(false);
timeLastActivated = clock_t::now();
break;
default:
button->setChecked(false);
}
lastKnownEmergencyStopState = state;
}
void
......
......@@ -84,6 +84,7 @@ namespace armarx
using clock_t = std::chrono::high_resolution_clock;
static constexpr std::chrono::milliseconds deactivationWaitPeriod{2500};
EmergencyStopState lastKnownEmergencyStopState;
clock_t::time_point timeLastActivated;
QTimer* timer;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment