path_planning.cpp
Go to the documentation of this file.
2 
3 namespace ram_qt_guis
4 {
5 
6 PathPlanning::PathPlanning(QWidget* parent) :
7  rviz::Panel(parent)
8 {
9  setObjectName("PathPlanning");
10  setName(objectName());
11 
12  QHBoxLayout *select_algorithm_layout = new QHBoxLayout;
13  select_algorithm_layout->addWidget(new QLabel("Generation algorithm:"));
14 
15  select_algorithm_ = new QComboBox;
16  select_algorithm_layout->addWidget(select_algorithm_);
17 
18  algorithm_description_ = new QLabel;
19 
20  algorithm_stacked_widget_ = new QStackedWidget();
21 
22  generate_trajectory_button_ = new QPushButton("Generate trajectory");
23 
24  // Scroll area
25  QVBoxLayout *scroll_widget_layout = new QVBoxLayout();
26  QWidget *scroll_widget = new QWidget;
27  scroll_widget->setLayout(scroll_widget_layout);
28  QScrollArea *scroll_area = new QScrollArea;
29  scroll_area->setWidget(scroll_widget);
30  scroll_area->setWidgetResizable(true);
31  scroll_area->setFrameShape(QFrame::NoFrame);
32 
33  // Main layout
34  QVBoxLayout* main_layout = new QVBoxLayout(this);
35  main_layout->addWidget(scroll_area);
36  scroll_widget_layout->addLayout(select_algorithm_layout);
37  scroll_widget_layout->addWidget(algorithm_description_);
38  scroll_widget_layout->addStretch(1);
39  scroll_widget_layout->addWidget(algorithm_stacked_widget_);
40  scroll_widget_layout->addStretch(2);
41  scroll_widget_layout->addWidget(generate_trajectory_button_);
42 
43  connect(this, SIGNAL(displayErrorMessageBox(const QString, const QString, const QString)), this,
44  SLOT(displayErrorBoxHandler(const QString, const QString, const QString)));
45 
46  // Algorithm generators
50 
51  // Add algorithms names
52  select_algorithm_->addItem(QString::fromStdString(donghong_ding_generator.name_));
53  select_algorithm_->addItem(QString::fromStdString(contours_generator.name_));
54  select_algorithm_->addItem(QString::fromStdString(follow_poses_generator.name_));
55 
56  // Add algorithms descriptions
58  algorithm_descriptions_.push_back(donghong_ding_generator.description_);
59  algorithm_descriptions_.push_back(contours_generator.description_);
60  algorithm_descriptions_.push_back(follow_poses_generator.description_);
61 
62  // Algorithm widget
66 
67  // Add algorithm widget
71 
72  // Action clients
73  donghong_ding_ac_.reset(new DonghongDingActionClient(donghong_ding_generator.service_name_, true));
74  contours_ac_.reset(new ContoursActionClient(contours_generator.service_name_, true));
75  follow_poses_ac_.reset(new FollowPosesActionClient(follow_poses_generator.service_name_, true));
76 
77  connect(donghong_ding_ui_, SIGNAL(valueChanged()), this, SIGNAL(configChanged()));
78  connect(contours_ui_, SIGNAL(valueChanged()), this, SIGNAL(configChanged()));
79  connect(follow_poses_ui_, SIGNAL(valueChanged()), this, SIGNAL(configChanged()));
80 }
81 
83 {
84 }
85 
87 {
88  Q_EMIT setEnabled(false);
89  // Generate trajectory
90 
91  donghong_ding_ac_->waitForServer();
92  contours_ac_->waitForServer();
93  follow_poses_ac_->waitForServer();
94 
95  ROS_INFO_STREAM("RViz panel " << getName().toStdString() << " actions connections have been made");
96 
97  connect(select_algorithm_, SIGNAL(currentIndexChanged(int)), this, SLOT(algorithmChanged()));
98  connect(select_algorithm_, SIGNAL(currentIndexChanged(int)), this, SIGNAL(configChanged()));
99 
100  select_algorithm_->setCurrentIndex(loaded_last_algorithm_);
101  Q_EMIT select_algorithm_->currentIndexChanged(loaded_last_algorithm_);
102  Q_EMIT setEnabled(true);
103 }
104 
106 {
107  Q_EMIT setEnabled(false);
108 
109  generate_trajectory_button_->disconnect();
110 
111  // Change description
112  algorithm_description_->setText(QString::fromStdString(algorithm_descriptions_[select_algorithm_->currentIndex()]));
113  // Change widget
114  algorithm_stacked_widget_->setCurrentIndex(select_algorithm_->currentIndex());
115 
116  // Connect button
117  switch (select_algorithm_->currentIndex())
118  {
119  case 0:
120  {
121  connect(generate_trajectory_button_, SIGNAL(clicked()), this, SLOT(donghongDingButtonHandler()));
122  break;
123  }
124  case 1:
125  {
126  connect(generate_trajectory_button_, SIGNAL(clicked()), this, SLOT(contoursButtonHandler()));
127  break;
128  }
129  case 2:
130  {
131  connect(generate_trajectory_button_, SIGNAL(clicked()), this, SLOT(FollowPosesButtonHandler()));
132  break;
133  }
134 
135  default:
136  displayErrorBoxHandler("Operation", "Error selecting algorithm", "");
137  break;
138  }
139  Q_EMIT setEnabled(true);
140 }
141 
142 // DonghongDing
144 {
145  Q_EMIT configChanged();
146  Q_EMIT setEnabled(false);
147 
148  std::string error = donghong_ding_ui_->fillGoal(donghong_ding_goal_);
149  if (!error.empty())
150  {
151  Q_EMIT displayErrorBoxHandler("Error filling goal", QString::fromStdString(error), "");
152  Q_EMIT setEnabled(true);
153  return;
154  }
155 
156  progress_dialog_ = std::make_shared<ProgressDialog>();
157 
158  donghong_ding_ac_->sendGoal(donghong_ding_goal_, boost::bind(&PathPlanning::donghongDingDoneCb, this, _1, _2), NULL,
159  boost::bind(&PathPlanning::donghongDingFeedbackCb, this, _1));
160 
161  if (!progress_dialog_->exec())
162  {
164  donghong_ding_ac_->cancelAllGoals();
165  }
166 
167  progress_dialog_.reset();
168 
169  Q_EMIT setEnabled(true);
170 }
171 
173  const ram_path_planning::DonghongDingResultConstPtr &result)
174 {
175  ros::Duration(0.1).sleep(); // Otherwise progress window bugs
176 
178  {
179  if (result->error_msg.empty())
180  {
181  if (progress_dialog_)
182  progress_dialog_->accept();
183  }
184  }
185 
187  {
188  if (progress_dialog_)
189  progress_dialog_->reject();
190 
191  Q_EMIT displayErrorMessageBox("Path planning failed",
192  QString::fromStdString(result->error_msg),
193  "");
194 
195  }
196 
198  {
199  if (progress_dialog_)
200  progress_dialog_->reject();
201  }
202 
203 }
204 
205 void PathPlanning::donghongDingFeedbackCb(const ram_path_planning::DonghongDingFeedbackConstPtr &feedback)
206 {
207  if (progress_dialog_ && progress_dialog_->isVisible())
208  Q_EMIT progress_dialog_->drawProgress(feedback->progress_value, QString::fromStdString(feedback->progress_msg));
209 }
210 
211 // Contours
213 {
214  Q_EMIT configChanged();
215  Q_EMIT setEnabled(false);
216 
217  std::string error = contours_ui_->fillGoal(contours_goal_);
218  if (!error.empty())
219  {
220  Q_EMIT displayErrorBoxHandler("Error filling goal", QString::fromStdString(error), "");
221  Q_EMIT setEnabled(true);
222  return;
223  }
224 
225  progress_dialog_ = std::make_shared<ProgressDialog>();
226 
227  contours_ac_->sendGoal(contours_goal_, boost::bind(&PathPlanning::contoursDoneCb, this, _1, _2), NULL,
228  boost::bind(&PathPlanning::contoursFeedbackCb, this, _1));
229 
230  if (!progress_dialog_->exec())
231  {
232  if (contours_ac_->getState().state_ == actionlib::SimpleClientGoalState::ACTIVE)
233  contours_ac_->cancelGoal();
234  }
235 
236  progress_dialog_.reset();
237 
238  Q_EMIT setEnabled(true);
239 }
240 
242  const ram_path_planning::ContoursResultConstPtr &result)
243 {
244  ros::Duration(0.1).sleep(); // Otherwise progress window bugs
245 
247  {
248  if (result->error_msg.empty())
249  {
250  if (progress_dialog_)
251  progress_dialog_->accept();
252  }
253  }
254 
256  {
257  if (progress_dialog_)
258  progress_dialog_->reject();
259  Q_EMIT displayErrorMessageBox("Path planning failed",
260  QString::fromStdString(result->error_msg),
261  "");
262  }
263 
265  {
266  if (progress_dialog_)
267  progress_dialog_->reject();
268  }
269  Q_EMIT setEnabled(true);
270 }
271 
272 void PathPlanning::contoursFeedbackCb(const ram_path_planning::ContoursFeedbackConstPtr &feedback)
273 {
274  if (progress_dialog_ && progress_dialog_->isVisible())
275  Q_EMIT progress_dialog_->drawProgress(feedback->progress_value, QString::fromStdString(feedback->progress_msg));
276 }
277 
278 // Follow poses
280 {
281  Q_EMIT configChanged();
282  Q_EMIT setEnabled(false);
283 
284  std::string error = follow_poses_ui_->fillGoal(follow_poses_goal_);
285  if (!error.empty())
286  {
287  Q_EMIT displayErrorBoxHandler("Error filling goal", QString::fromStdString(error), "");
288  Q_EMIT setEnabled(true);
289  return;
290  }
291 
292  progress_dialog_ = std::make_shared<ProgressDialog>();
293 
294  follow_poses_ac_->sendGoal(follow_poses_goal_, boost::bind(&PathPlanning::FollowPosesDoneCb, this, _1, _2), NULL,
295  boost::bind(&PathPlanning::FollowPosesFeedbackCb, this, _1));
296 
297  if (!progress_dialog_->exec())
298  {
300  follow_poses_ac_->cancelGoal();
301  }
302 
303  progress_dialog_.reset();
304 
305  Q_EMIT setEnabled(true);
306 
307 }
308 
310  const ram_path_planning::FollowPosesResultConstPtr &result)
311 {
312  ros::Duration(0.1).sleep(); // Otherwise progress window bugs
313 
315  {
316  if (result->error_msg.empty())
317  {
318  if (progress_dialog_)
319  progress_dialog_->accept();
320  }
321  }
322 
324  {
325  if (progress_dialog_)
326  progress_dialog_->reject();
327  Q_EMIT displayErrorMessageBox("Path planning failed",
328  QString::fromStdString(result->error_msg),
329  "");
330  }
331 
333  {
334  if (progress_dialog_)
335  progress_dialog_->reject();
336  }
337  Q_EMIT setEnabled(true);
338 }
339 
340 void PathPlanning::FollowPosesFeedbackCb(const ram_path_planning::FollowPosesFeedbackConstPtr &feedback)
341 {
342  if (progress_dialog_ && progress_dialog_->isVisible())
343  Q_EMIT progress_dialog_->drawProgress(feedback->progress_value, QString::fromStdString(feedback->progress_msg));
344 }
345 
346 // Error message
347 void PathPlanning::displayErrorBoxHandler(const QString title,
348  const QString message,
349  const QString info_msg)
350 {
351  const bool old_state(isEnabled());
352  Q_EMIT setEnabled(false);
353  QMessageBox msg_box;
354  msg_box.setWindowTitle(title);
355  msg_box.setText(message);
356  msg_box.setInformativeText(info_msg);
357  msg_box.setIcon(QMessageBox::Critical);
358  msg_box.setStandardButtons(QMessageBox::Ok);
359  msg_box.exec();
360  Q_EMIT setEnabled(old_state);
361 }
362 
363 // RViz function
364 void PathPlanning::load(const rviz::Config& config)
365 {
366  Q_EMIT configChanged();
367 
368  int tmp_int(0);
369  if (config.mapGetInt("algorithm", &tmp_int))
370  loaded_last_algorithm_ = tmp_int;
371 
372  donghong_ding_ui_->load(config);
373  contours_ui_->load(config);
374  follow_poses_ui_->load(config);
375  rviz::Panel::load(config);
376 
377  // Check connection of client
378  QtConcurrent::run(this, &PathPlanning::connectToActions);
379 }
380 
382  {
383  config.mapSetValue("algorithm", select_algorithm_->currentIndex());
384 
385  donghong_ding_ui_->save(config);
386  contours_ui_->save(config);
387  follow_poses_ui_->save(config);
388  rviz::Panel::save(config);
389 }
390 
391 }
392 
#define NULL
void save(rviz::Config config) const
void contoursDoneCb(const actionlib::SimpleClientGoalState &state, const ram_path_planning::ContoursResultConstPtr &result)
void contoursFeedbackCb(const ram_path_planning::ContoursFeedbackConstPtr &feedback)
actionlib::SimpleActionClient< ram_path_planning::ContoursAction > ContoursActionClient
ram_path_planning::FollowPoses< ram_path_planning::FollowPosesAction > follow_poses_generator
void load(const rviz::Config &config)
bool sleep() const
void FollowPosesFeedbackCb(const ram_path_planning::FollowPosesFeedbackConstPtr &feedback)
ContoursWidget * contours_ui_
void displayErrorBoxHandler(const QString title, const QString message, const QString info_msg)
void configChanged()
QPushButton * generate_trajectory_button_
void donghongDingDoneCb(const actionlib::SimpleClientGoalState &state, const ram_path_planning::DonghongDingResultConstPtr &result)
void load(const rviz::Config &config)
Definition: contours.cpp:154
actionlib::SimpleActionClient< ram_path_planning::DonghongDingAction > DonghongDingActionClient
void mapSetValue(const QString &key, QVariant value)
std::shared_ptr< ProgressDialog > progress_dialog_
virtual void setName(const QString &name)
void FollowPosesDoneCb(const actionlib::SimpleClientGoalState &state, const ram_path_planning::FollowPosesResultConstPtr &result)
std::unique_ptr< ContoursActionClient > contours_ac_
void displayErrorMessageBox(const QString, const QString, const QString)
std::string fillGoal(ram_path_planning::ContoursGoal &goal)
Definition: contours.cpp:203
virtual QString getName() const
void save(rviz::Config config) const
Definition: contours.cpp:192
void load(const rviz::Config &config)
std::vector< std::string > algorithm_descriptions_
bool mapGetInt(const QString &key, int *value_out) const
ram_path_planning::DonghongDingGoal donghong_ding_goal_
actionlib::SimpleActionClient< ram_path_planning::FollowPosesAction > FollowPosesActionClient
void save(rviz::Config config) const
ram_path_planning::FollowPosesGoal follow_poses_goal_
std::unique_ptr< DonghongDingActionClient > donghong_ding_ac_
#define ROS_INFO_STREAM(args)
std::unique_ptr< FollowPosesActionClient > follow_poses_ac_
virtual void save(Config config) const
void save(rviz::Config config) const
virtual void load(const Config &config)
std::string fillGoal(ram_path_planning::FollowPosesGoal &goal)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
ram_path_planning::ContoursGoal contours_goal_
void load(const rviz::Config &config)
PathPlanning(QWidget *parent=NULL)
std::string fillGoal(ram_path_planning::DonghongDingGoal &goal)
void donghongDingFeedbackCb(const ram_path_planning::DonghongDingFeedbackConstPtr &feedback)
DonghongDingWidget * donghong_ding_ui_
FollowPosesWidget * follow_poses_ui_
QStackedWidget * algorithm_stacked_widget_


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