UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-17)
usRobotManualControlWidget.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ustk software.
4  * Copyright (C) 2016 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ustk with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * This software was developed at:
17  * Inria Rennes - Bretagne Atlantique
18  * Campus Universitaire de Beaulieu
19  * 35042 Rennes Cedex
20  * France
21  *
22  * If you have questions regarding the use of this file, please contact
23  * Inria at ustk@inria.fr
24  *
25  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27  *
28  * Authors:
29  * Marc Pouliquen
30  *
31  *****************************************************************************/
32 
38 #include <iostream>
39 #include <visp3/ustk_gui/usRobotManualControlWidget.h>
40 
41 #ifdef USTK_HAVE_VTK_QT
42 
44 {
45  this->setStyleSheet("QGroupBox { border: 2px solid Lightgray;}");
46 
47  this->setMinimumWidth(160);
48  this->setMinimumHeight(200);
49 
50  txLabel = new QLabel("vx: ", this);
51  tyLabel = new QLabel("vy: ", this);
52  tzLabel = new QLabel("vz: ", this);
53  wxLabel = new QLabel("wx: ", this);
54  wyLabel = new QLabel("wy: ", this);
55  wzLabel = new QLabel("wz: ", this);
56 
57  txSlider = new QSlider(Qt::Horizontal, this);
58  txSlider->setValue(0);
59  txSlider->setRange(-100, 100);
60  tySlider = new QSlider(Qt::Horizontal, this);
61  tySlider->setValue(0);
62  tySlider->setRange(-100, 100);
63  tzSlider = new QSlider(Qt::Horizontal, this);
64  tzSlider->setValue(0);
65  tzSlider->setRange(-100, 100);
66 
67  wxSlider = new QSlider(Qt::Horizontal, this);
68  wxSlider->setValue(0);
69  wxSlider->setRange(-80, 80);
70  wySlider = new QSlider(Qt::Horizontal, this);
71  wySlider->setValue(0);
72  wySlider->setRange(-80, 80);
73  wzSlider = new QSlider(Qt::Horizontal, this);
74  wzSlider->setValue(0);
75  wzSlider->setRange(-80, 80);
76 
77  initPushButton = new QPushButton(this);
78  initPushButton->setText(QString("Init robot"));
79  initPushButton->setEnabled(true);
80  startStopPushButton = new QPushButton(this);
81  startStopPushButton->setText(QString("Start robot"));
82  startStopPushButton->setEnabled(false);
83 
84  labelRobotState = new QLabel(this);
85  labelRobotState->setText("Press security handle, then click Init robot");
86 
87  txSlider->setMinimumWidth(150);
88  tySlider->setMinimumWidth(150);
89  tzSlider->setMinimumWidth(150);
90  wxSlider->setMinimumWidth(150);
91  wySlider->setMinimumWidth(150);
92  wzSlider->setMinimumWidth(150);
93 
94  automaticForceButton = new QPushButton(this);
95  automaticForceButton->setText(QString("Enable automatic force control"));
96  automaticForceButton->setEnabled(true);
97 
98  L = new QGridLayout;
99  L->addWidget(txLabel, 0, 0, Qt::AlignRight);
100  L->addWidget(tyLabel, 1, 0, Qt::AlignRight);
101  L->addWidget(tzLabel, 2, 0, Qt::AlignRight);
102  L->addWidget(wxLabel, 3, 0, Qt::AlignRight);
103  L->addWidget(wyLabel, 4, 0, Qt::AlignRight);
104  L->addWidget(wzLabel, 5, 0, Qt::AlignRight);
105  L->addWidget(initPushButton, 6, 0, 1, 2, Qt::AlignCenter);
106  L->addWidget(startStopPushButton, 7, 0, 1, 2, Qt::AlignCenter);
107  L->addWidget(labelRobotState, 8, 0, 1, 2, Qt::AlignCenter);
108  L->addWidget(automaticForceButton, 9, 0, 1, 2, Qt::AlignCenter);
109 
110  L->addWidget(txSlider, 0, 1, Qt::AlignLeft);
111  L->addWidget(tySlider, 1, 1, Qt::AlignLeft);
112  L->addWidget(tzSlider, 2, 1, Qt::AlignLeft);
113  L->addWidget(wxSlider, 3, 1, Qt::AlignLeft);
114  L->addWidget(wySlider, 4, 1, Qt::AlignLeft);
115  L->addWidget(wzSlider, 5, 1, Qt::AlignLeft);
116 
117  this->setLayout(L);
118  // Setting up connections
119  setUpConnections();
120 }
121 
123 {
124  delete txLabel;
125  delete tyLabel;
126  delete tzLabel;
127  delete wxLabel;
128  delete wyLabel;
129  delete wzLabel;
130  // Sliders
131  delete txSlider;
132  delete tySlider;
133  delete tzSlider;
134  delete wxSlider;
135  delete wySlider;
136  delete wzSlider;
137 
138  delete startStopPushButton;
139  delete labelRobotState;
140 
141  delete automaticForceButton;
142 
143  // Layouts
144  delete L;
145 }
146 
147 void usRobotManualControlWidget::setUpConnections()
148 {
149  // Connection slider release action with release slot
150  connect(txSlider, SIGNAL(sliderReleased()), SLOT(releaseSlider()));
151  connect(tySlider, SIGNAL(sliderReleased()), SLOT(releaseSlider()));
152  connect(tzSlider, SIGNAL(sliderReleased()), SLOT(releaseSlider()));
153  connect(wxSlider, SIGNAL(sliderReleased()), SLOT(releaseSlider()));
154  connect(wySlider, SIGNAL(sliderReleased()), SLOT(releaseSlider()));
155  connect(wzSlider, SIGNAL(sliderReleased()), SLOT(releaseSlider()));
156  // Connection Signal-signal to use in a main GUI
157  connect(txSlider, SIGNAL(valueChanged(int)), SIGNAL(changeVX(int)));
158  connect(tySlider, SIGNAL(valueChanged(int)), SIGNAL(changeVY(int)));
159  connect(tzSlider, SIGNAL(valueChanged(int)), SIGNAL(changeVZ(int)));
160  connect(wxSlider, SIGNAL(valueChanged(int)), SIGNAL(changeWX(int)));
161  connect(wySlider, SIGNAL(valueChanged(int)), SIGNAL(changeWY(int)));
162  connect(wzSlider, SIGNAL(valueChanged(int)), SIGNAL(changeWZ(int)));
163  // signal-signal connection for start / stop robot buttons
164  connect(initPushButton, SIGNAL(clicked()), SIGNAL(initRobot()));
165  automaticForceButton->setText(QString("Enable automatic force control"));
166  automaticForceButton->setEnabled(false);
167 
168  // gui updates
169  connect(initPushButton, SIGNAL(clicked()), this, SLOT(robotInitialized()));
170  connect(startStopPushButton, SIGNAL(clicked()), this, SLOT(setRobotActivation()));
171 
172  connect(automaticForceButton, SIGNAL(clicked()), this, SLOT(activateAutomaticForceControlSlot()));
173 }
174 
176 {
177  QSlider *slider = dynamic_cast<QSlider *>(sender());
178  slider->setValue(0);
179 }
180 
182 {
183  startStopPushButton->setEnabled(true);
184  startStopPushButton->setText(QString("Start robot"));
185  labelRobotState->setText(QString("Now press the viper start button (flashing)"));
186  this->update();
187 }
188 
190 {
191  if (startStopPushButton->text() == QString("Start robot")) {
192  emit(startRobot());
193  startStopPushButton->setText(QString("Stop robot"));
194  labelRobotState->setText(QString("Robot OK, you can move it or stop it"));
195  automaticForceButton->setEnabled(true);
196  this->update();
197  }
198  else if (startStopPushButton->text() == QString("Stop robot")) {
199  emit(stopRobot());
200  startStopPushButton->setText(QString("Start robot"));
201  labelRobotState->setText(QString("Robot stopped"));
202  automaticForceButton->setEnabled(false);
203  this->update();
204  }
205 }
206 
208 {
209  labelRobotState->setText(text);
210  this->update();
211 }
212 
214 {
215  startStopPushButton->setEnabled(false);
216  labelRobotState->setText("Robot Error ! To restart, press security handle, then click Init robot");
217  automaticForceButton->setText(QString("Enable automatic force control"));
218  automaticForceButton->setEnabled(false);
219  this->update();
220 }
221 
222 void usRobotManualControlWidget::activateAutomaticForceControlSlot()
223 {
224 
225  bool activate = automaticForceButton->text() == QString("Enable automatic force control");
226 
227  txSlider->setEnabled(!activate);
228  tySlider->setEnabled(!activate);
229  automaticForceButton->setText(QString("Enable automatic force control"));
230  tzSlider->setEnabled(!activate);
231  wxSlider->setEnabled(!activate);
232  wySlider->setEnabled(!activate);
233  wzSlider->setEnabled(!activate);
234  if (activate) {
235  automaticForceButton->setText(QString("Disable automatic force control"));
236  labelRobotState->setText("Automatic force control enabled");
238  }
239  else {
240  automaticForceButton->setText(QString("Enable automatic force control"));
241  labelRobotState->setText("Manual robot control");
243  }
244 }
245 
246 #endif