UsTK : Ultrasound ToolKit  version 2.0.1 under development (2025-03-12)
tutorial-robot-control-gui.cpp
1 
3 #include <iostream>
4 #include <visp3/ustk_core/usConfig.h>
5 
6 #if defined(VISP_HAVE_MODULE_USTK_GUI) && defined(VISP_HAVE_MODULE_USTK_GRABBER) && defined(VISP_HAVE_VIPER850)
7 
8 #include <visp3/ustk_grabber/usNetworkGrabberPreScan2D.h>
9 #include <visp3/ustk_gui/usConfidenceMapController.h>
10 #include <visp3/ustk_gui/usImageDisplayWidgetRobotControl.h>
11 #include <visp3/ustk_gui/usRobotManualControlWidget.h>
12 #include <visp3/ustk_gui/usUltrasonixClientWidget.h>
13 #include <visp3/ustk_gui/usViper850WrapperVelocityControl.h>
14 
15 #include <QApplication>
16 #include <QHBoxLayout>
17 #include <QMainWindow>
18 
19 int main(int argc, char **argv)
20 {
21 
22  QApplication app(argc, argv);
23  app.setApplicationName(QString("USTK display widget"));
24 
25  // Qt widgets
27  widget->enableControlArrows();
28  widget->enableFeaturesDisplay();
29 
30  usRobotManualControlWidget *robotControlPanel = new usRobotManualControlWidget();
31  usUltrasonixClientWidget *ultrasonixControlWidet = new usUltrasonixClientWidget();
32 
33  QWidget *centralWidget = new QWidget();
34  QHBoxLayout *mainLayout = new QHBoxLayout();
35  mainLayout->addWidget(ultrasonixControlWidet);
36  mainLayout->addWidget(widget, 2);
37  mainLayout->addWidget(robotControlPanel);
38  centralWidget->setLayout(mainLayout);
39 
40  // robot control
41  QThread *threadRobotControl = new QThread();
43  viperControl.moveToThread(threadRobotControl);
44  threadRobotControl->start();
45  viperControl.run();
46 
47  // confidence-map-based controller
48  usConfidenceMapController *confidenceController = new usConfidenceMapController();
49  QThread *confidenceThread = new QThread();
50  confidenceController->moveToThread(confidenceThread);
51  confidenceThread->start();
52 
53  // grabber
54  QThread *grabbingThread = new QThread();
56  qtGrabber->moveToThread(grabbingThread);
57  grabbingThread->start();
58 
59  QMainWindow window;
60  window.setCentralWidget(centralWidget);
61  window.resize(1280, 480);
62  window.show();
63 
64  // sliders robot controls
65  QObject::connect(robotControlPanel, SIGNAL(changeVX(int)), &viperControl, SLOT(setXVelocity(int)));
66  QObject::connect(robotControlPanel, SIGNAL(changeVY(int)), &viperControl, SLOT(setYVelocity(int)));
67  QObject::connect(robotControlPanel, SIGNAL(changeVZ(int)), &viperControl, SLOT(setZVelocity(int)));
68  QObject::connect(robotControlPanel, SIGNAL(changeWX(int)), &viperControl, SLOT(setXAngularVelocity(int)));
69  QObject::connect(robotControlPanel, SIGNAL(changeWY(int)), &viperControl, SLOT(setYAngularVelocity(int)));
70  QObject::connect(robotControlPanel, SIGNAL(changeWZ(int)), &viperControl, SLOT(setZAngularVelocity(int)));
71 
72  // buttons robot controls
73  QObject::connect(widget, SIGNAL(moveLeft()), &viperControl, SLOT(moveLeft()));
74  QObject::connect(widget, SIGNAL(moveRight()), &viperControl, SLOT(moveRight()));
75  QObject::connect(widget, SIGNAL(stopMove()), &viperControl, SLOT(stopMoveLateral()));
76 
77  QObject::connect(robotControlPanel, SIGNAL(initRobot()), &viperControl, SLOT(init()));
78  QObject::connect(robotControlPanel, SIGNAL(startRobot()), &viperControl, SLOT(run()));
79  QObject::connect(robotControlPanel, SIGNAL(stopRobot()), &viperControl, SLOT(stop()));
80 
81  QObject::connect(robotControlPanel, SIGNAL(activateAutomaticForceControl()), &viperControl,
82  SLOT(startAutomaticForceControl()));
83  QObject::connect(robotControlPanel, SIGNAL(disableAutomaticForceControl()), &viperControl,
84  SLOT(stopAutomaticForceControl()));
85 
86  // manage errors
87  QObject::connect(&viperControl, SIGNAL(robotError()), robotControlPanel, SLOT(robotErrorSlot()));
88 
89  // grabber control
90  qRegisterMetaType<QHostAddress>("QHostAddress");
91  qRegisterMetaType<usNetworkGrabber::usInitHeaderSent>("usNetworkGrabber::usInitHeaderSent");
92  QObject::connect(ultrasonixControlWidet, SIGNAL(connectToServer(QHostAddress)), qtGrabber,
93  SLOT(connectToServer(QHostAddress)));
94  QObject::connect(ultrasonixControlWidet, SIGNAL(initAcquisition(usNetworkGrabber::usInitHeaderSent)), qtGrabber,
95  SLOT(initAcquisitionSlot(usNetworkGrabber::usInitHeaderSent)));
96  QObject::connect(ultrasonixControlWidet, SIGNAL(center3DProbeMotor()), qtGrabber, SLOT(center3DProbeMotor()));
97  QObject::connect(ultrasonixControlWidet, SIGNAL(runAcquisition()), qtGrabber, SLOT(runAcquisition()));
98  QObject::connect(ultrasonixControlWidet, SIGNAL(stopAcquisition()), qtGrabber, SLOT(stopAcquisition()));
99 
100  // send new images via qt signal
101  qRegisterMetaType<usImagePreScan2D<unsigned char> >("usImagePreScan2D<unsigned char>");
102  QObject::connect(qtGrabber, SIGNAL(newFrame(usImagePreScan2D<unsigned char>)), widget,
103  SLOT(updateFrame(usImagePreScan2D<unsigned char>)));
104 
105  // confidence controller
106  QObject::connect(qtGrabber, SIGNAL(newFrame(usImagePreScan2D<unsigned char>)), confidenceController,
107  SLOT(updateImage(usImagePreScan2D<unsigned char>)));
108  QObject::connect(widget, SIGNAL(confidenceServoing(bool)), confidenceController, SLOT(activateController(bool)));
109  QObject::connect(confidenceController, SIGNAL(updateProbeOrientation(int)), &viperControl,
110  SLOT(setZAngularVelocity(int)));
111  QObject::connect(confidenceController, SIGNAL(confidenceBarycenterAngle(double)), widget,
112  SLOT(updateConfidenceAngle(double)));
113  QObject::connect(confidenceController, SIGNAL(confidenceMap(usImagePreScan2D<unsigned char>)), widget,
114  SLOT(updateConfidenceMap(usImagePreScan2D<unsigned char>)));
115 
116  app.exec();
117 
118  grabbingThread->exit();
119 
120  delete widget;
121  delete robotControlPanel;
122  delete centralWidget;
123  delete mainLayout;
124  delete grabbingThread;
125  delete qtGrabber;
126 
127  return 0;
128 }
129 
130 #else
131 int main()
132 {
133  std::cout << "You should build ustk_gui and ustk_grabber, and have a viper850 robot to run this tutorial"
134  << std::endl;
135  return 0;
136 }
137 
138 #endif
Qt widget class for 2D ultrasound image display, containing robot control tools.
Specific class to grab pre-scan frames from the ultrasound station on the network.