moveit2
The MoveIt Motion Planning Framework for ROS 2.
example.cpp
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 
39 #include <ros/ros.h>
40 
41 int main(int argc, char** argv)
42 {
43  ros::init(argc, argv, "kinematics_cache");
45  opt.origin.x = 0.0;
46  opt.origin.y = -1.0;
47  opt.origin.z = -1.0;
48 
49  opt.workspace_size[0] = 2.0;
50  opt.workspace_size[1] = 2.0;
51  opt.workspace_size[2] = 2.0;
52 
53  opt.resolution[0] = 0.01;
54  opt.resolution[1] = 0.01;
55  opt.resolution[2] = 0.01;
56  opt.max_solutions_per_grid_location = 2;
57 
58  kinematics_cache_ros::KinematicsCacheROS pr2_kinematics_cache;
59  ros::NodeHandle private_handle("~");
60 
61  if (!pr2_kinematics_cache.init(opt, "pr2_arm_kinematics/PR2ArmKinematicsPlugin", "right_arm", "torso_lift_link",
62  "r_wrist_roll_link", 0.01))
63  return (0);
64 
65  pr2_kinematics_cache.generateCacheMap(10.0);
66 
67  geometry_msgs::Pose point;
68  point.position.x = 0.0;
69  point.position.y = -1.0;
70  point.position.z = -1.0;
71 
72  unsigned int max_num = 200;
73 
74  for (unsigned int i = 0; i < max_num; ++i)
75  {
76  point.position.x = opt.origin.x + i / 100.0;
77  for (unsigned int j = 0; j < max_num; ++j)
78  {
79  point.position.y = opt.origin.y + j / 100.0;
80  for (unsigned int k = 0; k < max_num; ++k)
81  {
82  point.position.z = opt.origin.z + k / 100.0;
83  unsigned int num_solutions(0);
84  if (!pr2_kinematics_cache.getNumSolutions(point, num_solutions))
85  ROS_ERROR("Outside grid");
86  else if (num_solutions > 0)
87  ROS_INFO("Num solutions: %d", num_solutions);
88  }
89  }
90  }
91  return (0);
92 }
bool generateCacheMap(double timeout)
Generate the cache map spending timeout (seconds) on the generation process)
bool getNumSolutions(const geometry_msgs::Pose &pose, unsigned int &num_solutions) const
Get number of candidate solutions for a particular pose.
bool init(const kinematics_cache::KinematicsCache::Options &opt, const std::string &kinematics_solver_name, const std::string &group_name, const std::string &base_frame, const std::string &tip_frame, double search_discretization)
Initialization function.
int main(int argc, char **argv)
Definition: example.cpp:41