kinematics_base.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Sachin Chitta, Dave Coleman */
36 
37 #ifndef MOVEIT_KINEMATICS_BASE_KINEMATICS_BASE_
38 #define MOVEIT_KINEMATICS_BASE_KINEMATICS_BASE_
39 
40 #include <geometry_msgs/PoseStamped.h>
41 #include <moveit_msgs/MoveItErrorCodes.h>
43 #include <ros/node_handle.h>
44 
45 #include <boost/function.hpp>
46 #include <string>
47 
48 namespace moveit
49 {
50 namespace core
51 {
55 }
56 }
57 
59 namespace kinematics
60 {
61 /*
62  * @enum DiscretizationMethods
63  *
64  * @brief Flags for choosing the type discretization method applied on the redundant joints during an ik query
65  */
66 namespace DiscretizationMethods
67 {
69 {
78 };
79 }
81 
82 /*
83  * @enum KinematicErrors
84  * @brief Kinematic error codes that occur in a ik query
85  */
86 namespace KinematicErrors
87 {
89 {
90  OK = 1,
100 };
101 }
103 
109 {
111  : lock_redundant_joints(false)
112  , return_approximate_solution(false)
113  , discretization_method(DiscretizationMethods::NO_DISCRETIZATION)
114  {
115  }
116 
119  DiscretizationMethod discretization_method;
121 };
122 
123 /*
124  * @struct KinematicsResult
125  * @brief Reports result details of an ik query
126  *
127  * This struct is used as an output argument of the getPositionIK(...) method that returns multiple joint solutions.
128  * It contains the type of error that led to a failure or KinematicErrors::OK when a set of joint solutions is found.
129  * The solution percentage shall provide a ratio of solutions found over solutions searched.
130  *
131  */
133 {
134  KinematicError kinematic_error;
137 };
138 
140 
146 {
147 public:
148  static const double DEFAULT_SEARCH_DISCRETIZATION; /* = 0.1 */
149  static const double DEFAULT_TIMEOUT; /* = 1.0 */
150 
152  typedef boost::function<void(const geometry_msgs::Pose& ik_pose, const std::vector<double>& ik_solution,
153  moveit_msgs::MoveItErrorCodes& error_code)>
155 
168  virtual bool
169  getPositionIK(const geometry_msgs::Pose& ik_pose, const std::vector<double>& ik_seed_state,
170  std::vector<double>& solution, moveit_msgs::MoveItErrorCodes& error_code,
172 
188  virtual bool getPositionIK(const std::vector<geometry_msgs::Pose>& ik_poses, const std::vector<double>& ik_seed_state,
189  std::vector<std::vector<double> >& solutions, KinematicsResult& result,
190  const kinematics::KinematicsQueryOptions& options) const;
191 
204  virtual bool
205  searchPositionIK(const geometry_msgs::Pose& ik_pose, const std::vector<double>& ik_seed_state, double timeout,
206  std::vector<double>& solution, moveit_msgs::MoveItErrorCodes& error_code,
208 
223  virtual bool
224  searchPositionIK(const geometry_msgs::Pose& ik_pose, const std::vector<double>& ik_seed_state, double timeout,
225  const std::vector<double>& consistency_limits, std::vector<double>& solution,
226  moveit_msgs::MoveItErrorCodes& error_code,
228 
242  virtual bool
243  searchPositionIK(const geometry_msgs::Pose& ik_pose, const std::vector<double>& ik_seed_state, double timeout,
244  std::vector<double>& solution, const IKCallbackFn& solution_callback,
245  moveit_msgs::MoveItErrorCodes& error_code,
247 
263  virtual bool
264  searchPositionIK(const geometry_msgs::Pose& ik_pose, const std::vector<double>& ik_seed_state, double timeout,
265  const std::vector<double>& consistency_limits, std::vector<double>& solution,
266  const IKCallbackFn& solution_callback, moveit_msgs::MoveItErrorCodes& error_code,
268 
290  virtual bool
291  searchPositionIK(const std::vector<geometry_msgs::Pose>& ik_poses, const std::vector<double>& ik_seed_state,
292  double timeout, const std::vector<double>& consistency_limits, std::vector<double>& solution,
293  const IKCallbackFn& solution_callback, moveit_msgs::MoveItErrorCodes& error_code,
295  const moveit::core::RobotState* context_state = NULL) const
296  {
297  // For IK solvers that do not support multiple poses, fall back to single pose call
298  if (ik_poses.size() == 1)
299  {
300  // Check if a solution_callback function was provided and call the corresponding function
301  if (solution_callback)
302  {
303  return searchPositionIK(ik_poses[0], ik_seed_state, timeout, consistency_limits, solution, solution_callback,
304  error_code, options);
305  }
306  else
307  {
308  return searchPositionIK(ik_poses[0], ik_seed_state, timeout, consistency_limits, solution, error_code, options);
309  }
310  }
311 
312  // Otherwise throw error because this function should have been implemented
313  ROS_ERROR_NAMED("kinematics_base", "This kinematic solver does not support searchPositionIK with multiple poses");
314  return false;
315  }
316 
324  virtual bool getPositionFK(const std::vector<std::string>& link_names, const std::vector<double>& joint_angles,
325  std::vector<geometry_msgs::Pose>& poses) const = 0;
326 
337  /* Replace by tip_frames-based method! */
338  [[deprecated]] virtual void setValues(const std::string& robot_description, const std::string& group_name,
339  const std::string& base_frame, const std::string& tip_frame,
340  double search_discretization);
341 
352  virtual void setValues(const std::string& robot_description, const std::string& group_name,
353  const std::string& base_frame, const std::vector<std::string>& tip_frames,
354  double search_discretization);
355 
370  [[deprecated]] virtual bool initialize(const std::string& robot_description, const std::string& group_name,
371  const std::string& base_frame, const std::string& tip_frame,
372  double search_discretization);
373 
388  virtual bool initialize(const std::string& robot_description, const std::string& group_name,
389  const std::string& base_frame, const std::vector<std::string>& tip_frames,
390  double search_discretization);
391 
406  virtual bool initialize(const moveit::core::RobotModel& robot_model, const std::string& group_name,
407  const std::string& base_frame, const std::vector<std::string>& tip_frames,
408  double search_discretization);
409 
414  virtual const std::string& getGroupName() const
415  {
416  return group_name_;
417  }
418 
424  virtual const std::string& getBaseFrame() const
425  {
426  return base_frame_;
427  }
428 
434  virtual const std::string& getTipFrame() const
435  {
436  if (tip_frames_.size() > 1)
437  ROS_ERROR_NAMED("kinematics_base", "This kinematic solver has more than one tip frame, "
438  "do not call getTipFrame()");
439 
440  return tip_frames_[0];
441  }
442 
448  virtual const std::vector<std::string>& getTipFrames() const
449  {
450  return tip_frames_;
451  }
452 
461  virtual bool setRedundantJoints(const std::vector<unsigned int>& redundant_joint_indices);
462 
469  bool setRedundantJoints(const std::vector<std::string>& redundant_joint_names);
470 
474  virtual void getRedundantJoints(std::vector<unsigned int>& redundant_joint_indices) const
475  {
476  redundant_joint_indices = redundant_joint_indices_;
477  }
478 
482  virtual const std::vector<std::string>& getJointNames() const = 0;
483 
487  virtual const std::vector<std::string>& getLinkNames() const = 0;
488 
505  virtual bool supportsGroup(const moveit::core::JointModelGroup* jmg, std::string* error_text_out = NULL) const;
506 
510  void setSearchDiscretization(double sd)
511  {
512  redundant_joint_discretization_.clear();
513  for (unsigned int index : redundant_joint_indices_)
514  redundant_joint_discretization_[index] = sd;
515  }
516 
524  void setSearchDiscretization(const std::map<int, double>& discretization)
525  {
526  redundant_joint_discretization_.clear();
527  redundant_joint_indices_.clear();
528  for (std::map<int, double>::const_iterator i = discretization.begin(); i != discretization.end(); i++)
529  {
530  redundant_joint_discretization_.insert(*i);
531  redundant_joint_indices_.push_back(i->first);
532  }
533  }
534 
538  double getSearchDiscretization(int joint_index = 0) const
539  {
540  if (redundant_joint_discretization_.count(joint_index) > 0)
541  {
542  return redundant_joint_discretization_.at(joint_index);
543  }
544  else
545  {
546  return 0.0; // returned when there aren't any redundant joints
547  }
548  }
549 
554  std::vector<DiscretizationMethod> getSupportedDiscretizationMethods() const
555  {
556  return supported_methods_;
557  }
558 
561  void setDefaultTimeout(double timeout)
562  {
563  default_timeout_ = timeout;
564  }
565 
568  double getDefaultTimeout() const
569  {
570  return default_timeout_;
571  }
572 
576  virtual ~KinematicsBase();
577 
578  KinematicsBase();
579 
580 protected:
581  moveit::core::RobotModelConstPtr robot_model_;
582  std::string robot_description_;
583  std::string group_name_;
584  std::string base_frame_;
585  std::vector<std::string> tip_frames_;
586 
587  // The next two variables still exists for backwards compatibility
588  // with previously generated custom ik solvers like IKFast
589  // Replace tip_frame_ -> tip_frames_[0], search_discretization_ -> redundant_joint_discretization_
590  [[deprecated]] std::string tip_frame_;
591  [[deprecated]] double search_discretization_;
592 
594  std::vector<unsigned int> redundant_joint_indices_;
595  std::map<int, double> redundant_joint_discretization_;
596  std::vector<DiscretizationMethod> supported_methods_;
597 
611  template <typename T>
612  inline bool lookupParam(const std::string& param, T& val, const T& default_val) const
613  {
614  ros::NodeHandle pnh("~");
615  if (pnh.hasParam(group_name_ + "/" + param))
616  {
617  val = pnh.param(group_name_ + "/" + param, default_val);
618  return true;
619  }
620 
621  if (pnh.hasParam(param))
622  {
623  val = pnh.param(param, default_val);
624  return true;
625  }
626 
627  ros::NodeHandle nh;
628  if (nh.hasParam("robot_description_kinematics/" + group_name_ + "/" + param))
629  {
630  val = nh.param("robot_description_kinematics/" + group_name_ + "/" + param, default_val);
631  return true;
632  }
633 
634  if (nh.hasParam("robot_description_kinematics/" + param))
635  {
636  val = nh.param("robot_description_kinematics/" + param, default_val);
637  return true;
638  }
639 
640  val = default_val;
641 
642  return false;
643  }
644 
653  void storeValues(const moveit::core::RobotModel& robot_model, const std::string& group_name,
654  const std::string& base_frame, const std::vector<std::string>& tip_frames,
655  double search_discretization);
656 
657 private:
658  std::string removeSlash(const std::string& str) const;
659 };
660 };
661 
662 #endif
std::vector< unsigned int > redundant_joint_indices_
A set of options for the kinematics solver.
Core components of MoveIt!
void setDefaultTimeout(double timeout)
For functions that require a timeout specified but one is not specified using arguments, a default timeout is used, as set by this function (and initialized to KinematicsBase::DEFAULT_TIMEOUT)
ROSCONSOLE_DECL void initialize()
virtual const std::string & getTipFrame() const
Return the name of the tip frame of the chain on which the solver is operating. This is usually a lin...
void setSearchDiscretization(double sd)
Set the search discretization value for all the redundant joints.
std::vector< std::string > tip_frames_
moveit::core::RobotModelConstPtr robot_model_
double getSearchDiscretization(int joint_index=0) const
Get the value of the search discretization.
static const double DEFAULT_TIMEOUT
virtual void getRedundantJoints(std::vector< unsigned int > &redundant_joint_indices) const
Get the set of redundant joints.
Definition of a kinematic model. This class is not thread safe, however multiple instances can be cre...
Definition: robot_model.h:67
virtual const std::string & getBaseFrame() const
Return the name of the frame in which the solver is operating. This is usually a link name...
DiscretizationMethods::DiscretizationMethod DiscretizationMethod
Provides an interface for kinematics solvers.
unsigned int index
bool param(const std::string &param_name, T &param_val, const T &default_val) const
virtual bool searchPositionIK(const std::vector< geometry_msgs::Pose > &ik_poses, const std::vector< double > &ik_seed_state, double timeout, const std::vector< double > &consistency_limits, std::vector< double > &solution, const IKCallbackFn &solution_callback, moveit_msgs::MoveItErrorCodes &error_code, const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions(), const moveit::core::RobotState *context_state=NULL) const
Given a set of desired poses for a planning group with multiple end-effectors, search for the joint a...
MOVEIT_CLASS_FORWARD(RobotModel)
options
bool lookupParam(const std::string &param, T &val, const T &default_val) const
Enables kinematics plugins access to parameters that are defined for the private namespace and inside...
double getDefaultTimeout() const
For functions that require a timeout specified but one is not specified using arguments, this default timeout is used.
DiscretizationMethod discretization_method
std::vector< DiscretizationMethod > supported_methods_
boost::function< void(const geometry_msgs::Pose &ik_pose, const std::vector< double > &ik_solution, moveit_msgs::MoveItErrorCodes &error_code)> IKCallbackFn
Signature for a callback to validate an IK solution. Typically used for collision checking...
std::vector< DiscretizationMethod > getSupportedDiscretizationMethods() const
Returns the set of supported kinematics discretization search types. This implementation only support...
bool hasParam(const std::string &key) const
std::map< int, double > redundant_joint_discretization_
static const double DEFAULT_SEARCH_DISCRETIZATION
void setSearchDiscretization(const std::map< int, double > &discretization)
Sets individual discretization values for each redundant joint.
API for forward and inverse kinematics.
virtual const std::string & getGroupName() const
Return the name of the group that the solver is operating on.
#define ROS_ERROR_NAMED(name,...)
Representation of a robot&#39;s state. This includes position, velocity, acceleration and effort...
Definition: robot_state.h:122
Main namespace for MoveIt!
virtual const std::vector< std::string > & getTipFrames() const
Return the names of the tip frames of the kinematic tree on which the solver is operating. This is usually a link name. No namespacing (e.g., no "/" prefix) should be used.
KinematicErrors::KinematicError KinematicError


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Thu Mar 26 2020 03:51:41