|
| 1 | +/********************************************************************* |
| 2 | + * Software License Agreement (BSD License) |
| 3 | + * |
| 4 | + * Copyright (c) 2012, 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, Inc. 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 | + |
| 37 | +#pragma once |
| 38 | + |
| 39 | +#include <moveit/robot_model/link_model.hpp> |
| 40 | +#include <moveit/transforms/transforms.hpp> |
| 41 | +#include <geometric_shapes/check_isometry.h> |
| 42 | +#include <eigen_stl_containers/eigen_stl_containers.h> |
| 43 | +#include <trajectory_msgs/msg/joint_trajectory.hpp> |
| 44 | +#include <set> |
| 45 | +#include <functional> |
| 46 | + |
| 47 | +namespace moveit |
| 48 | +{ |
| 49 | +namespace core |
| 50 | +{ |
| 51 | +class AttachedBody; |
| 52 | +typedef std::function<void(AttachedBody* body, bool attached)> AttachedBodyCallback; |
| 53 | + |
| 54 | +/** @brief Object defining bodies that can be attached to robot links. |
| 55 | + * |
| 56 | + * This is useful when handling objects picked up by the robot. */ |
| 57 | +class AttachedBody |
| 58 | +{ |
| 59 | +public: |
| 60 | + /** \brief Construct an attached body for a specified \e link. |
| 61 | + * |
| 62 | + * The name of this body is \e id and it consists of \e shapes that attach to the link by the transforms |
| 63 | + * \e shape_poses. The set of links that are allowed to be touched by this object is specified by \e touch_links. |
| 64 | + * detach_posture may describe a detach motion for the gripper when placing the object. |
| 65 | + * The shape and subframe poses are relative to the \e pose, and \e pose is relative to the parent link. */ |
| 66 | + AttachedBody(const LinkModel* parent, const std::string& id, const Eigen::Isometry3d& pose, |
| 67 | + const std::vector<shapes::ShapeConstPtr>& shapes, const EigenSTL::vector_Isometry3d& shape_poses, |
| 68 | + const std::set<std::string>& touch_links, const trajectory_msgs::msg::JointTrajectory& detach_posture, |
| 69 | + const moveit::core::FixedTransformsMap& subframe_poses = moveit::core::FixedTransformsMap()); |
| 70 | + |
| 71 | + ~AttachedBody(); |
| 72 | + |
| 73 | + /** \brief Get the name of the attached body */ |
| 74 | + const std::string& getName() const |
| 75 | + { |
| 76 | + return id_; |
| 77 | + } |
| 78 | + |
| 79 | + /** \brief Get the pose of the attached body relative to the parent link */ |
| 80 | + const Eigen::Isometry3d& getPose() const |
| 81 | + { |
| 82 | + return pose_; |
| 83 | + } |
| 84 | + |
| 85 | + /** \brief Get the pose of the attached body, relative to the world */ |
| 86 | + const Eigen::Isometry3d& getGlobalPose() const |
| 87 | + { |
| 88 | + return global_pose_; |
| 89 | + } |
| 90 | + |
| 91 | + /** \brief Get the name of the link this body is attached to */ |
| 92 | + const std::string& getAttachedLinkName() const |
| 93 | + { |
| 94 | + return parent_link_model_->getName(); |
| 95 | + } |
| 96 | + |
| 97 | + /** \brief Get the model of the link this body is attached to */ |
| 98 | + const LinkModel* getAttachedLink() const |
| 99 | + { |
| 100 | + return parent_link_model_; |
| 101 | + } |
| 102 | + |
| 103 | + /** \brief Get the shapes that make up this attached body */ |
| 104 | + const std::vector<shapes::ShapeConstPtr>& getShapes() const |
| 105 | + { |
| 106 | + return shapes_; |
| 107 | + } |
| 108 | + |
| 109 | + /** \brief Get the shape poses (the transforms to the shapes of this body, relative to the pose). The returned |
| 110 | + * transforms are guaranteed to be valid isometries. */ |
| 111 | + const EigenSTL::vector_Isometry3d& getShapePoses() const |
| 112 | + { |
| 113 | + return shape_poses_; |
| 114 | + } |
| 115 | + |
| 116 | + /** \brief Get the links that the attached body is allowed to touch */ |
| 117 | + const std::set<std::string>& getTouchLinks() const |
| 118 | + { |
| 119 | + return touch_links_; |
| 120 | + } |
| 121 | + |
| 122 | + /** \brief Return the posture that is necessary for the object to be released, (if any). This is useful for example |
| 123 | + when storing the configuration of a gripper holding an object */ |
| 124 | + const trajectory_msgs::msg::JointTrajectory& getDetachPosture() const |
| 125 | + { |
| 126 | + return detach_posture_; |
| 127 | + } |
| 128 | + |
| 129 | + /** \brief Get the fixed transforms (the transforms to the shapes of this body, relative to the link). The returned |
| 130 | + * transforms are guaranteed to be valid isometries. */ |
| 131 | + const EigenSTL::vector_Isometry3d& getShapePosesInLinkFrame() const |
| 132 | + { |
| 133 | + return shape_poses_in_link_frame_; |
| 134 | + } |
| 135 | + |
| 136 | + /** \brief Get subframes of this object (relative to the object pose). The returned transforms are guaranteed to be |
| 137 | + * valid isometries. */ |
| 138 | + const moveit::core::FixedTransformsMap& getSubframes() const |
| 139 | + { |
| 140 | + return subframe_poses_; |
| 141 | + } |
| 142 | + |
| 143 | + /** \brief Get subframes of this object (in the world frame) */ |
| 144 | + const moveit::core::FixedTransformsMap& getGlobalSubframeTransforms() const |
| 145 | + { |
| 146 | + return global_subframe_poses_; |
| 147 | + } |
| 148 | + |
| 149 | + /** \brief Set all subframes of this object. |
| 150 | + * |
| 151 | + * Use these to define points of interest on the object to plan with |
| 152 | + * (e.g. screwdriver/tip, kettle/spout, mug/base). |
| 153 | + */ |
| 154 | + void setSubframeTransforms(const moveit::core::FixedTransformsMap& subframe_poses) |
| 155 | + { |
| 156 | + for (const auto& t : subframe_poses) |
| 157 | + { |
| 158 | + ASSERT_ISOMETRY(t.second) // unsanitized input, could contain a non-isometry |
| 159 | + } |
| 160 | + subframe_poses_ = subframe_poses; |
| 161 | + } |
| 162 | + |
| 163 | + /** \brief Get the fixed transform to a named subframe on this body (relative to the body's pose) |
| 164 | + * |
| 165 | + * The frame_name needs to have the object's name prepended (e.g. "screwdriver/tip" returns true if the object's |
| 166 | + * name is "screwdriver"). Returns an identity transform if frame_name is unknown (and set found to false). |
| 167 | + * The returned transform is guaranteed to be a valid isometry. */ |
| 168 | + const Eigen::Isometry3d& getSubframeTransform(const std::string& frame_name, bool* found = nullptr) const; |
| 169 | + |
| 170 | + /** \brief Get the fixed transform to a named subframe on this body, relative to the world frame. |
| 171 | + * The frame_name needs to have the object's name prepended (e.g. "screwdriver/tip" returns true if the object's |
| 172 | + * name is "screwdriver"). Returns an identity transform if frame_name is unknown (and set found to false). |
| 173 | + * The returned transform is guaranteed to be a valid isometry. */ |
| 174 | + const Eigen::Isometry3d& getGlobalSubframeTransform(const std::string& frame_name, bool* found = nullptr) const; |
| 175 | + |
| 176 | + /** \brief Check whether a subframe of given @frame_name is present in this object. |
| 177 | + * |
| 178 | + * The frame_name needs to have the object's name prepended (e.g. "screwdriver/tip" returns true if the object's |
| 179 | + * name is "screwdriver"). */ |
| 180 | + bool hasSubframeTransform(const std::string& frame_name) const; |
| 181 | + |
| 182 | + /** \brief Get the global transforms (in world frame) for the collision bodies. The returned transforms are |
| 183 | + * guaranteed to be valid isometries. */ |
| 184 | + const EigenSTL::vector_Isometry3d& getGlobalCollisionBodyTransforms() const |
| 185 | + { |
| 186 | + return global_collision_body_transforms_; |
| 187 | + } |
| 188 | + |
| 189 | + /** \brief Set the padding for the shapes of this attached object */ |
| 190 | + void setPadding(double padding); |
| 191 | + |
| 192 | + /** \brief Set the scale for the shapes of this attached object */ |
| 193 | + void setScale(double scale); |
| 194 | + |
| 195 | + /** \brief Recompute global_collision_body_transform given the transform of the parent link */ |
| 196 | + void computeTransform(const Eigen::Isometry3d& parent_link_global_transform); |
| 197 | + |
| 198 | +private: |
| 199 | + /** \brief The link that owns this attached body */ |
| 200 | + const LinkModel* parent_link_model_; |
| 201 | + |
| 202 | + /** \brief string id for reference */ |
| 203 | + std::string id_; |
| 204 | + |
| 205 | + /** \brief The transform from the parent link to the attached body's pose*/ |
| 206 | + Eigen::Isometry3d pose_; |
| 207 | + |
| 208 | + /** \brief The transform from the model frame to the attached body's pose */ |
| 209 | + Eigen::Isometry3d global_pose_; |
| 210 | + |
| 211 | + /** \brief The geometries of the attached body */ |
| 212 | + std::vector<shapes::ShapeConstPtr> shapes_; |
| 213 | + |
| 214 | + /** \brief The transforms from the object's pose to the object's geometries*/ |
| 215 | + EigenSTL::vector_Isometry3d shape_poses_; |
| 216 | + |
| 217 | + /** \brief The transforms from the link to the object's geometries*/ |
| 218 | + EigenSTL::vector_Isometry3d shape_poses_in_link_frame_; |
| 219 | + |
| 220 | + /** \brief The global transforms for the attached bodies (computed by forward kinematics) */ |
| 221 | + EigenSTL::vector_Isometry3d global_collision_body_transforms_; |
| 222 | + |
| 223 | + /** \brief The set of links this body is allowed to touch */ |
| 224 | + std::set<std::string> touch_links_; |
| 225 | + |
| 226 | + /** \brief Posture of links for releasing the object (if any). This is useful for example when storing |
| 227 | + the configuration of a gripper holding an object */ |
| 228 | + trajectory_msgs::msg::JointTrajectory detach_posture_; |
| 229 | + |
| 230 | + /** \brief Transforms to subframes on the object, relative to the object's pose. */ |
| 231 | + moveit::core::FixedTransformsMap subframe_poses_; |
| 232 | + |
| 233 | + /** \brief Transforms to subframes on the object, relative to the model frame. */ |
| 234 | + moveit::core::FixedTransformsMap global_subframe_poses_; |
| 235 | +}; |
| 236 | +} // namespace core |
| 237 | +} // namespace moveit |
0 commit comments