Costmap3DBuilder.h
Go to the documentation of this file.
1/**
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Niklas Arlt ( niklas dot arlt at kit dot edu )
17 * @date 2025
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <functional>
25#include <optional>
26#include <string>
27#include <vector>
28
29#include <Eigen/Core>
30#include <Eigen/Geometry>
31
32#include <VirtualRobot/SceneObjectSet.h>
33#include <VirtualRobot/VirtualRobot.h>
34
42
44{
45
47 {
48 public:
50 {
51 bool restrictToRooms = false;
52
53 /*!
54 * Only applicable when restrictToRooms is true.
55 * The list of rooms for which the costmap should be generated, leave empty to
56 * include all rooms.
57 */
58 std::vector<std::string> roomEnableList;
59
60 /*!
61 * The maximum distance from the costmap to an obstacle to be included for costmap
62 * calculation. Every obstacles further away will be discarded.
63 */
64 float maxFilterDistance = 1000.F;
65
66
67 Eigen::Vector3f collisionModelScaleFactor = Eigen::Vector3f::Ones();
68 bool approximation2D = false;
69 float approx2DignoreVerticesOver = 2000.F; // [mm]
70 float obstacleSafetyMargin = 15.F; // [mm]
71
72 std::set<std::string> primitiveApproximationIDs;
73 };
74
76 const VirtualRobot::SceneObjectSetPtr& obstacles,
77 const std::vector<VirtualRobot::RobotPtr>& articulatedObjects,
78 const std::vector<Room>& rooms,
79 const Costmap3D::Parameters& parameters,
80 const std::string& robotCollisonModelName,
81 const Costmap3DBuilderParams& builderParameters);
82
83 Costmap3D create(const SceneBounds& init = SceneBounds());
84
85 // Extend costmap from laser scanners / cartographer
87
88
89 static Costmap3D::Grid createUniformGrid(const SceneBounds& sceneBounds,
90 const Costmap3D::Parameters& parameters);
91
92 static Eigen::MatrixXf
94 const Costmap3D::Parameters& parameters);
95
96 static void initializeMask(Costmap3D& costmap);
97
99 {
102
103 Eigen::Isometry2f root_T_used_root_2d = Eigen::Isometry2f::Identity();
104 };
105
106 std::optional<DebugOutput2D> getDebugOutput2D();
107
108 private:
109 using CollisionPolygon = util::geometry::polygon_type;
110
111 float computeCost(const core::Pose2D& pose2d, const Robot2D& robot2d, const Scene2D& scene);
112
113 Costmap3D inflateRotationDimension(Costmap& costmap);
114
115 void fillGridCosts2D(Costmap3D& costmap);
116 void fillGridCosts(Costmap3D& costmap);
117 void extendGridCosts(Costmap3D& costmap, const std::vector<Room>& rooms);
118
119 VirtualRobot::SceneObjectSetPtr filterObjectsForCostmap(const Costmap3D& costmap);
120
121 // fn: collisionRobot, robotCollisionModel, mask, costs, index -> costs
122 // expects mask calculation based on costs after this function
123
124 struct MapStructCommon
125 {
126 std::optional<float> maskOpt;
127 float cost;
128 const Costmap3D::Index& posIdx;
130
131 bool
132 isMaskedOut() const
133 {
134 return maskOpt.has_value() and not maskOpt.value();
135 }
136 };
137
138 struct MapStruct
139 {
140 MapStructCommon c;
141 DistanceCalculator distanceCalculator;
142 };
143
144 struct MapStructRobot2D
145 {
146 MapStructCommon c;
147 Robot2D robot;
148 Scene2D scene;
149 };
150
151 std::optional<DebugOutput2D> debugOutput2D;
152
153 using MapFn = std::function<float(const MapStruct&)>;
154 using MapFnRobot2D = std::function<float(const MapStructRobot2D&)>;
155 void applyFnToCostmap(Costmap3D& costmap, const MapFn& fn);
156 void applyFnToCostmap(Costmap3D& costmap, const MapFnRobot2D& fn);
157
158 void initializeEmptyMask(Costmap3D& costmap);
159
160 const VirtualRobot::RobotPtr robot;
161 const VirtualRobot::SceneObjectSetPtr obstacles;
162 VirtualRobot::SceneObjectSetPtr filteredObstacles;
163 const std::vector<VirtualRobot::RobotPtr> articulatedObjects;
164 std::vector<Room> rooms;
165 const Costmap3D::Parameters parameters;
166 const std::string robotCollisionModelName;
167
168 const Costmap3DBuilderParams builderParameters;
169
170 Eigen::Isometry2f root_T_used_root_2d = Eigen::Isometry2f::Identity();
171 };
172
173} // namespace armarx::navigation::algorithms::orientation_aware
#define float
Definition 16_Level.h:22
constexpr T c
static Eigen::MatrixXf createUniformGridSingleOrientation(const SceneBounds &sceneBounds, const Costmap3D::Parameters &parameters)
Costmap3D create(const SceneBounds &init=SceneBounds())
Costmap3DBuilder(const VirtualRobot::RobotPtr &robot, const VirtualRobot::SceneObjectSetPtr &obstacles, const std::vector< VirtualRobot::RobotPtr > &articulatedObjects, const std::vector< Room > &rooms, const Costmap3D::Parameters &parameters, const std::string &robotCollisonModelName, const Costmap3DBuilderParams &builderParameters)
static Costmap3D::Grid createUniformGrid(const SceneBounds &sceneBounds, const Costmap3D::Parameters &parameters)
Brief description of class rooms.
Definition rooms.h:39
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
Eigen::Isometry2f Pose2D
Definition basic_types.h:34
boost::geometry::model::polygon< point_type > polygon_type
Definition geometry.h:36