39 #include <pluginlib/class_loader.hpp>
42 #include <boost/graph/adjacency_list.hpp>
43 #include <boost/graph/depth_first_search.hpp>
56 template <
class Edge,
class Graph>
69 config_data_->registerType(
"group_meta",
"moveit_setup::srdf_setup::GroupMetaConfig");
76 rename(old_group_name, new_group_name);
85 for (std::string& subgroup :
group.subgroups_)
88 if (subgroup == old_group_name)
90 subgroup.assign(new_group_name);
97 for (srdf::Model::EndEffector& eef :
srdf_config_->getEndEffectors())
100 if (eef.parent_group_ == old_group_name)
102 RCLCPP_DEBUG_STREAM(*
logger_,
"Changed eef '" << eef.name_ <<
"' to new parent group name " << new_group_name);
103 eef.parent_group_ = new_group_name;
108 if (eef.component_group_.compare(old_group_name) == 0)
110 RCLCPP_DEBUG_STREAM(*
logger_,
"Changed eef '" << eef.name_ <<
"' to new group name " << new_group_name);
111 eef.component_group_ = new_group_name;
117 for (srdf::Model::GroupState& gs :
srdf_config_->getGroupStates())
120 if (gs.group_ == old_group_name)
122 RCLCPP_DEBUG_STREAM(*
logger_,
"Changed group state group '" << gs.group_ <<
"' to new parent group name "
124 gs.group_ = new_group_name;
148 auto it = eefs.begin();
149 while (it != eefs.end())
151 if (it->component_group_ == group_name)
168 auto& subgroups =
group.subgroups_;
169 std::vector<std::string>::iterator subgroup_it = std::find(subgroups.begin(), subgroups.end(), group_name);
170 while (subgroup_it != subgroups.end())
172 subgroups.erase(subgroup_it);
174 subgroup_it = std::find(subgroups.begin(), subgroups.end(), group_name);
186 srdf::Model::Group* searched_group =
find(group_name);
189 searched_group->joints_ = joint_names;
198 srdf::Model::Group* searched_group =
find(group_name);
201 searched_group->links_ = link_names;
210 if ((!tip.empty() && base.empty()) || (tip.empty() && !base.empty()))
212 throw std::runtime_error(
"You must specify a link for both the base and tip, or leave both "
217 if (!tip.empty() && !base.empty())
220 if (tip.compare(base) == 0)
222 throw std::runtime_error(
"Tip and base link cannot be the same link.");
225 bool found_tip =
false;
226 bool found_base =
false;
229 for (
const std::string& link : links)
232 if (link.compare(tip) == 0)
234 else if (link.compare(base) == 0)
238 if (found_tip && found_base)
243 if (!found_tip || !found_base)
245 throw std::runtime_error(
"Tip or base link(s) were not found in kinematic chain.");
250 srdf::Model::Group* searched_group =
find(group_name);
253 searched_group->chains_.clear();
256 if (!tip.empty() && !base.empty())
258 searched_group->chains_.push_back(std::pair<std::string, std::string>(base, tip));
270 std::map<std::string, int> group_nodes;
277 group_nodes.insert(std::pair<std::string, int>(group_name, node_id));
282 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS> Graph;
283 Graph g(group_nodes.size());
290 if (
group.name_ == selected_group_name)
293 for (
const std::string& to_string : subgroups)
296 int to_id = group_nodes[to_string];
299 add_edge(from_id, to_id, g);
305 for (
const std::string& to_string :
group.subgroups_)
309 int to_id = group_nodes[to_string];
312 add_edge(from_id, to_id, g);
320 bool has_cycle =
false;
322 boost::depth_first_search(g, visitor(vis));
326 throw std::runtime_error(
"Depth first search reveals a cycle in the subgroups");
330 srdf::Model::Group* searched_group =
find(selected_group_name);
333 searched_group->subgroups_ = subgroups;
362 std::vector<std::string> pose_names;
363 for (
const srdf::Model::GroupState& pose :
srdf_config_->getGroupStates())
365 if (pose.group_ == group_name)
367 pose_names.push_back(pose.name_);
375 std::vector<std::string> eef_names;
376 for (
const srdf::Model::EndEffector& eef :
srdf_config_->getEndEffectors())
378 if (eef.component_group_ == group_name)
380 eef_names.push_back(eef.name_);
389 std::unique_ptr<pluginlib::ClassLoader<kinematics::KinematicsBase>> loader;
392 loader = std::make_unique<pluginlib::ClassLoader<kinematics::KinematicsBase>>(
"moveit_core",
393 "kinematics::KinematicsBase");
395 catch (pluginlib::PluginlibException& ex)
397 throw std::runtime_error(std::string(
"Exception while creating class loader for kinematic "
398 "solver plugins: ") +
402 std::vector<std::string> planners(loader->getDeclaredClasses());
405 if (planners.empty())
407 throw std::runtime_error(
"No MoveIt-compatible kinematics solvers found. Try "
408 "installing moveit_kinematics (sudo apt-get install "
409 "ros-${ROS_DISTRO}-moveit-kinematics)");
416 std::vector<std::string> planner_names;
419 planner_names.push_back(
"AnytimePathShortening");
420 planner_names.push_back(
"SBL");
421 planner_names.push_back(
"EST");
422 planner_names.push_back(
"LBKPIECE");
423 planner_names.push_back(
"BKPIECE");
424 planner_names.push_back(
"KPIECE");
425 planner_names.push_back(
"RRT");
426 planner_names.push_back(
"RRTConnect");
427 planner_names.push_back(
"RRTstar");
428 planner_names.push_back(
"TRRT");
429 planner_names.push_back(
"PRM");
430 planner_names.push_back(
"PRMstar");
431 planner_names.push_back(
"FMT");
432 planner_names.push_back(
"BFMT");
433 planner_names.push_back(
"PDST");
434 planner_names.push_back(
"STRIDE");
435 planner_names.push_back(
"BiTRRT");
436 planner_names.push_back(
"LBTRRT");
437 planner_names.push_back(
"BiEST");
438 planner_names.push_back(
"ProjEST");
439 planner_names.push_back(
"LazyPRM");
440 planner_names.push_back(
"LazyPRMstar");
441 planner_names.push_back(
"SPARS");
442 planner_names.push_back(
"SPARStwo");
444 return planner_names;
A joint from the robot. Models the transform that this joint applies in the kinematic chain....
const LinkModel * getChildLinkModel() const
Get the link that this joint connects to. There will always be such a link.
std::string getTypeName() const
Get the type of joint as a string.
DataWarehousePtr config_data_
std::shared_ptr< rclcpp::Logger > logger_
void setChain(const std::string &group_name, const std::string &base, const std::string &tip)
Set the specified group's kinematic chain.
void onInit() override
Overridable initialization method.
const std::vector< std::string > & getLinkNames() const
void setLinks(const std::string &group_name, const std::vector< std::string > &link_names)
Set the specified group's link names.
void setSubgroups(const std::string &selected_group_name, const std::vector< std::string > &subgroups)
Set the specified group's subgroups.
void renameGroup(const std::string &old_group_name, const std::string &new_group_name)
std::string getChildOfJoint(const std::string &joint_name) const
void deleteGroup(const std::string &group_name)
std::vector< std::string > getPosesByGroup(const std::string &group_name) const
std::string getJointType(const std::string &joint_name) const
std::shared_ptr< GroupMetaConfig > group_meta_config_
std::vector< std::string > getGroupNames() const
std::vector< std::string > getKinematicPlanners() const
std::vector< std::string > getOMPLPlanners() const
std::vector< std::string > getEndEffectorsByGroup(const std::string &group_name) const
void setJoints(const std::string &group_name, const std::vector< std::string > &joint_names)
Set the specified group's joint names.
LinkNameTree getLinkNameTree() const
void onInit() override
Overridable initialization method.
std::shared_ptr< SRDFConfig > srdf_config_
srdf::Model::Group * find(const std::string &name)
Return a pointer to an item with the given name if it exists, otherwise null.
bool remove(const std::string &name)
Delete an item with the given name from the list.
srdf::Model::Group * rename(const std::string &old_name, const std::string &new_name)
Renames an item and returns a pointer to the item.
LinkNameTree buildLinkNameTree(const moveit::core::LinkModel *link)
CycleDetector(bool &has_cycle)
void backEdge(Edge, Graph &)