alignment_widget.cpp
Go to the documentation of this file.
1 #include <QVBoxLayout>
2 #include <QPushButton>
3 #include <QLabel>
4 #include <QFuture>
5 #include <QtConcurrent/QtConcurrentRun>
6 
7 #include "alignment_widget.h"
8 
10 {
11  setObjectName("AlignmentWidget_");
12  alignment_button_ = new QPushButton;
13  alignment_button_->setText("Start Alignment");
14 
15  QVBoxLayout* alignment_layout = new QVBoxLayout(this);
16  alignment_layout->addWidget(alignment_button_);
17 
18  // Connect handlers
19  connect(alignment_button_, SIGNAL(released()), this, SLOT(alignmentButtonHandler()));
20 
21  //Setup client
22  alignment_service_ = nh_.serviceClient<fanuc_grinding_alignment::AlignmentService>("alignment_service");
23 
24  QFuture<void> future = QtConcurrent::run(this, &fanuc_grinding_rviz_plugin::AlignmentWidget::connectToServices);
25 }
26 
28 {
29  Q_EMIT guiChanged();
31  updateGUI();
32 }
33 
34 void fanuc_grinding_rviz_plugin::AlignmentWidget::setAlignmentParams(const fanuc_grinding_alignment::AlignmentService::Request &params)
35 {
36  srv_alignment_.request = params;
37  updateGUI();
38 }
39 
41 {
42  // Not implemented yet
43 }
44 
46 {
47  // Not implemented yet
48 }
49 
51  const QString scan_filename)
52 {
53  srv_alignment_.request.CADFileName = cad_filename.toStdString();
54  srv_alignment_.request.ScanFileName = scan_filename.toStdString();
55 }
56 
58 {
59  // get CAD and Scan params which are stored in grinding rviz plugin
60  Q_EMIT getCADAndScanParams();
61 
62  // Start client service call in an other thread
63  QFuture<void> future = QtConcurrent::run(this, &AlignmentWidget::alignment);
64 }
65 
67 {
68  // Disable UI
69  Q_EMIT enablePanel(false);
70 
71  // Call client service
73  Q_EMIT sendStatus(QString::fromStdString(srv_alignment_.response.ReturnMessage));
74 
75  if(srv_alignment_.response.ReturnStatus == true)
76  Q_EMIT enablePanelComparison();
77  else
78  {
79  Q_EMIT sendMsgBox("Error aligning meshes",
80  QString::fromStdString(srv_alignment_.response.ReturnMessage), "");
81  }
82 
83  // Re-enable UI
84  Q_EMIT enablePanel(true); // Enable UI
85 }
86 
88 {
89  Q_EMIT enablePanel(false);
90 
91  // Check offset_move_robot_ connection
92  Q_EMIT sendStatus("Connecting to service");
93  while (ros::ok())
94  {
96  {
97  ROS_INFO_STREAM(objectName().toStdString() + " RViz panel connected to the service " << alignment_service_.getService());
98  Q_EMIT sendStatus(QString::fromStdString("RViz panel connected to the service: " + alignment_service_.getService()));
99  break;
100  }
101  else
102  {
103  ROS_WARN_STREAM(objectName().toStdString() + " RViz panel could not connect to ROS service:\n\t" << alignment_service_.getService());
104  Q_EMIT sendStatus(QString::fromStdString("RViz panel could not connect to ROS service: " + alignment_service_.getService()));
105  sleep(1);
106  }
107  }
108 
109  ROS_INFO_STREAM(objectName().toStdString() + " service connections have been made");
110  Q_EMIT sendStatus("Ready to take commands");
111  Q_EMIT enablePanel(true);
112 }
113 
114 // Save all configuration data from this panel to the given Config object
116 {
117  // NOT IMPLEMENTED YET
118 }
119 
120 // Load all configuration data for this panel from the given Config object.
122 {
123  // NOT IMPLEMENTED YET
124 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void load(const rviz::Config &config)
fanuc_grinding_alignment::AlignmentService srv_alignment_
void sendMsgBox(const QString title, const QString msg, const QString info_msg)
bool call(MReq &req, MRes &res)
void setCADAndScanParams(const QString cad_filename, const QString scan_filename)
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
ROSCPP_DECL bool ok()
#define ROS_WARN_STREAM(args)
void setAlignmentParams(const fanuc_grinding_alignment::AlignmentService::Request &params)
#define ROS_INFO_STREAM(args)
std::string getService()
void sendStatus(const QString status)


rviz_plugin
Author(s): Kévin Bolloré, Victor Lamoine - Institut Maupertuis
autogenerated on Thu Dec 19 2019 03:38:28