40 #include <QVBoxLayout> 41 #include <QHBoxLayout> 42 #include <QMessageBox> 44 #include <QApplication> 46 #include <QFileDialog> 57 #include <boost/algorithm/string.hpp> 58 #include <boost/filesystem.hpp> 59 #include <boost/algorithm/string.hpp> 66 namespace fs = boost::filesystem;
75 QVBoxLayout* layout =
new QVBoxLayout(
this);
78 QHBoxLayout* hlayout =
new QHBoxLayout();
80 QVBoxLayout* left_layout =
new QVBoxLayout();
82 QVBoxLayout* right_layout =
new QVBoxLayout();
87 std::string image_path =
"./resources/MoveIt_Setup_Assistant2.png";
88 if (chdir(
config_data_->setup_assistant_path_.c_str()) != 0)
90 ROS_ERROR(
"FAILED TO CHANGE PACKAGE TO moveit_setup_assistant");
108 new HeaderWidget(
"MoveIt! Setup Assistant",
"These tools will assist you in creating a Semantic Robot " 109 "Description Format (SRDF) file, various yaml configuration and many " 110 "roslaunch files for utilizing all aspects of MoveIt! functionality.",
112 layout->addWidget(header);
125 "Specify the package name or path of an existing MoveIt! configuration package to be " 126 "edited for your robot. Example package name: <i>panda_moveit_config</i>",
127 "optional xacro arguments:",
this,
true);
136 "Specify the location of an existing Universal Robot Description Format or " 137 "COLLADA file for your robot",
138 "optional xacro arguments:",
this,
false,
true);
146 QHBoxLayout* load_files_layout =
new QHBoxLayout();
154 btn_load_ =
new QPushButton(
"&Load Files",
this);
159 load_files_layout->setAlignment(
btn_load_, Qt::AlignRight);
164 QFont next_label_font(QFont().defaultFamily(), 11, QFont::Bold);
166 next_label_->setText(
"Success! Use the left navigation pane to continue.");
171 layout->setAlignment(Qt::AlignTop);
172 hlayout->setAlignment(Qt::AlignTop);
173 left_layout->setAlignment(Qt::AlignTop);
174 right_layout->setAlignment(Qt::AlignTop);
177 left_layout->setSpacing(10);
180 hlayout->addLayout(left_layout);
181 hlayout->addLayout(right_layout);
182 layout->addLayout(hlayout);
185 QWidget* vspacer =
new QWidget(
this);
186 vspacer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
187 layout->addWidget(vspacer);
192 layout->addLayout(load_files_layout);
194 this->setLayout(layout);
201 QTimer* update_timer =
new QTimer(
this);
202 update_timer->setSingleShot(
true);
203 connect(update_timer, SIGNAL(timeout()),
btn_load_, SLOT(click()));
204 update_timer->start(100);
313 if (package_path_input.empty())
316 QMessageBox::warning(
this,
"Error Loading Files",
"Please specify a configuration package path to load.");
324 QMessageBox::critical(
this,
"Error Loading Files",
"The specified path is not a directory or is not accessable");
328 std::string setup_assistant_path;
331 if (!
config_data_->getSetupAssistantYAMLPath(setup_assistant_path))
334 QMessageBox::warning(
335 this,
"Incorrect Directory/Package",
336 QString(
"The chosen package location exists but was not created using MoveIt! Setup Assistant. " 337 "If this is a mistake, provide the missing file: ")
338 .
append(setup_assistant_path.c_str()));
343 if (!
config_data_->inputSetupAssistantYAML(setup_assistant_path))
346 QMessageBox::warning(
this,
"Setup Assistant File Error",
347 QString(
"Unable to correctly parse the setup assistant configuration file: ")
348 .
append(setup_assistant_path.c_str()));
361 QApplication::processEvents();
368 QApplication::processEvents();
387 QApplication::processEvents();
395 QApplication::processEvents();
401 fs::path kinematics_yaml_path =
config_data_->config_pkg_path_;
402 kinematics_yaml_path /=
"config/kinematics.yaml";
404 if (!
config_data_->inputKinematicsYAML(kinematics_yaml_path.make_preferred().native().c_str()))
406 QMessageBox::warning(
this,
"No Kinematic YAML File",
407 QString(
"Failed to parse kinematics yaml file. This file is not critical but any previous " 408 "kinematic solver settings have been lost. To re-populate this file edit each " 409 "existing planning group and choose a solver, then save each change. \n\nFile error " 411 .
append(kinematics_yaml_path.make_preferred().native().c_str()));
418 fs::path ros_controllers_yaml_path =
config_data_->config_pkg_path_;
419 ros_controllers_yaml_path /=
"config/ros_controllers.yaml";
420 config_data_->inputROSControllersYAML(ros_controllers_yaml_path.make_preferred().native().c_str());
422 fs::path ompl_yaml_path =
config_data_->config_pkg_path_;
423 ompl_yaml_path /=
"config/ompl_planning.yaml";
424 config_data_->inputOMPLYAML(ompl_yaml_path.make_preferred().native().c_str());
433 QApplication::processEvents();
440 QApplication::processEvents();
444 ROS_INFO(
"Loading Setup Assistant Complete");
459 QMessageBox::warning(
this,
"Error Loading Files",
"No robot model file specefied");
466 QMessageBox::warning(
this,
"Error Loading Files",
467 QString(
"Unable to locate the URDF file: ").
append(
config_data_->urdf_path_.c_str()));
479 QApplication::processEvents();
490 QApplication::processEvents();
493 const std::string blank_srdf =
"<?xml version='1.0'?><robot name='" +
config_data_->urdf_model_->getName() +
"'></" 499 QMessageBox::warning(
this,
"Error Loading Files",
"Failure loading blank SRDF file.");
505 QApplication::processEvents();
514 QApplication::processEvents();
521 QApplication::processEvents();
525 ROS_INFO(
"Loading Setup Assistant Complete");
534 const std::vector<std::string> xacro_args_ = { xacro_args };
538 QMessageBox::warning(
this,
"Error Loading Files",
539 QString(
"URDF/COLLADA file not found: ").
append(urdf_file_path.c_str()));
545 QMessageBox::warning(
this,
"Error Loading Files",
"Running xacro failed.\nPlease check console for errors.");
552 QMessageBox::warning(
this,
"Error Loading Files",
"URDF/COLLADA file is not a valid robot model.");
562 while (!nh.ok() && steps < 4)
564 ROS_WARN(
"Waiting for node handle");
570 ROS_INFO(
"Setting Param Server with Robot Description");
572 nh.setParam(
"/robot_description",
config_data_->urdf_string_);
582 const std::vector<std::string> xacro_args;
584 std::string srdf_string;
587 QMessageBox::warning(
this,
"Error Loading Files", QString(
"SRDF file not found: ").
append(srdf_file_path.c_str()));
603 QMessageBox::warning(
this,
"Error Loading Files",
"SRDF file not a valid semantic robot description model.");
611 while (!nh.
ok() && steps < 4)
613 ROS_WARN(
"Waiting for node handle");
619 ROS_INFO(
"Setting Param Server with Robot Semantic Description");
620 nh.
setParam(
"/robot_description_semantic", srdf_string);
635 fs::path urdf_directory = urdf_path;
636 urdf_directory.remove_filename();
639 fs::path relative_path;
640 std::string package_name;
643 fs::path package_path;
645 std::vector<std::string> path_parts;
648 for (fs::path::iterator it = urdf_directory.begin(); it != urdf_directory.end(); ++it)
649 path_parts.push_back(it->native());
651 bool packageFound =
false;
654 for (
int segment_length = path_parts.size(); segment_length > 0; --segment_length)
660 for (
int segment_count = 0; segment_count < segment_length; ++segment_count)
662 sub_path /= path_parts[segment_count];
665 if (segment_count == segment_length - 1)
667 package_name = path_parts[segment_count];
672 package_path = sub_path;
673 package_path /=
"package.xml";
674 ROS_DEBUG_STREAM(
"Checking for " << package_path.make_preferred().native());
677 if (fs::is_regular_file(package_path) || fs::is_regular_file(sub_path /
"manifest.xml"))
680 for (std::size_t relative_count = segment_length; relative_count < path_parts.size(); ++relative_count)
681 relative_path /= path_parts[relative_count];
684 relative_path /= urdf_path.filename();
705 if (robot_desc_pkg_path.empty())
707 QMessageBox::warning(
this,
"Package Not Found In ROS Workspace",
708 QString(
"ROS was unable to find the package name '")
710 .
append(
"' within the ROS workspace. This may cause issues later."));
715 config_data_->urdf_pkg_relative_path_ = relative_path.make_preferred().native();
733 QMessageBox::warning(
this,
"Error Loading Files", QString(
"ROS was unable to find the package name '")
735 .
append(
"'. Verify this package is inside your ROS " 736 "workspace and is a proper ROS package."));
740 QMessageBox::warning(
this,
"Error Loading Files",
741 QString(
"Unable to locate the URDF file in package. Expected File: \n")
750 ROS_WARN(
"The URDF path is absolute to the filesystem and not relative to a ROS package/stack");
763 QMessageBox::warning(
this,
"Error Loading Files",
764 QString(
"Unable to locate the SRDF file: ").
append(
config_data_->srdf_path_.c_str()));
777 fs::path sensors_3d_yaml_path =
config_data_->config_pkg_path_;
778 sensors_3d_yaml_path /=
"config/sensors_3d.yaml";
781 fs::path default_sensors_3d_yaml_path =
"templates/moveit_config_pkg_template/config/sensors_3d.yaml";
783 if (!fs::is_regular_file(sensors_3d_yaml_path))
785 return config_data_->input3DSensorsYAML(default_sensors_3d_yaml_path.make_preferred().native().c_str());
789 return config_data_->input3DSensorsYAML(default_sensors_3d_yaml_path.make_preferred().native().c_str(),
790 sensors_3d_yaml_path.make_preferred().native().c_str());
806 setFrameShape(QFrame::StyledPanel);
807 setFrameShadow(QFrame::Raised);
812 QVBoxLayout* layout =
new QVBoxLayout(
this);
815 QHBoxLayout* hlayout =
new QHBoxLayout();
818 QLabel* widget_title =
new QLabel(
this);
819 widget_title->setText(
"Create new or edit existing?");
820 QFont widget_title_font(QFont().defaultFamily(), 12, QFont::Bold);
821 widget_title->setFont(widget_title_font);
822 layout->addWidget(widget_title);
823 layout->setAlignment(widget_title, Qt::AlignTop);
828 "All settings for MoveIt! are stored in the MoveIt! configuration package. Here you have " 829 "the option to create a new configuration package or load an existing one. Note: " 830 "changes to a MoveIt! configuration package outside this Setup Assistant are likely to be " 831 "overwritten by this tool.");
835 p.setColor(QPalette::Active, QPalette::Base, this->palette().color(QWidget::backgroundRole()));
836 p.setColor(QPalette::Inactive, QPalette::Base, this->palette().color(QWidget::backgroundRole()));
850 btn_new_->setText(
"Create &New MoveIt\nConfiguration Package");
855 btn_exist_->setText(
"&Edit Existing MoveIt\nConfiguration Package");
860 layout->addLayout(hlayout);
static bool isXacroFile(const std::string &path)
#define ROS_DEBUG_STREAM(args)
ROSLIB_DECL std::string getPath(const std::string &package_name)
#define ROS_INFO_STREAM(args)
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
static bool loadXmlFileToString(std::string &buffer, const std::string &path, const std::vector< std::string > &xacro_args)
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL void spinOnce()
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const