v2/kinematics_cache/include/moveit/kinematics_cache/kinematics_cache.h
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2012, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Willow Garage, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Sachin Chitta
36 *********************************************************************/
37 
38 #ifndef KINEMATICS_CACHE_H_
39 #define KINEMATICS_CACHE_H_
40 
41 #include <moveit/kinematics_base/kinematics_base.h>
42 #include <moveit/robot_model/robot_model.h>
43 #include <moveit/robot_state/robot_state.h>
44 
45 #include <boost/shared_ptr.hpp>
46 
47 namespace kinematics_cache
48 {
49 class KinematicsCache
50 {
51 public:
52  struct Options
53  {
54  geometry_msgs::Point origin;
55  boost::array<double, 3> workspace_size;
56  boost::array<double, 3> resolution;
58  };
59 
65 
70  bool generateCacheMap(double timeout);
71 
79  bool getSolution(const geometry_msgs::Pose& pose, unsigned int solution_index, std::vector<double>& solution) const;
80 
90  bool getSolutions(const geometry_msgs::Pose& pose, std::vector<std::vector<double> >& solutions) const;
91 
98  bool getNumSolutions(const geometry_msgs::Pose& pose, unsigned int& num_solutions) const;
99 
106  bool initialize(kinematics::KinematicsBaseConstPtr& solver, const robot_model::RobotModelConstPtr& kinematic_model,
107  const KinematicsCache::Options& opt);
108 
110  const kinematics::KinematicsBaseConstPtr& getSolverInstance() const
111  {
112  return kinematics_solver_;
113  }
114 
116  const robot_model::RobotModelConstPtr& getModelInstance() const
117  {
118  return kinematic_model_;
119  }
120 
123  {
124  return options_;
125  }
126 
127  const std::string& getGroupName() const
128  {
129  return kinematics_solver_->getGroupName();
130  }
131 
134  bool addToCache(const geometry_msgs::Pose& pose, const std::vector<double>& joint_values, bool overwrite = false);
135 
136  bool writeToFile(const std::string& filename);
137 
138  bool readFromFile(const std::string& filename);
139 
140  std::pair<double, double> getMinMaxSquaredDistance();
141 
142 private:
144  unsigned int getSolutionLocation(unsigned int& grid_index, unsigned int& solution_index) const;
145 
147  std::vector<double> getSolution(unsigned int grid_index, unsigned int solution_index) const;
148 
150  bool getGridIndex(const geometry_msgs::Pose& pose, unsigned int& grid_index) const;
151 
153  void setup(const KinematicsCache::Options& opt);
154 
155  void updateDistances(const geometry_msgs::Pose& pose);
156 
158  geometry_msgs::Point cache_origin_;
160  unsigned int cache_size_x_, cache_size_y_, cache_size_z_;
161  unsigned int max_solutions_per_grid_location_;
162  unsigned int solution_dimension_;
163  unsigned int size_grid_node_;
165  unsigned int kinematics_cache_size_;
167  std::vector<double> kinematics_cache_vector_;
168  std::vector<unsigned int> num_solutions_vector_;
170  kinematics::KinematicsBaseConstPtr kinematics_solver_;
172  robot_model::RobotModelConstPtr kinematic_model_;
173  robot_state::RobotStatePtr kinematic_state_;
175  const robot_model::JointModelGroup* joint_model_group_;
176  boost::shared_ptr<robot_state::JointStateGroup> joint_state_group_;
178  // mutable std::vector<double> solution_local_; /** Local pre-allocated storage */
179 
181 };
182 
183 typedef boost::shared_ptr<KinematicsCache> KinematicsCachePtr;
184 }
185 
186 #endif
const kinematics::KinematicsBaseConstPtr & getSolverInstance() const
Return the instance of the kinematics solver.
void setup(const KinematicsCache::Options &opt)
Setup the cache.
bool initialize(kinematics::KinematicsBaseConstPtr &solver, const planning_models::RobotModelConstPtr &kinematic_model, const KinematicsCache::Options &opt)
Initialize the cache class.
const robot_model::RobotModelConstPtr & getModelInstance() const
Return the instance of the kinematics model.
bool addToCache(const geometry_msgs::Pose &pose, const std::vector< double > &joint_values, bool overwrite=false)
Add a new solution to the cache at the given location.
bool generateCacheMap(double timeout)
Generate the cache map spending timeout (seconds) on the generation process)
unsigned int getSolutionLocation(unsigned int &grid_index, unsigned int &solution_index) const
Get the location of a solution given the grid index and solution index.
const Options & getCacheParameters() const
Return the cache parameters used for cache construction.
bool getGridIndex(const geometry_msgs::Pose &pose, unsigned int &grid_index) const
Get the grid index for a given pose.
bool getSolution(const geometry_msgs::Pose &pose, unsigned int solution_index, std::vector< double > &solution) const
Get a candidate solution for a particular pose. Note that the pose will be projected onto the grid us...
bool getNumSolutions(const geometry_msgs::Pose &pose, unsigned int &num_solutions) const
Get number of candidate solutions for a particular pose.
bool getSolutions(const geometry_msgs::Pose &pose, std::vector< std::vector< double > > &solutions) const
Get all candidate solutions for a particular pose. Note that the pose will be projected onto the grid...


moveit_experimental
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley , Jorge Nicho
autogenerated on Wed Jul 10 2019 04:03:02