attached_body.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, 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 the 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 
40 #include <boost/algorithm/string/predicate.hpp>
41 
42 namespace moveit
43 {
44 namespace core
45 {
46 AttachedBody::AttachedBody(const LinkModel* parent_link_model, const std::string& id,
47  const std::vector<shapes::ShapeConstPtr>& shapes,
48  const EigenSTL::vector_Isometry3d& attach_trans, const std::set<std::string>& touch_links,
49  const trajectory_msgs::JointTrajectory& detach_posture,
50  const FixedTransformsMap& subframe_poses)
51  : parent_link_model_(parent_link_model)
52  , id_(id)
53  , shapes_(shapes)
54  , attach_trans_(attach_trans)
55  , touch_links_(touch_links)
56  , detach_posture_(detach_posture)
57  , subframe_poses_(subframe_poses)
58  , global_subframe_poses_(subframe_poses)
59 {
60  for (const auto& t : attach_trans_)
61  {
62  ASSERT_ISOMETRY(t) // unsanitized input, could contain a non-isometry
63  }
64  for (const auto& t : subframe_poses_)
65  {
66  ASSERT_ISOMETRY(t.second) // unsanitized input, could contain a non-isometry
67  }
68  global_collision_body_transforms_.resize(attach_trans.size());
69  for (Eigen::Isometry3d& global_collision_body_transform : global_collision_body_transforms_)
70  global_collision_body_transform.setIdentity();
71 }
72 
73 AttachedBody::~AttachedBody() = default;
74 
75 void AttachedBody::setScale(double scale)
76 {
77  for (shapes::ShapeConstPtr& shape : shapes_)
78  {
79  // if this shape is only owned here (and because this is a non-const function), we can safely const-cast:
80  if (shape.unique())
81  const_cast<shapes::Shape*>(shape.get())->scale(scale);
82  else
83  {
84  // if the shape is owned elsewhere, we make a copy:
85  shapes::Shape* copy = shape->clone();
86  copy->scale(scale);
87  shape.reset(copy);
88  }
89  }
90 }
91 
92 void AttachedBody::computeTransform(const Eigen::Isometry3d& parent_link_global_transform)
93 {
94  ASSERT_ISOMETRY(parent_link_global_transform) // unsanitized input, could contain a non-isometry
95 
96  // update collision body transforms
97  for (std::size_t i = 0; i < global_collision_body_transforms_.size(); ++i)
98  global_collision_body_transforms_[i] = parent_link_global_transform * attach_trans_[i]; // valid isometry
99 
100  // update subframe transforms
101  for (auto global = global_subframe_poses_.begin(), end = global_subframe_poses_.end(), local = subframe_poses_.begin();
102  global != end; ++global, ++local)
103  global->second = parent_link_global_transform * local->second; // valid isometry
104 }
105 
106 void AttachedBody::setPadding(double padding)
107 {
108  for (shapes::ShapeConstPtr& shape : shapes_)
109  {
110  // if this shape is only owned here (and because this is a non-const function), we can safely const-cast:
111  if (shape.unique())
112  const_cast<shapes::Shape*>(shape.get())->padd(padding);
113  else
114  {
115  // if the shape is owned elsewhere, we make a copy:
116  shapes::Shape* copy = shape->clone();
117  copy->padd(padding);
118  shape.reset(copy);
119  }
120  }
121 }
122 
123 const Eigen::Isometry3d& AttachedBody::getSubframeTransform(const std::string& frame_name, bool* found) const
124 {
125  if (boost::starts_with(frame_name, id_) && frame_name[id_.length()] == '/')
126  {
127  auto it = subframe_poses_.find(frame_name.substr(id_.length() + 1));
128  if (it != subframe_poses_.end())
129  {
130  if (found)
131  *found = true;
132  return it->second;
133  }
134  }
135  static const Eigen::Isometry3d IDENTITY_TRANSFORM = Eigen::Isometry3d::Identity();
136  if (found)
137  *found = false;
138  return IDENTITY_TRANSFORM;
139 }
140 
141 const Eigen::Isometry3d& AttachedBody::getGlobalSubframeTransform(const std::string& frame_name, bool* found) const
142 {
143  if (boost::starts_with(frame_name, id_) && frame_name[id_.length()] == '/')
144  {
145  auto it = global_subframe_poses_.find(frame_name.substr(id_.length() + 1));
146  if (it != global_subframe_poses_.end())
147  {
148  if (found)
149  *found = true;
150  return it->second;
151  }
152  }
153  static const Eigen::Isometry3d IDENTITY_TRANSFORM = Eigen::Isometry3d::Identity();
154  if (found)
155  *found = false;
156  return IDENTITY_TRANSFORM;
157 }
158 
159 bool AttachedBody::hasSubframeTransform(const std::string& frame_name) const
160 {
161  bool found;
162  getSubframeTransform(frame_name, &found);
163  return found;
164 }
165 
166 } // namespace core
167 } // namespace moveit
moveit::core::AttachedBody::computeTransform
void computeTransform(const Eigen::Isometry3d &parent_link_global_transform)
Recompute global_collision_body_transform given the transform of the parent link.
Definition: attached_body.cpp:156
shapes
moveit::core::AttachedBody::getGlobalSubframeTransform
const Eigen::Isometry3d & getGlobalSubframeTransform(const std::string &frame_name, bool *found=nullptr) const
Get the fixed transform to a named subframe on this body. The frame_name needs to have the object's n...
Definition: attached_body.cpp:205
check_isometry.h
moveit::core::AttachedBody::~AttachedBody
~AttachedBody()
attached_body.h
moveit::core::AttachedBody::subframe_poses_
moveit::core::FixedTransformsMap subframe_poses_
Transforms to subframes on the object. Transforms are relative to the link.
Definition: attached_body.h:266
shapes::Shape::scale
void scale(double scale)
shapes::Shape
moveit::core::AttachedBody::global_subframe_poses_
moveit::core::FixedTransformsMap global_subframe_poses_
Transforms to subframes on the object, relative to the model frame.
Definition: attached_body.h:269
shapes::Shape::padd
void padd(double padding)
moveit::core::AttachedBody::setScale
void setScale(double scale)
Set the scale for the shapes of this attached object.
Definition: attached_body.cpp:139
moveit::core::AttachedBody::id_
std::string id_
string id for reference
Definition: attached_body.h:247
moveit::core::AttachedBody::setPadding
void setPadding(double padding)
Set the padding for the shapes of this attached object.
Definition: attached_body.cpp:170
moveit::core::AttachedBody::hasSubframeTransform
bool hasSubframeTransform(const std::string &frame_name) const
Check whether a subframe of given @frame_name is present in this object.
Definition: attached_body.cpp:223
ASSERT_ISOMETRY
#define ASSERT_ISOMETRY(transform)
shapes.h
moveit::core::AttachedBody::attach_trans_
EigenSTL::vector_Isometry3d attach_trans_
The constant transforms applied to the link (needs to be specified by user)
Definition: attached_body.h:253
moveit::core::FixedTransformsMap
std::map< std::string, Eigen::Isometry3d, std::less< std::string >, Eigen::aligned_allocator< std::pair< const std::string, Eigen::Isometry3d > > > FixedTransformsMap
Map frame names to the transformation matrix that can transform objects from the frame name to the pl...
Definition: transforms.h:117
moveit::core::AttachedBody::getSubframeTransform
const Eigen::Isometry3d & getSubframeTransform(const std::string &frame_name, bool *found=nullptr) const
Get the fixed transform to a named subframe on this body (relative to the robot link)
Definition: attached_body.cpp:187
moveit
Main namespace for MoveIt.
Definition: background_processing.h:46
moveit::core::AttachedBody::global_collision_body_transforms_
EigenSTL::vector_Isometry3d global_collision_body_transforms_
The global transforms for these attached bodies (computed by forward kinematics)
Definition: attached_body.h:263
shapes::Shape::clone
virtual Shape * clone() const=0
shapes::ShapeConstPtr
std::shared_ptr< const Shape > ShapeConstPtr
moveit::core::AttachedBody::shapes_
std::vector< shapes::ShapeConstPtr > shapes_
The geometries of the attached body.
Definition: attached_body.h:250
moveit::core::AttachedBody::AttachedBody
AttachedBody(const LinkModel *link, const std::string &id, const std::vector< shapes::ShapeConstPtr > &shapes, const EigenSTL::vector_Isometry3d &attach_trans, const std::set< std::string > &touch_links, const trajectory_msgs::JointTrajectory &attach_posture, const moveit::core::FixedTransformsMap &subframe_poses=moveit::core::FixedTransformsMap())
Construct an attached body for a specified link.
Definition: attached_body.cpp:110
t
geometry_msgs::TransformStamped t


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Tue Nov 24 2020 03:26:39