38 #include <moveit_msgs/JointLimits.h> 40 #include <QFormLayout> 41 #include <QMessageBox> 42 #include <QDoubleValidator> 43 #include <QTreeWidgetItem> 44 #include <QApplication> 58 QVBoxLayout* layout =
new QVBoxLayout();
60 layout->setAlignment(Qt::AlignTop);
63 this->setWindowTitle(
"ROS Control Controllers");
67 "Setup ROS Controllers",
"Configure MoveIt! to work with ROS Control to control the robot's physical hardware",
69 layout->addWidget(header);
107 QWidget* stacked_layout_widget =
new QWidget(
this);
110 layout->addWidget(stacked_layout_widget);
112 this->setLayout(layout);
121 QWidget* content_widget =
new QWidget(
this);
124 QVBoxLayout* layout =
new QVBoxLayout(
this);
126 QHBoxLayout* upper_controls_layout =
new QHBoxLayout();
129 QPushButton* btn_add_default =
130 new QPushButton(
"Auto Add &FollowJointsTrajectory \n Controllers For Each Planning Group",
this);
131 btn_add_default->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
132 btn_add_default->setMaximumWidth(600);
134 upper_controls_layout->addWidget(btn_add_default);
135 upper_controls_layout->setAlignment(btn_add_default, Qt::AlignLeft);
138 layout->addLayout(upper_controls_layout);
144 labels <<
"Controller" 145 <<
"Controller Type";
159 QLabel* expand_controls =
new QLabel(
this);
160 expand_controls->setText(
"<a href='expand'>Expand All</a> <a href='contract'>Collapse All</a>");
161 connect(expand_controls, SIGNAL(linkActivated(
const QString)),
this, SLOT(
alterTree(
const QString)));
165 QWidget* spacer =
new QWidget(
this);
166 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
170 btn_delete_ =
new QPushButton(
"&Delete Controller",
this);
171 btn_delete_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
178 btn_add_ =
new QPushButton(
"&Add Controller",
this);
185 btn_edit_ =
new QPushButton(
"&Edit Selected",
this);
195 content_widget->setLayout(layout);
197 return content_widget;
211 for (std::vector<moveit_setup_assistant::ROSControlConfig>::iterator controller_it =
213 controller_it !=
config_data_->getROSControllers().end(); ++controller_it)
231 const QFont top_level_font(QFont().defaultFamily(), 11, QFont::Bold);
232 const QFont type_font(QFont().defaultFamily(), 11, QFont::Normal, QFont::StyleItalic);
234 QTreeWidgetItem* controller;
236 controller =
new QTreeWidgetItem();
239 controller->setText(0, controller_it.
name_.c_str());
240 controller->setFont(0, top_level_font);
241 controller->setData(0, Qt::UserRole, QVariant::fromValue(0));
244 controller->setText(1, controller_it.
type_.c_str());
245 controller->setFont(1, type_font);
246 controller->setData(1, Qt::UserRole, QVariant::fromValue(4));
249 if (!controller_it.
joints_.empty())
252 QTreeWidgetItem* joints =
new QTreeWidgetItem(controller);
253 joints->setText(0,
"Joints");
254 joints->setFont(0, type_font);
255 joints->setData(0, Qt::UserRole, QVariant::fromValue(1));
256 controller->addChild(joints);
259 for (std::vector<std::string>::const_iterator joint_it = controller_it.
joints_.begin();
260 joint_it != controller_it.
joints_.end(); ++joint_it)
262 QTreeWidgetItem* joint_item =
new QTreeWidgetItem(joints);
263 joint_item->setData(0, Qt::UserRole, QVariant::fromValue(2));
266 joint_item->setText(0, (*joint_it).c_str());
267 joints->addChild(joint_item);
289 const robot_model::RobotModelConstPtr& model =
config_data_->getRobotModel();
292 const std::vector<std::string>& joints = model->getJointModelNames();
294 if (joints.size() == 0)
296 QMessageBox::critical(
this,
"Error Loading",
"No joints found for robot model");
308 QString(
"Edit '").
append(QString::fromUtf8(this_controller->
name_.c_str())).append(
"' Joint Collection"));
320 std::vector<std::string>
groups;
323 for (std::vector<srdf::Model::Group>::const_iterator group_it =
config_data_->srdf_->srdf_model_->getGroups().begin();
324 group_it !=
config_data_->srdf_->srdf_model_->getGroups().end(); ++group_it)
327 groups.push_back(group_it->name_);
338 QString(
"Edit '").
append(QString::fromUtf8(this_controller->
name_.c_str())).append(
"' Joints groups collection"));
351 if (controller_name.empty())
359 int type_ = item->data(0, Qt::UserRole).value<
int>();
361 controller_name = item->text(0).toUtf8().constData();
365 if (QMessageBox::question(
366 this,
"Confirm Controller Deletion",
367 QString(
"Are you sure you want to delete the controller '").
append(controller_name.c_str()).
append(
" ?"),
368 QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
410 QMessageBox::warning(
this,
"Error adding contollers",
"No Planning Groups configured!");
422 if (this_controller ==
NULL)
452 if (editing && editing->
joints_.empty())
478 for (std::size_t i = 0; i < joints.size(); ++i)
480 const robot_model::JointModel* joint_model =
config_data_->getRobotModel()->getJointModel(joints[i]);
489 const std::string link = joint_model->getChildLinkModel()->getName();
509 for (std::size_t i = 0; i < groups.size(); ++i)
522 int type = selected_item->data(0, Qt::UserRole).value<
int>();
584 searched_controller->
joints_.clear();
609 searched_controller->
joints_.clear();
615 const robot_model::JointModelGroup* joint_model_group =
config_data_->getRobotModel()->getJointModelGroup(
617 const std::vector<const robot_model::JointModel*>& joint_models = joint_model_group->getActiveJointModels();
620 for (
const robot_model::JointModel* joint : joint_models)
622 if (joint->isPassive() || joint->getMimic() !=
NULL || joint->getType() == robot_model::JointModel::FIXED)
624 searched_controller->
joints_.push_back(joint->getName());
660 std::smatch invalid_name_match;
661 std::regex invalid_reg_ex(
"[^a-z|^1-9|^_]");
664 if (controller_name.empty() || std::regex_search(controller_name, invalid_name_match, invalid_reg_ex))
666 QMessageBox::warning(
this,
"Error Saving",
"Invalid ROS controller name");
678 for (std::vector<moveit_setup_assistant::ROSControlConfig>::const_iterator controller_it =
680 controller_it !=
config_data_->getROSControllers().end(); ++controller_it)
682 if (controller_it->name_.compare(controller_name) == 0)
685 if (&(*controller_it) != searched_controller)
687 QMessageBox::warning(
this,
"Error Saving",
"A controller already exists with that name!");
696 if (searched_controller ==
NULL)
699 new_controller.
name_ = controller_name;
700 new_controller.
type_ = controller_type;
708 const std::string old_controller_name = searched_controller->
name_;
711 searched_controller->
name_ = controller_name;
712 searched_controller->
type_ = controller_type;
730 QTreeWidgetItem* controller_item;
739 int type = item->data(0, Qt::UserRole).value<
int>();
744 controller_item = item->parent()->parent();
757 controller_item = item->parent();
781 QMessageBox::critical(
this,
"Error Loading",
"An internal error has occured while loading.");
831 if (link.contains(
"expand"))
840 if (selected_items.size() == 0)
#define ROS_INFO_STREAM_NAMED(name, args)
std::vector< std::string > joints_
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
#define ROS_WARN_STREAM_NAMED(name, args)