38 #include <kinematics_cache/kinematics_cache.h> 49 const planning_models::RobotModelConstPtr& kinematic_model,
85 ROS_DEBUG(
"Solution dimension: %d", (
int)solution_dimension_);
90 ros::WallTime start_time = ros::WallTime::now();
91 std::vector<std::string> fk_names;
92 std::vector<double> fk_values;
93 std::vector<geometry_msgs::Pose> poses;
99 while ((ros::WallTime::now() - start_time).toSec() <= timeout &&
106 ROS_ERROR(
"Fk failed");
111 ROS_DEBUG(
"Adding to cache failed for: %f %f %f", poses[0].position.x, poses[0].position.y, poses[0].position.z);
122 unsigned int grid_index;
125 ROS_DEBUG(
"Failed to get grid index");
131 ROS_DEBUG(
"Pose already has max number of solutions");
134 if (num_solutions == 0)
139 for (
unsigned int i = 0; i < joint_values.size(); ++i)
158 ROS_DEBUG(
"X position %f,%d lies outside grid: %d %d", pose.position.x, x_index, 0,
cache_size_x_);
163 ROS_DEBUG(
"Y position %f,%d lies outside grid: %d %d", pose.position.y, y_index, 0,
cache_size_y_);
168 ROS_DEBUG(
"Z position %f,%d lies outside grid: %d %d", pose.position.z, z_index, 0,
cache_size_z_);
171 ROS_DEBUG(
"Grid indices: %d %d %d", x_index, y_index, z_index);
178 unsigned int grid_index;
188 ROS_DEBUG(
"[Grid Index, Solution number location]: %d, %d", grid_index,
190 return (grid_index *
size_grid_node_ + solution_index * solution_dimension_);
194 std::vector<double>& solution)
const 196 unsigned int grid_index;
204 solution =
getSolution(grid_index, solution_index);
210 unsigned int grid_index;
215 for (
unsigned int i = 0; i < solution.size(); i++)
230 return solution_local;
235 std::ifstream file(filename.c_str());
238 ROS_WARN(
"Could not open file: %s", filename.c_str());
241 std::string group_name;
242 std::getline(file, group_name);
243 if (group_name.empty())
245 ROS_ERROR(
"Could not find group_name in file: %s", group_name.c_str());
251 ROS_ERROR(
"Input file group name %s does not match solver group name %s", group_name.c_str(),
257 std::string line_string;
258 std::getline(file, line_string);
259 std::stringstream line_stream(line_string);
262 std::getline(file, line_string);
265 line_stream << line_string;
268 std::getline(file, line_string);
271 line_stream << line_string;
274 std::getline(file, line_string);
277 line_stream << line_string;
282 std::getline(file, line_string);
285 line_stream << line_string;
288 std::getline(file, line_string);
291 line_stream << line_string;
294 std::vector<double> kinematics_cache_vector;
295 std::vector<unsigned int> num_solutions_vector;
296 std::getline(file, line_string);
297 std::getline(file, line_string);
300 line_stream << line_string;
302 while (line_stream >> d)
304 kinematics_cache_vector.push_back(d);
307 std::getline(file, line_string);
308 std::getline(file, line_string);
311 line_stream << line_string;
313 while (line_stream >> index)
315 num_solutions_vector.push_back(index);
322 ROS_DEBUG(
"Read %d total points from file: %s", (
int)
num_solutions_vector_.size(), filename.c_str());
328 ROS_DEBUG(
"Writing %d total points to file: %s", (
int)
num_solutions_vector_.size(), filename.c_str());
330 file.open(filename.c_str());
333 ROS_WARN(
"Could not open file: %s", filename.c_str());
339 file << group_name << std::endl;
350 std::ostream_iterator<double>(file,
" "));
355 std::ostream_iterator<unsigned int>(file,
" "));
370 double distance_squared =
371 (pose.position.x * pose.position.x + pose.position.y * pose.position.y + pose.position.z * pose.position.z);
void updateDistances(const geometry_msgs::Pose &pose)
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.
double cache_resolution_z_
double min_squared_distance_
geometry_msgs::Point origin
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.
geometry_msgs::Point cache_origin_
bool generateCacheMap(double timeout)
Generate the cache map spending timeout (seconds) on the generation process)
kinematics::KinematicsBaseConstPtr kinematics_solver_
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.
unsigned int max_solutions_per_grid_location
KinematicsCache::Options options_
bool readFromFile(const std::string &filename)
unsigned int cache_size_y_
double max_squared_distance_
double cache_resolution_x_
unsigned int kinematics_cache_size_
bool getGridIndex(const geometry_msgs::Pose &pose, unsigned int &grid_index) const
Get the grid index for a given pose.
unsigned int max_solutions_per_grid_location_
boost::shared_ptr< planning_models::RobotState *::JointStateGroup > joint_state_group_
bool writeToFile(const std::string &filename)
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...
boost::array< double, 3 > resolution
std::vector< double > kinematics_cache_vector_
double cache_resolution_y_
bool getNumSolutions(const geometry_msgs::Pose &pose, unsigned int &num_solutions) const
Get number of candidate solutions for a particular pose.
unsigned int solution_dimension_
planning_models::RobotModelConstPtr kinematic_model_
boost::array< double, 3 > workspace_size
unsigned int cache_size_z_
unsigned int kinematics_cache_points_with_solution_
unsigned int cache_size_x_
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...
unsigned int size_grid_node_
std::vector< unsigned int > num_solutions_vector_
std::pair< double, double > getMinMaxSquaredDistance()
planning_models::RobotState *Ptr kinematic_state_
const planning_models::RobotModel::JointModelGroup * joint_model_group_