Download data/core/components/code/Qt/mtsTeleOperationPSMQtWidget.cpp from introvoyz045/sawIntuitiveResearchKit: direct link, hf CLI and curl.
- Browser
- Download file 13.4 kB
-
https://huggingface.co/datasets/introvoyz045/sawIntuitiveResearchKit/resolve/main/data/core/components/code/Qt/mtsTeleOperationPSMQtWidget.cpp
- Command line
-
hf download hf://datasets/introvoyz045/sawIntuitiveResearchKit/data/core/components/code/Qt/mtsTeleOperationPSMQtWidget.cpp
-
curl -L -o mtsTeleOperationPSMQtWidget.cpp https://huggingface.co/datasets/introvoyz045/sawIntuitiveResearchKit/resolve/main/data/core/components/code/Qt/mtsTeleOperationPSMQtWidget.cpp
13.4 kB
| /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |
| /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */ | |
| /* | |
| Author(s): Zihan Chen, Anton Deguet | |
| Created on: 2013-02-20 | |
| (C) Copyright 2013-2023 Johns Hopkins University (JHU), All Rights Reserved. | |
| --- begin cisst license - do not edit --- | |
| This software is provided "as is" under an open source license, with | |
| no warranty. The complete license can be found in license.txt and | |
| http://www.cisst.org/cisst/license.txt. | |
| --- end cisst license --- | |
| */ | |
| // system include | |
| // Qt include | |
| // cisst | |
| CMN_IMPLEMENT_SERVICES_DERIVED_ONEARG(mtsTeleOperationPSMQtWidget, mtsComponent, std::string); | |
| mtsTeleOperationPSMQtWidget::mtsTeleOperationPSMQtWidget(const std::string & componentName, double periodInSeconds): | |
| mtsComponent(componentName), | |
| TimerPeriodInMilliseconds(periodInSeconds * 1000), // Qt timers are in milliseconds | |
| LogEnabled(false) | |
| { | |
| QMMessage = new mtsMessageQtWidget(); | |
| // Setup cisst interface | |
| mtsInterfaceRequired * interfaceRequired = AddInterfaceRequired("TeleOperation"); | |
| if (interfaceRequired) { | |
| QMMessage->SetInterfaceRequired(interfaceRequired); | |
| interfaceRequired->AddFunction("set_scale", TeleOperation.set_scale); | |
| interfaceRequired->AddFunction("lock_rotation", TeleOperation.lock_rotation); | |
| interfaceRequired->AddFunction("lock_translation", TeleOperation.lock_translation); | |
| interfaceRequired->AddFunction("set_align_MTM", TeleOperation.set_align_MTM); | |
| interfaceRequired->AddFunction("MTM/measured_cp", TeleOperation.MTM_measured_cp); | |
| interfaceRequired->AddFunction("PSM/setpoint_cp", TeleOperation.PSM_setpoint_cp); | |
| interfaceRequired->AddFunction("align_MTM", TeleOperation.align_MTM); | |
| interfaceRequired->AddFunction("alignment_offset", TeleOperation.alignment_offset); | |
| interfaceRequired->AddFunction("period_statistics", TeleOperation.period_statistics); | |
| // events | |
| interfaceRequired->AddEventHandlerWrite(&mtsTeleOperationPSMQtWidget::DesiredStateEventHandler, | |
| this, "desired_state"); | |
| interfaceRequired->AddEventHandlerWrite(&mtsTeleOperationPSMQtWidget::CurrentStateEventHandler, | |
| this, "current_state"); | |
| interfaceRequired->AddEventHandlerWrite(&mtsTeleOperationPSMQtWidget::FollowingEventHandler, | |
| this, "following"); | |
| interfaceRequired->AddEventHandlerWrite(&mtsTeleOperationPSMQtWidget::ScaleEventHandler, | |
| this, "scale"); | |
| interfaceRequired->AddEventHandlerWrite(&mtsTeleOperationPSMQtWidget::RotationLockedEventHandler, | |
| this, "rotation_locked"); | |
| interfaceRequired->AddEventHandlerWrite(&mtsTeleOperationPSMQtWidget::TranslationLockedEventHandler, | |
| this, "translation_locked"); | |
| interfaceRequired->AddEventHandlerWrite(&mtsTeleOperationPSMQtWidget::AlignMTMEventHandler, | |
| this, "align_MTM"); | |
| } | |
| } | |
| void mtsTeleOperationPSMQtWidget::Configure(const std::string &filename) | |
| { | |
| CMN_LOG_CLASS_INIT_VERBOSE << "Configure: " << filename << std::endl; | |
| } | |
| void mtsTeleOperationPSMQtWidget::Startup(void) | |
| { | |
| setupUi(); | |
| startTimer(TimerPeriodInMilliseconds); | |
| if (!LogEnabled) { | |
| QMMessage->hide(); | |
| } | |
| if (!parent()) { | |
| show(); | |
| } | |
| bool align; | |
| if (TeleOperation.align_MTM(align)) { | |
| emit SignalAlignMTM(align); | |
| } | |
| } | |
| void mtsTeleOperationPSMQtWidget::Cleanup(void) | |
| { | |
| this->hide(); | |
| CMN_LOG_CLASS_INIT_VERBOSE << "Cleanup" << std::endl; | |
| } | |
| void mtsTeleOperationPSMQtWidget::closeEvent(QCloseEvent * event) | |
| { | |
| int answer = QMessageBox::warning(this, tr("mtsTeleOperationPSMQtWidget"), | |
| tr("Do you really want to quit this application?"), | |
| QMessageBox::No | QMessageBox::Yes); | |
| if (answer == QMessageBox::Yes) { | |
| event->accept(); | |
| QCoreApplication::exit(); | |
| } else { | |
| event->ignore(); | |
| } | |
| } | |
| void mtsTeleOperationPSMQtWidget::timerEvent(QTimerEvent * CMN_UNUSED(event)) | |
| { | |
| // make sure we should update the display | |
| if (this->isHidden()) { | |
| return; | |
| } | |
| // retrieve transformations | |
| TeleOperation.MTM_measured_cp(m_MTM_measured_cp); | |
| QCPGMTMWidget->SetValue(m_MTM_measured_cp); | |
| // for PSM, check if the registration rotation is needed | |
| TeleOperation.PSM_setpoint_cp(m_PSM_setpoint_cp); | |
| QCPGPSMWidget->SetValue(m_PSM_setpoint_cp); | |
| // alignment offset | |
| TeleOperation.alignment_offset(m_alignment_offset); | |
| QVRAlignOffset->SetValue(m_alignment_offset); | |
| TeleOperation.period_statistics(m_interval_statistics); | |
| QMIntervalStatistics->SetValue(m_interval_statistics); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotSetScale(double scale) | |
| { | |
| TeleOperation.set_scale(scale); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotLockRotation(bool lock) | |
| { | |
| TeleOperation.lock_rotation(lock); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotLockTranslation(bool lock) | |
| { | |
| TeleOperation.lock_translation(lock); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotSetAlignMTM(bool align) | |
| { | |
| TeleOperation.set_align_MTM(align); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotDesiredStateEventHandler(QString state) | |
| { | |
| QLEDesiredState->setText(state); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotCurrentStateEventHandler(QString state) | |
| { | |
| QLECurrentState->setText(state); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotFollowingEventHandler(bool following) | |
| { | |
| if (following) { | |
| QLEFollowing->setText("FOLLOWING"); | |
| } else { | |
| QLEFollowing->setText("INDEPENDENT"); | |
| } | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotScaleEventHandler(double scale) | |
| { | |
| QSBScale->setValue(scale); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotRotationLockedEventHandler(bool lock) | |
| { | |
| QCBLockRotation->setChecked(lock); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotTranslationLockedEventHandler(bool lock) | |
| { | |
| QCBLockTranslation->setChecked(lock); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotAlignMTMEventHandler(bool align) | |
| { | |
| QCBAlignMTM->setChecked(align); | |
| } | |
| void mtsTeleOperationPSMQtWidget::setupUi(void) | |
| { | |
| // main layout | |
| QVBoxLayout * mainLayout = new QVBoxLayout(); | |
| setLayout(mainLayout); | |
| // instructions | |
| QLabel * instructionsLabel = new QLabel("To start tele-operation you must first insert the tool past the cannula tip (push tool clutch button and manually insert tool).\nOperator must be present to operate (sometime using COAG pedal).\nYou can use the clutch pedal to re-position your MTMs."); | |
| instructionsLabel->setWordWrap(true); | |
| mainLayout->addWidget(instructionsLabel); | |
| // 3D frames | |
| QGridLayout * frameLayout = new QGridLayout; | |
| mainLayout->addLayout(frameLayout); | |
| int column = 0; | |
| QLabel * mtmLabel = new QLabel("<b>MTM</b>"); | |
| mtmLabel->setAlignment(Qt::AlignCenter); | |
| frameLayout->addWidget(mtmLabel, 0, column); | |
| QCPGMTMWidget = new prmPositionCartesianGetQtWidget(); | |
| frameLayout->addWidget(QCPGMTMWidget, 1, column); | |
| column++; | |
| QLabel * psmLabel = new QLabel("<b>PSM</b>"); | |
| psmLabel->setAlignment(Qt::AlignCenter); | |
| frameLayout->addWidget(psmLabel, 0, column); | |
| QCPGPSMWidget = new prmPositionCartesianGetQtWidget(); | |
| frameLayout->addWidget(QCPGPSMWidget, 1, column); | |
| column++; | |
| QLabel * alignLabel = new QLabel("<b>Alignment</b>"); | |
| alignLabel->setAlignment(Qt::AlignCenter); | |
| frameLayout->addWidget(alignLabel, 0, column); | |
| QVRAlignOffset = new vctQtWidgetRotationDoubleRead(vctQtWidgetRotationDoubleRead::OPENGL_WIDGET); | |
| frameLayout->addWidget(QVRAlignOffset, 1, column); | |
| // scale/lock/unlock/messages | |
| QHBoxLayout * buttonsLayout = new QHBoxLayout; | |
| mainLayout->addLayout(buttonsLayout); | |
| // scale | |
| QSBScale = new QDoubleSpinBox(); | |
| QSBScale->setRange(0.1, 1.0); | |
| QSBScale->setSingleStep(0.1); | |
| QSBScale->setPrefix("scale "); | |
| QSBScale->setValue(mtsIntuitiveResearchKit::TeleOperationPSM::Scale); | |
| buttonsLayout->addWidget(QSBScale); | |
| // enable/disable rotation/translation | |
| QCBLockRotation = new QCheckBox("Lock Rotation"); | |
| buttonsLayout->addWidget(QCBLockRotation); | |
| QCBLockTranslation = new QCheckBox("Lock Translation"); | |
| buttonsLayout->addWidget(QCBLockTranslation); | |
| // align MTM | |
| QCBAlignMTM = new QCheckBox("Align MTM"); | |
| QCBAlignMTM->setChecked(true); | |
| buttonsLayout->addWidget(QCBAlignMTM); | |
| // messages on/off | |
| QPBLog = new QPushButton("Messages"); | |
| QPBLog->setCheckable(true); | |
| buttonsLayout->addWidget(QPBLog); | |
| // state and timing | |
| QHBoxLayout * stateAndTimingLayout = new QHBoxLayout(); | |
| mainLayout->addLayout(stateAndTimingLayout); | |
| // state info | |
| QVBoxLayout * stateLayout = new QVBoxLayout(); | |
| stateAndTimingLayout->addLayout(stateLayout); | |
| QHBoxLayout * stateDesiredLayout = new QHBoxLayout; | |
| stateLayout->addLayout(stateDesiredLayout); | |
| QLabel * label = new QLabel("Desired state"); | |
| stateDesiredLayout->addWidget(label); | |
| QLEDesiredState = new QLineEdit(""); | |
| QLEDesiredState->setReadOnly(true); | |
| stateDesiredLayout->addWidget(QLEDesiredState); | |
| stateDesiredLayout->addStretch(); | |
| QHBoxLayout * stateCurrentLayout = new QHBoxLayout; | |
| stateLayout->addLayout(stateCurrentLayout); | |
| label = new QLabel("Current state"); | |
| stateCurrentLayout->addWidget(label); | |
| QLECurrentState = new QLineEdit(""); | |
| QLECurrentState->setReadOnly(true); | |
| stateCurrentLayout->addWidget(QLECurrentState); | |
| stateCurrentLayout->addStretch(); | |
| QHBoxLayout * followingLayout = new QHBoxLayout; | |
| stateLayout->addLayout(followingLayout); | |
| label = new QLabel("Teleoperation \"mode\""); | |
| followingLayout->addWidget(label); | |
| QLEFollowing = new QLineEdit(""); | |
| QLEFollowing->setReadOnly(true); | |
| followingLayout->addWidget(QLEFollowing); | |
| followingLayout->addStretch(); | |
| // Timing | |
| QMIntervalStatistics = new mtsIntervalStatisticsQtWidget(); | |
| stateAndTimingLayout->addWidget(QMIntervalStatistics); | |
| // messages | |
| QMMessage->setupUi(); | |
| mainLayout->addWidget(QMMessage); | |
| setWindowTitle("TeleOperation Controller"); | |
| resize(sizeHint()); | |
| // setup Qt Connection | |
| connect(this, SIGNAL(SignalDesiredState(QString)), | |
| this, SLOT(SlotDesiredStateEventHandler(QString))); | |
| connect(this, SIGNAL(SignalCurrentState(QString)), | |
| this, SLOT(SlotCurrentStateEventHandler(QString))); | |
| connect(this, SIGNAL(SignalFollowing(bool)), | |
| this, SLOT(SlotFollowingEventHandler(bool))); | |
| connect(QSBScale, SIGNAL(valueChanged(double)), | |
| this, SLOT(SlotSetScale(double))); | |
| connect(this, SIGNAL(SignalScale(double)), | |
| this, SLOT(SlotScaleEventHandler(double))); | |
| connect(QCBLockRotation, SIGNAL(clicked(bool)), | |
| this, SLOT(SlotLockRotation(bool))); | |
| connect(this, SIGNAL(SignalRotationLocked(bool)), | |
| this, SLOT(SlotRotationLockedEventHandler(bool))); | |
| connect(QCBLockTranslation, SIGNAL(clicked(bool)), | |
| this, SLOT(SlotLockTranslation(bool))); | |
| connect(this, SIGNAL(SignalTranslationLocked(bool)), | |
| this, SLOT(SlotTranslationLockedEventHandler(bool))); | |
| connect(QCBAlignMTM, SIGNAL(clicked(bool)), | |
| this, SLOT(SlotSetAlignMTM(bool))); | |
| connect(this, SIGNAL(SignalAlignMTM(bool)), | |
| this, SLOT(SlotAlignMTMEventHandler(bool))); | |
| // messages | |
| connect(QPBLog, SIGNAL(clicked()), | |
| this, SLOT(SlotLogEnabled())); | |
| } | |
| void mtsTeleOperationPSMQtWidget::DesiredStateEventHandler(const std::string & state) | |
| { | |
| emit SignalDesiredState(QString(state.c_str())); | |
| } | |
| void mtsTeleOperationPSMQtWidget::CurrentStateEventHandler(const std::string & state) | |
| { | |
| emit SignalCurrentState(QString(state.c_str())); | |
| } | |
| void mtsTeleOperationPSMQtWidget::FollowingEventHandler(const bool & following) | |
| { | |
| emit SignalFollowing(following); | |
| } | |
| void mtsTeleOperationPSMQtWidget::ScaleEventHandler(const double & scale) | |
| { | |
| emit SignalScale(scale); | |
| } | |
| void mtsTeleOperationPSMQtWidget::RotationLockedEventHandler(const bool & lock) | |
| { | |
| emit SignalRotationLocked(lock); | |
| } | |
| void mtsTeleOperationPSMQtWidget::TranslationLockedEventHandler(const bool & lock) | |
| { | |
| emit SignalTranslationLocked(lock); | |
| } | |
| void mtsTeleOperationPSMQtWidget::AlignMTMEventHandler(const bool & align) | |
| { | |
| emit SignalAlignMTM(align); | |
| } | |
| void mtsTeleOperationPSMQtWidget::SlotLogEnabled(void) | |
| { | |
| LogEnabled = QPBLog->isChecked(); | |
| if (LogEnabled) { | |
| QMMessage->show(); | |
| } else { | |
| QMMessage->hide(); | |
| } | |
| } | |