entry_exit_strategies.cpp
Go to the documentation of this file.
2 
3 namespace ram_qt_guis
4 {
6  rviz::Panel(parent)
7 {
8  setObjectName("Entry, exit strategies");
9  setName(objectName());
10 
11  // Entry
12  entry_number_of_poses_ = new QSpinBox;
13  entry_number_of_poses_->setRange(1, 100);
14 
15  entry_angle_ = new QDoubleSpinBox;
16  entry_angle_->setRange(-180, 180);
17  entry_angle_->setSingleStep(10);
18  entry_angle_->setSuffix(" °");
19 
20  entry_distance_ = new QDoubleSpinBox;
21  entry_distance_->setRange(0, 1000);
22  entry_distance_->setSingleStep(1);
23  entry_distance_->setSuffix(" mm");
24 
25  QGridLayout* entry_layout = new QGridLayout;
26  entry_layout->addWidget(new QLabel("Number of poses:"), 0, 0);
27  entry_layout->addWidget(entry_number_of_poses_, 0, 1);
28  entry_layout->addWidget(new QLabel("Angle:"));
29  entry_layout->addWidget(entry_angle_);
30  entry_layout->addWidget(new QLabel("Distance:"));
31  entry_layout->addWidget(entry_distance_);
32 
33  // Exit
34  exit_number_of_poses_ = new QSpinBox;
35  exit_number_of_poses_->setRange(1, 100);
36 
37  exit_angle_ = new QDoubleSpinBox;
38  exit_angle_->setRange(-180, 180);
39  exit_angle_->setSingleStep(10);
40  exit_angle_->setSuffix(" °");
41 
42  exit_distance_ = new QDoubleSpinBox;
43  exit_distance_->setRange(0.0, 1000);
44  exit_distance_->setSingleStep(1);
45  exit_distance_->setSuffix(" mm");
46 
47  entry_exit_button_ = new QPushButton("Entry / exit strategies");
48 
49  QGridLayout* exit_layout = new QGridLayout;
50  exit_layout->addWidget(new QLabel("Number of poses:"), 0, 0);
51  exit_layout->addWidget(exit_number_of_poses_, 0, 1);
52  exit_layout->addWidget(new QLabel("Angle:"));
53  exit_layout->addWidget(exit_angle_);
54  exit_layout->addWidget(new QLabel("Distance:"));
55  exit_layout->addWidget(exit_distance_);
56 
57  // Scroll area
58  QVBoxLayout *scroll_widget_layout = new QVBoxLayout();
59  QWidget *scroll_widget = new QWidget;
60  scroll_widget->setLayout(scroll_widget_layout);
61  QScrollArea *scroll_area = new QScrollArea;
62  scroll_area->setWidget(scroll_widget);
63  scroll_area->setWidgetResizable(true);
64  scroll_area->setFrameShape(QFrame::NoFrame);
65 
66  QVBoxLayout* main_layout = new QVBoxLayout(this);
67  main_layout->addWidget(scroll_area);
68  scroll_widget_layout->addWidget(new QLabel("<b>Entry strategy</b>"));
69  scroll_widget_layout->addLayout(entry_layout);
70  scroll_widget_layout->addStretch(1);
71  scroll_widget_layout->addWidget(new QLabel("<b>Exit strategy</b>"));
72  scroll_widget_layout->addLayout(exit_layout);
73  scroll_widget_layout->addStretch(1);
74  scroll_widget_layout->addWidget(entry_exit_button_);
75  scroll_widget_layout->addStretch(1);
76 
77  connect(this, SIGNAL(displayErrorMessageBox(const QString, const QString, const QString)), this,
78  SLOT(displayErrorBoxHandler(const QString, const QString, const QString)));
79 
80  connect(entry_exit_button_, SIGNAL(clicked()), this, SLOT(sendEntryExitParameters()));
81 
82  // connect with configChanged signal
83  connect(entry_number_of_poses_, SIGNAL(valueChanged(int)), this, SIGNAL(configChanged()));
84  connect(entry_angle_, SIGNAL(valueChanged(double)), this, SIGNAL(configChanged()));
85  connect(entry_distance_, SIGNAL(valueChanged(double)), this, SIGNAL(configChanged()));
86 
87  connect(exit_number_of_poses_, SIGNAL(valueChanged(int)), this, SIGNAL(configChanged()));
88  connect(exit_angle_, SIGNAL(valueChanged(double)), this, SIGNAL(configChanged()));
89  connect(exit_distance_, SIGNAL(valueChanged(double)), this, SIGNAL(configChanged()));
90 
91  // Setup service clients
92  entry_parameters_client_ = nh_.serviceClient<ram_utils::EntryExitParameters>("ram/information/entry_parameters");
93  exit_parameters_client_ = nh_.serviceClient<ram_utils::EntryExitParameters>("ram/information/exit_parameters");
94 
95  // Check connection of clients
97 }
98 
100 {
101 }
102 
104 {
105  Q_EMIT configChanged();
106 
107  entry_parameters_.request.angle = entry_angle_->value() * M_PI / 180.0; // Convert in radians
108  entry_parameters_.request.distance = entry_distance_->value() / 1000.0; // Convert meters in millimeters
109  entry_parameters_.request.number_of_poses = entry_number_of_poses_->value();
110 
111  exit_parameters_.request.angle = exit_angle_->value() * M_PI / 180.0;
112  exit_parameters_.request.distance = exit_distance_->value() / 1000.0;
113  exit_parameters_.request.number_of_poses = exit_number_of_poses_->value();
114 }
115 
117 {
118  Q_EMIT setEnabled(false);
119 
120  while (nh_.ok())
121  {
122  if (client.waitForExistence(ros::Duration(2)))
123  {
125  "RViz panel " << getName().toStdString() << " connected to the service " << client.getService());
126  break;
127  }
128  else
129  {
131  "RViz panel " << getName().toStdString() << " could not connect to ROS service: " << client.getService());
132  ros::Duration(1).sleep();
133  }
134  }
135 }
136 
138 {
139  Q_EMIT setEnabled(false);
140 
143 
144  ROS_INFO_STREAM("RViz panel " << getName().toStdString() << " services connections have been made");
145  Q_EMIT setEnabled(true);
146 }
147 
149  const QString message,
150  const QString info_msg)
151 {
152  bool old_state(isEnabled());
153  Q_EMIT setEnabled(false);
154  QMessageBox msg_box;
155  msg_box.setWindowTitle(title);
156  msg_box.setText(message);
157  msg_box.setInformativeText(info_msg);
158  msg_box.setIcon(QMessageBox::Critical);
159  msg_box.setStandardButtons(QMessageBox::Ok);
160  msg_box.exec();
161  Q_EMIT setEnabled(old_state);
162 }
163 
165 {
166  Q_EMIT setEnabled(false);
167 
168  // Call service
171 
172  if (!success)
173  {
174  Q_EMIT displayErrorMessageBox("Service call failed", QString::fromStdString(entry_parameters_client_.getService()),
175  "Check the logs!");
176  Q_EMIT setEnabled(true);
177  return;
178  }
179 
180  // Call service
183 
184  if (!success)
185  {
186  Q_EMIT displayErrorMessageBox("Service call failed",
187  QString::fromStdString(exit_parameters_client_.getService()),
188  "Check the logs!");
189  Q_EMIT setEnabled(true);
190  return;
191  }
192 
193  Q_EMIT setEnabled(true);
194 }
195 
197 {
198  int tmp_int(0);
199  float tmp_float(0.01);
200  Q_EMIT configChanged();
201 
202  if (config.mapGetInt("entry_number_of_poses", &tmp_int))
203  entry_number_of_poses_->setValue(tmp_int);
204  else
205  entry_number_of_poses_->setValue(1);
206 
207  if (config.mapGetFloat("entry_angle", &tmp_float))
208  entry_angle_->setValue(tmp_float);
209  else
210  entry_angle_->setValue(90);
211 
212  if (config.mapGetFloat("entry_distance", &tmp_float))
213  entry_distance_->setValue(tmp_float);
214  else
215  entry_distance_->setValue(10);
216 
217  if (config.mapGetInt("exit_number_of_poses", &tmp_int))
218  exit_number_of_poses_->setValue(tmp_int);
219  else
220  exit_number_of_poses_->setValue(1);
221 
222  if (config.mapGetFloat("exit_angle", &tmp_float))
223  exit_angle_->setValue(tmp_float);
224  else
225  exit_angle_->setValue(90);
226 
227  if (config.mapGetFloat("exit_distance", &tmp_float))
228  exit_distance_->setValue(tmp_float);
229  else
230  exit_distance_->setValue(10);
231 
232  Q_EMIT sendEntryExitParameters();
233  rviz::Panel::load(config);
234 }
235 
237  {
238  config.mapSetValue("entry_number_of_poses", entry_number_of_poses_->value());
239  config.mapSetValue("entry_angle", entry_angle_->value());
240  config.mapSetValue("entry_distance", entry_distance_->value());
241 
242  config.mapSetValue("exit_number_of_poses", exit_number_of_poses_->value());
243  config.mapSetValue("exit_angle", exit_angle_->value());
244  config.mapSetValue("exit_distance", exit_distance_->value());
245 
246  rviz::Panel::save(config);
247 }
248 
249 }
250 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ram_utils::EntryExitParameters exit_parameters_
bool sleep() const
bool call(MReq &req, MRes &res)
bool mapGetFloat(const QString &key, float *value_out) const
void connectToService(ros::ServiceClient &client)
void configChanged()
void mapSetValue(const QString &key, QVariant value)
void load(const rviz::Config &config)
virtual void setName(const QString &name)
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
virtual QString getName() const
bool mapGetInt(const QString &key, int *value_out) const
ram_utils::EntryExitParameters entry_parameters_
void save(rviz::Config config) const
void displayErrorBoxHandler(const QString title, const QString message, const QString info_msg)
#define ROS_INFO_STREAM(args)
std::string getService()
virtual void save(Config config) const
bool ok() const
#define ROS_ERROR_STREAM(args)
virtual void load(const Config &config)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void displayErrorMessageBox(const QString, const QString, const QString)


ram_qt_guis
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:50:11