38 #include <rclcpp/duration.hpp>
39 #include <rclcpp/logger.hpp>
40 #include <rclcpp/logging.hpp>
41 #include <rclcpp/time.hpp>
42 #include <tf2_eigen/tf2_eigen.hpp>
48 static const rclcpp::Logger LOGGER =
49 rclcpp::get_logger(
"moveit_collision_distance_field.collision_common_distance_field");
52 using Comperator = std::owner_less<shapes::ShapeConstWeakPtr>;
53 using Map = std::map<shapes::ShapeConstWeakPtr, BodyDecompositionConstPtr, Comperator>;
74 shapes::ShapeConstWeakPtr wptr(shape);
76 std::scoped_lock slock(cache.
lock_);
77 BodyDecompositionCache::Map::const_iterator cache_it = cache.
map_.find(wptr);
78 if (cache_it != cache.
map_.end())
80 return cache_it->second;
84 BodyDecompositionConstPtr bdcp = std::make_shared<const BodyDecomposition>(shape, resolution);
86 std::scoped_lock slock(cache.
lock_);
87 cache.
map_[wptr] = bdcp;
97 PosedBodyPointDecompositionVectorPtr ret = std::make_shared<PosedBodyPointDecompositionVector>();
98 for (
unsigned int i = 0; i < obj.
shapes_.size(); ++i)
100 PosedBodyPointDecompositionPtr pbd(
102 ret->addToVector(pbd);
111 PosedBodySphereDecompositionVectorPtr ret = std::make_shared<PosedBodySphereDecompositionVector>();
112 for (
unsigned int i = 0; i < att->
getShapes().size(); ++i)
114 PosedBodySphereDecompositionPtr pbd(
117 ret->addToVector(pbd);
125 PosedBodyPointDecompositionVectorPtr ret = std::make_shared<PosedBodyPointDecompositionVector>();
126 for (
unsigned int i = 0; i < att->
getShapes().size(); ++i)
128 PosedBodyPointDecompositionPtr pbd =
130 ret->addToVector(pbd);
137 visualization_msgs::msg::MarkerArray& body_marker_array)
140 std::string robot_ns = gsr->dfce_->group_name_ +
"_sphere_decomposition";
141 std::string attached_ns =
"attached_sphere_decomposition";
144 std_msgs::msg::ColorRGBA robot_color;
146 robot_color.b = 0.8f;
150 std_msgs::msg::ColorRGBA attached_color;
151 attached_color.r = 1;
152 attached_color.g = 1;
153 attached_color.b = 0;
154 attached_color.a = 0.5;
157 visualization_msgs::msg::Marker sphere_marker;
158 sphere_marker.header.frame_id = reference_frame;
159 sphere_marker.header.stamp = rclcpp::Time(0);
160 sphere_marker.ns = robot_ns;
161 sphere_marker.id = 0;
162 sphere_marker.type = visualization_msgs::msg::Marker::SPHERE;
163 sphere_marker.action = visualization_msgs::msg::Marker::ADD;
164 sphere_marker.pose.orientation.x = 0;
165 sphere_marker.pose.orientation.y = 0;
166 sphere_marker.pose.orientation.z = 0;
167 sphere_marker.pose.orientation.w = 1;
168 sphere_marker.color = robot_color;
169 sphere_marker.lifetime = rclcpp::Duration(0, 0);
173 for (
unsigned int i = 0; i < gsr->dfce_->link_names_.size(); ++i)
176 if (gsr->dfce_->link_has_geometry_[i])
180 collision_detection::PosedBodySphereDecompositionConstPtr sphere_representation =
181 gsr->link_body_decompositions_[i];
182 for (
unsigned int j = 0; j < sphere_representation->getCollisionSpheres().size(); ++j)
184 sphere_marker.pose.position = tf2::toMsg(sphere_representation->getSphereCenters()[j]);
185 sphere_marker.scale.x = sphere_marker.scale.y = sphere_marker.scale.z =
186 sphere_representation->getCollisionSpheres()[j].radius_;
187 sphere_marker.id = id;
190 body_marker_array.markers.push_back(sphere_marker);
195 sphere_marker.ns = attached_ns;
196 sphere_marker.color = attached_color;
197 for (
unsigned int i = 0; i < gsr->dfce_->attached_body_names_.size(); ++i)
203 "Attached body '%s' was not found, skipping sphere "
204 "decomposition visualization",
205 gsr->dfce_->attached_body_names_[i].c_str());
209 if (gsr->attached_body_decompositions_[i]->getSize() != att->
getShapes().size())
211 RCLCPP_WARN(LOGGER,
"Attached body size discrepancy");
215 for (
unsigned int j = 0; j < att->
getShapes().size(); ++j)
217 PosedBodySphereDecompositionVectorPtr sphere_decp = gsr->attached_body_decompositions_[i];
220 sphere_marker.pose.position = tf2::toMsg(sphere_decp->getSphereCenters()[j]);
221 sphere_marker.scale.x = sphere_marker.scale.y = sphere_marker.scale.z =
222 sphere_decp->getCollisionSpheres()[j].radius_;
223 sphere_marker.id = id;
224 body_marker_array.markers.push_back(sphere_marker);
Object defining bodies that can be attached to robot links.
const EigenSTL::vector_Isometry3d & getGlobalCollisionBodyTransforms() const
Get the global transforms (in world frame) for the collision bodies. The returned transforms are guar...
const std::vector< shapes::ShapeConstPtr > & getShapes() const
Get the shapes that make up this attached body.
A link from the robot. Contains the constant transform applied to the link and its geometry.
const std::string & getName() const
The name of this link.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
const LinkModel * getLinkModel(const std::string &link) const
Get the model of a particular link.
const Eigen::Isometry3d & getFrameTransform(const std::string &frame_id, bool *frame_found=nullptr)
Get the transformation matrix from the model frame (root of model) to the frame identified by frame_i...
const AttachedBody * getAttachedBody(const std::string &name) const
Get the attached body named name. Return nullptr if not found.
PosedBodyPointDecompositionVectorPtr getCollisionObjectPointDecomposition(const collision_detection::World::Object &obj, double resolution)
void getBodySphereVisualizationMarkers(const GroupStateRepresentationPtr &gsr, const std::string &reference_frame, visualization_msgs::msg::MarkerArray &body_marker_array)
BodyDecompositionCache & getBodyDecompositionCache()
PosedBodySphereDecompositionVectorPtr getAttachedBodySphereDecomposition(const moveit::core::AttachedBody *att, double resolution)
BodyDecompositionConstPtr getBodyDecompositionCacheEntry(const shapes::ShapeConstPtr &shape, double resolution)
PosedBodyPointDecompositionVectorPtr getAttachedBodyPointDecomposition(const moveit::core::AttachedBody *att, double resolution)
static const unsigned int MAX_CLEAN_COUNT
unsigned int clean_count_
std::owner_less< shapes::ShapeConstWeakPtr > Comperator
std::map< shapes::ShapeConstWeakPtr, BodyDecompositionConstPtr, Comperator > Map
A representation of an object.
EigenSTL::vector_Isometry3d global_shape_poses_
The poses of the corresponding entries in shapes_, relative to the world frame.
std::vector< shapes::ShapeConstPtr > shapes_
All the shapes making up this object.