kinematic_element.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018, University of Edinburgh
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_CORE_KINEMATIC_ELEMENT_H_
31 #define EXOTICA_CORE_KINEMATIC_ELEMENT_H_
32 
33 #include <exotica_core/tools.h>
35 #include <kdl/frames.hpp>
36 #include <kdl/segment.hpp>
37 #include <stack>
38 
39 namespace exotica
40 {
42 {
43 public:
45 
46  std::string name;
48  std::string shape_resource_path = "";
50  Eigen::Vector3d scale = Eigen::Vector3d::Ones();
51  Eigen::Vector4d color = Eigen::Vector4d(1.0, 1.0, 1.0, 1.0);
52 };
53 
55 {
56 public:
58 
59  KinematicElement(int _id, std::shared_ptr<KinematicElement> _parent, const KDL::Segment& _segment) : id(_id), parent(_parent), segment(_segment)
60  {
61  }
62 
64  {
65  // Remove from parent to avoid expired pointers
66  std::shared_ptr<KinematicElement> my_parent = parent.lock();
67  if (my_parent)
68  {
69  my_parent->RemoveExpiredChildren();
70  }
71  }
72 
73  inline void UpdateClosestRobotLink()
74  {
75  std::shared_ptr<KinematicElement> element = parent.lock();
76  closest_robot_link = std::shared_ptr<KinematicElement>(nullptr);
77  while (element && element->id > 0)
78  {
79  if (element->is_robot_link)
80  {
81  closest_robot_link = element;
82  break;
83  }
84  element = element->parent.lock();
85  }
86  SetChildrenClosestRobotLink();
87  }
88 
89  inline KDL::Frame GetPose(const double& x = 0.0)
90  {
91  if (is_trajectory_generated)
92  {
93  return generated_offset;
94  }
95  else
96  {
97  return segment.pose(x);
98  }
99  }
100 
101  inline void RemoveExpiredChildren()
102  {
103  for (size_t i = 0; i < children.size(); ++i)
104  {
105  if (children[i].expired())
106  {
107  children.erase(children.begin() + i);
108  }
109  }
110  }
111 
112  int id;
113  int control_id = -1;
114  bool is_controlled = false;
115  std::weak_ptr<KinematicElement> parent;
116  std::string parent_name;
117  std::vector<std::weak_ptr<KinematicElement>> children;
118  std::weak_ptr<KinematicElement> closest_robot_link = std::shared_ptr<KinematicElement>(nullptr);
121  KDL::Frame generated_offset = KDL::Frame::Identity();
122  bool is_trajectory_generated = false;
123  std::vector<double> joint_limits;
124  double velocity_limit = std::numeric_limits<double>::quiet_NaN();
125  double acceleration_limit = std::numeric_limits<double>::quiet_NaN();
127  std::string shape_resource_path = std::string();
128  Eigen::Vector3d scale = Eigen::Vector3d::Ones();
129  bool is_robot_link = false;
130  Eigen::Vector4d color = Eigen::Vector4d(0.5, 0.5, 0.5, 1.0);
131  std::vector<VisualElement> visual;
132 
133 private:
135  {
136  std::stack<std::shared_ptr<KinematicElement>> elements;
137  for (auto child : children) elements.push(child.lock());
138  while (!elements.empty())
139  {
140  auto parent = elements.top();
141  elements.pop();
142  parent->closest_robot_link = closest_robot_link;
143  for (auto child : parent->children) elements.push(child.lock());
144  }
145  }
146 };
147 } // namespace exotica
148 
149 #endif // EXOTICA_CORE_KINEMATIC_ELEMENT_H_
std::vector< std::weak_ptr< KinematicElement > > children
std::weak_ptr< KinematicElement > parent
KDL::Frame GetPose(const double &x=0.0)
std::shared_ptr< Shape > ShapePtr
shapes::ShapePtr shape
EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::string name
EIGEN_MAKE_ALIGNED_OPERATOR_NEW KinematicElement(int _id, std::shared_ptr< KinematicElement > _parent, const KDL::Segment &_segment)
std::vector< VisualElement > visual
std::vector< double > joint_limits
static Frame Identity()
double x
std::shared_ptr< const Shape > ShapeConstPtr


exotica_core
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Sat Apr 10 2021 02:34:49