TebObstacleManager.cpp
Go to the documentation of this file.
1 #include "TebObstacleManager.h"
2 
3 #include <SimoxUtility/algorithm/apply.hpp>
4 
7 #include <teb_local_planner/extension/obstacles/EllipseObstacle.h>
8 #include <teb_local_planner/obstacles.h>
9 
11 {
12 
13  void
15  {
16  container.clear();
17  visualizationIndex = 0;
18  }
19 
20  size_t
22  {
23  return container.size();
24  }
25  void
27  const memory::LaserScannerFeatures& features,
28  viz::Layer* visLayer)
29  {
30 
31  Eigen::Isometry3f global_T_frame = features.frameGlobalPose;
32  for (const auto& feature : features.features)
33  {
34  std::vector<Eigen::Vector2f> convexHull =
35  simox::alg::apply(feature.convexHull,
36  [&](const Eigen::Vector2f& point)
37  {
38  Eigen::Vector3f point3d = conv::to3D(point);
39  return conv::to2D(global_T_frame * point3d);
40  });
41 
42  addPolygonObstacle(convexHull, visLayer);
43  }
44  }
45 
46  void
48  {
49  auto obst = boost::make_shared<teb_local_planner::PolygonObstacle>();
50 
51  for (const auto& vertex : polygon)
52  {
53  obst->pushBackVertex(conv::toRos2D(vertex));
54  }
55  obst->finalizePolygon();
56  container.push_back(obst);
57 
58  // visualize bounding box if layer is available
59  if (visLayer != nullptr)
60  {
61  visLayer->add(viz::Polygon("polygon_" + std::to_string(visualizationIndex++))
62  .points(conv::to3D(polygon))
63  .color(simox::Color::gray()));
64  }
65  }
66 
67  void
68  TebObstacleManager::addBoxObstacle(const VirtualRobot::BoundingBox& bbox, viz::Layer* visLayer)
69  {
70  const Eigen::Vector2f min = conv::to2D(bbox.getMin());
71  const Eigen::Vector2f max = conv::to2D(bbox.getMax());
72 
73  Polygon poly{};
74  poly.push_back(min);
75  poly.emplace_back(min.x(), max.y());
76  poly.push_back(max);
77  poly.emplace_back(max.x(), min.y());
78 
79  addPolygonObstacle(poly, visLayer);
80  }
81 
82  void
84  {
85  auto proxemicZones = proxemics.createProxemicZones(human);
86 
87  int i = 0;
88  for (const auto& proxemicZone : proxemicZones)
89  {
90  auto pose = conv::toRos(proxemicZone.pose);
91  auto shape = conv::toRos(proxemicZone.shape);
92 
93  auto obst = boost::make_shared<teb_local_planner::extension::EllipseObstacle>(
94  pose.position(), pose.theta(), shape.a, shape.b);
95 
96  const auto& penalty = proxemicZone.penalty;
97 
98  obst->setPenaltyModel(conv::toRos(penalty));
99 
100  obst->setWeight(proxemicZone.weight);
101  obst->setHomotopicRelevance(proxemicZone.homotopicRelevance);
102 
103  if (human.linearVelocity != Eigen::Vector2f::Zero())
104  {
105  obst->setCentroidVelocity(conv::toRos2D(human.linearVelocity));
106  }
107 
108  container.push_back(obst);
109 
110  // visualize proxemic zone if layer is available
111  if (visLayer != nullptr)
112  {
113  const Eigen::Vector3f axisLength(
114  proxemicZone.shape.a, proxemicZone.shape.b, 10.f - i);
115  const core::Pose pose3d = conv::to3D(proxemicZone.pose);
116 
117  visLayer->add(viz::Ellipsoid("proxemicZone_" + std::to_string(visualizationIndex++))
118  .pose(pose3d)
119  .axisLengths(axisLength)
120  .color(PROXEMIC_ZONE_COLOR[i % PROXEMIC_ZONE_COLOR.size()]));
121  }
122  i++;
123  }
124  }
125 
126 } // namespace armarx::navigation::local_planning
armarx::navigation::memory::LaserScannerFeatures
Definition: types.h:62
armarx::navigation::local_planning::TebObstacleManager::addBoxObstacle
void addBoxObstacle(const VirtualRobot::BoundingBox &bbox, viz::Layer *visLayer=nullptr)
Definition: TebObstacleManager.cpp:68
armarx::navigation::human::Human
Definition: types.h:33
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
Convex::convexHull
ConvexHull< Point >::type convexHull(const std::vector< Point > &points)
Definition: convexHull.hpp:487
armarx::navigation::local_planning
This file is part of ArmarX.
Definition: fwd.h:35
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:29
armarx::navigation::memory::LaserScannerFeatures::features
std::vector< LaserScannerFeature > features
Definition: types.h:68
armarx::navigation::memory::LaserScannerFeatures::frameGlobalPose
Eigen::Isometry3f frameGlobalPose
Definition: types.h:66
armarx::navigation::conv::toRos
Eigen::Vector2d toRos(const Eigen::Vector3f &vec)
Definition: ros_conversions.cpp:24
armarx::viz::Ellipsoid
Definition: Elements.h:147
armarx::navigation::local_planning::TebObstacleManager::Polygon
std::vector< Eigen::Vector2f > Polygon
Definition: TebObstacleManager.h:39
armarx::navigation::conv::toRos2D
Eigen::Vector2d toRos2D(const Eigen::Vector2f &vec)
Definition: ros_conversions.cpp:18
armarx::navigation::human::ProxemicZoneCreator::createProxemicZones
ProxemicZones createProxemicZones(const Human &human)
Definition: ProxemicZoneCreator.cpp:9
armarx::navigation::human::Human::linearVelocity
Eigen::Vector2f linearVelocity
Definition: types.h:36
armarx::viz::Polygon
Definition: Elements.h:258
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::navigation::conv::to2D
std::vector< Eigen::Vector2f > to2D(const std::vector< Eigen::Vector3f > &v)
Definition: eigen.cpp:26
armarx::navigation::local_planning::TebObstacleManager::clear
void clear()
Definition: TebObstacleManager.cpp:14
armarx::navigation::local_planning::TebObstacleManager::size
size_t size()
Definition: TebObstacleManager.cpp:21
armarx::navigation::local_planning::TebObstacleManager::addLaserScannerFeaturesObstacle
void addLaserScannerFeaturesObstacle(const memory::LaserScannerFeatures &features, viz::Layer *visLayer=nullptr)
Definition: TebObstacleManager.cpp:26
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::navigation::local_planning::TebObstacleManager::addHumanObstacle
void addHumanObstacle(const human::Human &human, viz::Layer *visLayer=nullptr)
Definition: TebObstacleManager.cpp:83
armarx::navigation::conv::to3D
std::vector< Eigen::Vector3f > to3D(const std::vector< Eigen::Vector2f > &v)
Definition: eigen.cpp:11
armarx::navigation::local_planning::TebObstacleManager::addPolygonObstacle
void addPolygonObstacle(const Polygon &polygon, viz::Layer *visLayer=nullptr)
Definition: TebObstacleManager.cpp:47
eigen.h
armarx::viz::Layer
Definition: Layer.h:12
TebObstacleManager.h
ros_conversions.h