Go to the documentation of this file.00001
00026 #include <constrained_ik/moveit_interface/constrained_ik_planner_plugin.h>
00027 #include <class_loader/class_loader.h>
00028
00029 const std::string JOINT_INTERP_PLANNER = "JointInterpolation";
00030 const std::string CARTESIAN_PLANNER = "Cartesian";
00032 namespace constrained_ik
00033 {
00034 bool CLIKPlannerManager::initialize(const robot_model::RobotModelConstPtr &model, const std::string &ns)
00035 {
00036 if (!ns.empty())
00037 nh_ = ros::NodeHandle(ns);
00038
00039 for (auto & group_name : model->getJointModelGroupNames())
00040 {
00041
00042 if (model->getJointModelGroup(group_name)->isChain())
00043 {
00044 planners_.insert(std::make_pair(std::make_pair(CARTESIAN_PLANNER, group_name), CLIKPlanningContextPtr(new CartesianPlanner(CARTESIAN_PLANNER, group_name))));
00045
00046 CartesianDynReconfigServerPtr drs(new CartesianDynReconfigServer(mutex_, ros::NodeHandle(nh_, "constrained_ik_solver/" + group_name)));
00047 drs->setCallback(boost::bind(&CLIKPlannerManager::cartesianDynamicReconfigureCallback, this, _1, _2, group_name));
00048 cartesian_dynamic_reconfigure_server_.insert(std::make_pair(group_name, drs));
00049
00050
00051 planners_.insert(std::make_pair(std::make_pair(JOINT_INTERP_PLANNER, group_name), CLIKPlanningContextPtr(new JointInterpolationPlanner(JOINT_INTERP_PLANNER, group_name))));
00052 }
00053 }
00054
00055 dynamic_reconfigure_server_.reset(new ManagerDynReconfigServer(mutex_, ros::NodeHandle(nh_, "constrained_ik_planner")));
00056 dynamic_reconfigure_server_->setCallback(boost::bind(&CLIKPlannerManager::managerDynamicReconfigureCallback, this, _1, _2));
00057
00058 return true;
00059 }
00060
00061 void CLIKPlannerManager::getPlanningAlgorithms(std::vector<std::string> &algs) const
00062 {
00063 algs.clear();
00064 algs.push_back(JOINT_INTERP_PLANNER);
00065 algs.push_back(CARTESIAN_PLANNER);
00066 }
00067
00068 void CLIKPlannerManager::setPlannerConfigurations(const planning_interface::PlannerConfigurationMap &pcs)
00069 {
00070 std::cout << "Entered setPlannerConfigurations" << std::endl;
00071 }
00072
00073 planning_interface::PlanningContextPtr CLIKPlannerManager::getPlanningContext(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, moveit_msgs::MoveItErrorCodes &error_code) const
00074 {
00075 constrained_ik::CLIKPlanningContextPtr planner;
00076
00077 if (req.group_name.empty())
00078 {
00079 logError("No group specified to plan for");
00080 error_code.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME;
00081 return planning_interface::PlanningContextPtr();
00082 }
00083
00084 error_code.val = moveit_msgs::MoveItErrorCodes::FAILURE;
00085
00086 if (!planning_scene)
00087 {
00088 logError("No planning scene supplied as input");
00089 return planning_interface::PlanningContextPtr();
00090 }
00091
00092
00093 std::map<std::pair<std::string, std::string>, constrained_ik::CLIKPlanningContextPtr>::const_iterator it;
00094 if (req.planner_id.empty())
00095 it = planners_.find(std::make_pair(JOINT_INTERP_PLANNER, req.group_name));
00096 else
00097 it = planners_.find(std::make_pair(req.planner_id, req.group_name));
00098
00099 if (it == planners_.end())
00100 {
00101 logError("No planner for specified group");
00102 error_code.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME;
00103 return planning_interface::PlanningContextPtr();
00104 }
00105 planner = it->second;
00106
00107
00108 planner->clear();
00109 planner->setPlanningScene(planning_scene);
00110 planner->setMotionPlanRequest(req);
00111
00112
00113 return planner;
00114 }
00115
00116 void CLIKPlannerManager::managerDynamicReconfigureCallback(CLIKPlannerDynamicConfig &config, uint32_t level)
00117 {
00118 typedef std::map<std::pair<std::string, std::string>, constrained_ik::CLIKPlanningContextPtr>::const_iterator it_type;
00119
00120 config_ = config;
00121 for (it_type it = planners_.begin(); it != planners_.end(); it++)
00122 {
00123 it->second->setPlannerConfiguration(config_);
00124 }
00125
00126 }
00127
00128 void CLIKPlannerManager::cartesianDynamicReconfigureCallback(CLIKDynamicConfig &config, uint32_t level, std::string group_name)
00129 {
00130
00131 validateConstrainedIKConfiguration<CLIKDynamicConfig>(config);
00132
00133 typedef std::map<std::pair<std::string, std::string>, constrained_ik::CLIKPlanningContextPtr>::const_iterator it_type;
00134 it_type it = planners_.find(std::make_pair(CARTESIAN_PLANNER, group_name));
00135 if (it != planners_.end())
00136 {
00137 ConstrainedIKConfiguration new_config = convertToConstrainedIKConfiguration(config);
00138 boost::shared_ptr<CartesianPlanner> planner = boost::static_pointer_cast<CartesianPlanner>(it->second);
00139 planner->setSolverConfiguration(new_config);
00140 }
00141 }
00142
00143 }
00144 CLASS_LOADER_REGISTER_CLASS(constrained_ik::CLIKPlannerManager, planning_interface::PlannerManager)