constraint_sampler_tools.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, 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: Ioan Sucan */
36 
39 
40 void constraint_samplers::visualizeDistribution(const moveit_msgs::Constraints& constr,
41  const planning_scene::PlanningSceneConstPtr& scene,
42  const std::string& group, const std::string& link_name,
43  unsigned int sample_count, visualization_msgs::MarkerArray& markers)
44 {
45  visualizeDistribution(ConstraintSamplerManager::selectDefaultSampler(scene, group, constr), scene->getCurrentState(),
46  link_name, sample_count, markers);
47 }
48 
49 double constraint_samplers::countSamplesPerSecond(const moveit_msgs::Constraints& constr,
50  const planning_scene::PlanningSceneConstPtr& scene,
51  const std::string& group)
52 {
53  return countSamplesPerSecond(ConstraintSamplerManager::selectDefaultSampler(scene, group, constr),
54  scene->getCurrentState());
55 }
56 
57 double constraint_samplers::countSamplesPerSecond(const ConstraintSamplerPtr& sampler,
58  const robot_state::RobotState& reference_state)
59 {
60  if (!sampler)
61  {
62  ROS_ERROR_NAMED("constraint_samplers", "No sampler specified for counting samples per second");
63  return 0.0;
64  }
65  robot_state::RobotState ks(reference_state);
66  unsigned long int valid = 0;
67  unsigned long int total = 0;
69  do
70  {
71  static const unsigned int n = 10;
72  total += n;
73  for (unsigned int i = 0; i < n; ++i)
74  {
75  if (sampler->sample(ks, 1))
76  valid++;
77  }
78  } while (ros::WallTime::now() < end);
79  return (double)valid / (double)total;
80 }
81 
82 void constraint_samplers::visualizeDistribution(const ConstraintSamplerPtr& sampler,
83  const robot_state::RobotState& reference_state,
84  const std::string& link_name, unsigned int sample_count,
85  visualization_msgs::MarkerArray& markers)
86 {
87  if (!sampler)
88  {
89  ROS_ERROR_NAMED("constraint_samplers", "No sampler specified for visualizing distribution of samples");
90  return;
91  }
92  const robot_state::LinkModel* lm = reference_state.getLinkModel(link_name);
93  if (!lm)
94  return;
95  robot_state::RobotState ks(reference_state);
96  std_msgs::ColorRGBA color;
97  color.r = 1.0f;
98  color.g = 0.0f;
99  color.b = 0.0f;
100  color.a = 1.0f;
101  for (unsigned int i = 0; i < sample_count; ++i)
102  {
103  if (!sampler->sample(ks))
104  continue;
105  const Eigen::Vector3d& pos = ks.getGlobalLinkTransform(lm).translation();
106  visualization_msgs::Marker mk;
107  mk.header.stamp = ros::Time::now();
108  mk.header.frame_id = sampler->getJointModelGroup()->getParentModel().getModelFrame();
109  mk.ns = "constraint_samples";
110  mk.id = i;
111  mk.type = visualization_msgs::Marker::SPHERE;
112  mk.action = visualization_msgs::Marker::ADD;
113  mk.pose.position.x = pos.x();
114  mk.pose.position.y = pos.y();
115  mk.pose.position.z = pos.z();
116  mk.pose.orientation.w = 1.0;
117  mk.scale.x = mk.scale.y = mk.scale.z = 0.035;
118  mk.color = color;
119  mk.lifetime = ros::Duration(30.0);
120  markers.markers.push_back(mk);
121  }
122 }
void visualizeDistribution(const ConstraintSamplerPtr &sampler, const robot_state::RobotState &reference_state, const std::string &link_name, unsigned int sample_count, visualization_msgs::MarkerArray &markers)
const Eigen::Affine3d & getGlobalLinkTransform(const std::string &link_name)
Definition: robot_state.h:1368
double countSamplesPerSecond(const ConstraintSamplerPtr &sampler, const robot_state::RobotState &reference_state)
static WallTime now()
const LinkModel * getLinkModel(const std::string &link) const
Get the model of a particular link.
Definition: robot_state.h:156
#define ROS_ERROR_NAMED(name,...)
static Time now()
Representation of a robot&#39;s state. This includes position, velocity, acceleration and effort...
Definition: robot_state.h:123
A link from the robot. Contains the constant transform applied to the link and its geometry...
Definition: link_model.h:72


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Wed Jul 10 2019 04:03:05