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 * Robot footprint radius in mm. Only applicable when restrictToRooms is true.
62 * When >= 0, cells closer than this distance to a room boundary are excluded.
63 * -1 disables the footprint restriction.
64 */
66
67 /*!
68 * The maximum distance from the costmap to an obstacle to be included for costmap
69 * calculation. Every obstacles further away will be discarded.
70 */
71 float maxFilterDistance = 1000.F;
72
73
74 Eigen::Vector3f collisionModelScaleFactor = Eigen::Vector3f::Ones();
75 bool approximation2D = false;
76 float approx2DignoreVerticesOver = 2000.F; // [mm]
77 float obstacleSafetyMargin = 15.F; // [mm]
78
79 std::set<std::string> primitiveApproximationIDs;
80 };
81
83 const VirtualRobot::SceneObjectSetPtr& obstacles,
84 const std::vector<VirtualRobot::RobotPtr>& articulatedObjects,
85 const std::vector<Room>& rooms,
86 const Costmap3D::Parameters& parameters,
87 const std::string& robotCollisonModelName,
88 const Costmap3DBuilderParams& builderParameters);
89
90 Costmap3D create(const SceneBounds& init = SceneBounds());
91
92 // Extend costmap from laser scanners / cartographer
94
95
96 static Costmap3D::Grid createUniformGrid(const SceneBounds& sceneBounds,
97 const Costmap3D::Parameters& parameters);
98
99 static Eigen::MatrixXf
101 const Costmap3D::Parameters& parameters);
102
103 static void initializeMask(Costmap3D& costmap);
104
106 {
109
110 Eigen::Isometry2f root_T_used_root_2d = Eigen::Isometry2f::Identity();
111 };
112
113 std::optional<DebugOutput2D> getDebugOutput2D();
114
115 private:
116 using CollisionPolygon = util::geometry::polygon_type;
117
118 float computeCost(const core::Pose2D& pose2d, const Robot2D& robot2d, const Scene2D& scene);
119
120 Costmap3D inflateRotationDimension(Costmap& costmap);
121
122 void fillGridCosts2D(Costmap3D& costmap);
123 void fillGridCosts(Costmap3D& costmap);
124 void extendGridCosts(Costmap3D& costmap, const std::vector<Room>& rooms);
125
126 VirtualRobot::SceneObjectSetPtr filterObjectsForCostmap(const Costmap3D& costmap);
127
128 // fn: collisionRobot, robotCollisionModel, mask, costs, index -> costs
129 // expects mask calculation based on costs after this function
130
131 struct MapStructCommon
132 {
133 std::optional<float> maskOpt;
134 float cost;
135 const Costmap3D::Index& posIdx;
137
138 bool
139 isMaskedOut() const
140 {
141 return maskOpt.has_value() and not maskOpt.value();
142 }
143 };
144
145 struct MapStruct
146 {
147 MapStructCommon c;
148 DistanceCalculator distanceCalculator;
149 };
150
151 struct MapStructRobot2D
152 {
153 MapStructCommon c;
154 Robot2D robot;
155 Scene2D scene;
156 };
157
158 std::optional<DebugOutput2D> debugOutput2D;
159
160 using MapFn = std::function<float(const MapStruct&)>;
161 using MapFnRobot2D = std::function<float(const MapStructRobot2D&)>;
162 void applyFnToCostmap(Costmap3D& costmap, const MapFn& fn);
163 void applyFnToCostmap(Costmap3D& costmap, const MapFnRobot2D& fn);
164
165 void initializeEmptyMask(Costmap3D& costmap);
166
167 const VirtualRobot::RobotPtr robot;
168 const VirtualRobot::SceneObjectSetPtr obstacles;
169 VirtualRobot::SceneObjectSetPtr filteredObstacles;
170 const std::vector<VirtualRobot::RobotPtr> articulatedObjects;
171 std::vector<Room> rooms;
172 const Costmap3D::Parameters parameters;
173 const std::string robotCollisionModelName;
174
175 const Costmap3DBuilderParams builderParameters;
176
177 Eigen::Isometry2f root_T_used_root_2d = Eigen::Isometry2f::Identity();
178 };
179
180} // 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