Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <moveit/warehouse/planning_scene_storage.h>
00033 #include <moveit/warehouse/constraints_storage.h>
00034 #include <moveit/warehouse/state_storage.h>
00035
00036 #include <moveit/motion_planning_rviz_plugin/motion_planning_frame.h>
00037 #include <moveit/motion_planning_rviz_plugin/motion_planning_display.h>
00038
00039 #include <rviz/display_context.h>
00040 #include <rviz/window_manager_interface.h>
00041
00042 #include <QMessageBox>
00043 #include <QInputDialog>
00044
00045 #include "ui_motion_planning_rviz_plugin_frame.h"
00046
00047 namespace moveit_rviz_plugin
00048 {
00049
00050 void MotionPlanningFrame::databaseConnectButtonClicked()
00051 {
00052 planning_display_->addBackgroundJob(boost::bind(&MotionPlanningFrame::computeDatabaseConnectButtonClicked, this), "connect to database");
00053 }
00054
00055 void MotionPlanningFrame::publishSceneButtonClicked()
00056 {
00057 const planning_scene_monitor::LockedPlanningSceneRO &ps = planning_display_->getPlanningSceneRO();
00058 if (ps)
00059 {
00060 moveit_msgs::PlanningScene msg;
00061 ps->getPlanningSceneMsg(msg);
00062 planning_scene_publisher_.publish(msg);
00063 }
00064 }
00065
00066 void MotionPlanningFrame::planningAlgorithmIndexChanged(int index)
00067 {
00068 if (move_group_)
00069 {
00070 if (index > 0)
00071 move_group_->setPlannerId(ui_->planning_algorithm_combo_box->itemText(index).toStdString());
00072 else
00073 move_group_->setPlannerId("");
00074 }
00075 }
00076
00077 void MotionPlanningFrame::resetDbButtonClicked()
00078 {
00079 if (QMessageBox::warning(this, "Data about to be deleted", "The following dialog will allow you to drop a MoveIt Warehouse database. Are you sure you want to continue?",
00080 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
00081 return;
00082
00083 QStringList dbs;
00084 dbs.append("Planning Scenes");
00085 dbs.append("Constraints");
00086 dbs.append("Robot States");
00087
00088 bool ok = false;
00089 QString response = QInputDialog::getItem(this, tr("Select Database"), tr("Choose the database to reset:"),
00090 dbs, 2, false, &ok);
00091 if (!ok)
00092 return;
00093
00094 if (QMessageBox::critical(this, "Data about to be deleted", QString("All data in database '").append(response).append("'. Are you sure you want to continue?"),
00095 QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
00096 return;
00097
00098 planning_display_->addBackgroundJob(boost::bind(&MotionPlanningFrame::computeResetDbButtonClicked, this, response.toStdString()), "reset database");
00099 }
00100
00101 void MotionPlanningFrame::computeDatabaseConnectButtonClicked()
00102 {
00103 if (planning_scene_storage_)
00104 {
00105 planning_scene_storage_.reset();
00106 robot_state_storage_.reset();
00107 constraints_storage_.reset();
00108 planning_display_->addMainLoopJob(boost::bind(&MotionPlanningFrame::computeDatabaseConnectButtonClickedHelper, this, 1));
00109 }
00110 else
00111 {
00112 planning_display_->addMainLoopJob(boost::bind(&MotionPlanningFrame::computeDatabaseConnectButtonClickedHelper, this, 2));
00113 try
00114 {
00115 planning_scene_storage_.reset(new moveit_warehouse::PlanningSceneStorage(ui_->database_host->text().toStdString(),
00116 ui_->database_port->value(), 5.0));
00117 robot_state_storage_.reset(new moveit_warehouse::RobotStateStorage(ui_->database_host->text().toStdString(),
00118 ui_->database_port->value(), 5.0));
00119 constraints_storage_.reset(new moveit_warehouse::ConstraintsStorage(ui_->database_host->text().toStdString(),
00120 ui_->database_port->value(), 5.0));
00121 }
00122 catch(std::runtime_error &ex)
00123 {
00124 planning_display_->addMainLoopJob(boost::bind(&MotionPlanningFrame::computeDatabaseConnectButtonClickedHelper, this, 3));
00125 ROS_ERROR("%s", ex.what());
00126 return;
00127 }
00128 planning_display_->addMainLoopJob(boost::bind(&MotionPlanningFrame::computeDatabaseConnectButtonClickedHelper, this, 4));
00129 }
00130 }
00131
00132 void MotionPlanningFrame::computeDatabaseConnectButtonClickedHelper(int mode)
00133 {
00134 if (mode == 1)
00135 {
00136 ui_->planning_scene_tree->setUpdatesEnabled(false);
00137 ui_->planning_scene_tree->clear();
00138 ui_->planning_scene_tree->setUpdatesEnabled(true);
00139
00140 ui_->database_connect_button->setUpdatesEnabled(false);
00141 ui_->database_connect_button->setText(QString::fromStdString("Connect"));
00142 ui_->database_connect_button->setStyleSheet("QPushButton { color : green }");
00143 ui_->database_connect_button->setUpdatesEnabled(true);
00144 ui_->reset_db_button->hide();
00145
00146 ui_->load_scene_button->setEnabled(false);
00147 ui_->load_query_button->setEnabled(false);
00148 ui_->save_query_button->setEnabled(false);
00149 ui_->save_scene_button->setEnabled(false);
00150 ui_->delete_query_button->setEnabled(false);
00151 ui_->delete_scene_button->setEnabled(false);
00152 populateConstraintsList(std::vector<std::string>());
00153 }
00154 else
00155 if (mode == 2)
00156 {
00157 ui_->database_connect_button->setUpdatesEnabled(false);
00158 ui_->database_connect_button->setText(QString::fromStdString("Connecting ..."));
00159 ui_->database_connect_button->setUpdatesEnabled(true);
00160 populateConstraintsList(std::vector<std::string>());
00161 }
00162 else
00163 if (mode == 3)
00164 {
00165 ui_->database_connect_button->setUpdatesEnabled(false);
00166 ui_->database_connect_button->setText(QString::fromStdString("Connect"));
00167 ui_->database_connect_button->setStyleSheet("QPushButton { color : green }");
00168 ui_->database_connect_button->setUpdatesEnabled(true);
00169 ui_->reset_db_button->hide();
00170 }
00171 else
00172 if (mode == 4)
00173 {
00174 ui_->database_connect_button->setUpdatesEnabled(false);
00175 ui_->database_connect_button->setText(QString::fromStdString("Disconnect"));
00176 ui_->database_connect_button->setStyleSheet("QPushButton { color : darkBlue }");
00177 ui_->database_connect_button->setUpdatesEnabled(true);
00178 ui_->save_scene_button->setEnabled(true);
00179 ui_->reset_db_button->show();
00180 populatePlanningSceneTreeView();
00181 if (move_group_)
00182 {
00183 move_group_->setConstraintsDatabase(ui_->database_host->text().toStdString(), ui_->database_port->value());
00184 planning_display_->addBackgroundJob(boost::bind(&MotionPlanningFrame::populateConstraintsList, this), "populateConstraintsList");
00185 }
00186 }
00187 }
00188
00189 void MotionPlanningFrame::computeResetDbButtonClicked(const std::string &db)
00190 {
00191 if (db == "Constraints" && constraints_storage_)
00192 constraints_storage_->reset();
00193 else
00194 if (db == "Robot States" && robot_state_storage_)
00195 robot_state_storage_->reset();
00196 else
00197 if (db == "Planning Scenes")
00198 planning_scene_storage_->reset();
00199 }
00200 }