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