LaserBasedProximity.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 Fabian Reister ( fabian dot reister at kit dot edu )
17 * @author Christian R. G. Dreher ( c dot dreher at kit dot edu )
18 * @date 2021
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <cstdint>
26#include <optional>
27
28#include <boost/circular_buffer.hpp>
29
30#include <SimoxUtility/color/ColorMap.h>
31
36
37#include "SafetyGuard.h"
38
39namespace armarx::viz
40{
41 struct Layer;
42}
43
45{
46
48 {
49 enum class Mode : std::uint8_t
50 {
54 };
55
57
58 float safetyDistance{500.F};
59 float influenceDistance{2000.F};
60
61 // if enabled, reduce the velocity between safetyDistance and influenceDistance. If false, the robot will move with maximum velocity until it has to stop at safetyDistance.
62 bool reduceVelocity{true};
63
64 // Parameters to reduce the velocity in proximity to an obstacle between minDistance and maxDistance.
65 // It is v = v_max / (1 + lambda * d_s^lambda) with d_s = (1 - (d / maxDistance))^k
66 float k{4.F};
67 float lambda{6.F};
68 };
69
70 /// Why a laser scanner feature does not constrain the velocity.
71 enum class FilterReason : std::uint8_t
72 {
73 /// The feature constrains, or is a candidate to constrain, the velocity.
75
76 /// The feature has no points.
78
79 /// The feature lies fully inside one of the ignored regions.
81
82 /// The feature lies fully inside the inflated OOBB of an attached object.
84
85 /// Small feature close to the robot, most likely a measuring artifact of the sensor.
87
88 /// The feature is outside the influence distance.
90
91 /// The robot is moving away from the feature.
93
94 /// The robot passes the feature exactly tangentially.
96 };
97
99 {
100 float robotRadius{500.F}; //TODO(utetg): should there be a default, if yes what
101
102 bool enableHumans{true};
104
107
108 // any laser scanner feature that lies **fully** inside any of these regions will be ignored
109 std::vector<Eigen::AlignedBox2f> ignoredRegions;
110
111 float attachedObjectsInflation = 200; // [mm]
112
113 // any laser scanner feature that lies **fully** inside the OOBB of the attached object will be ignored
115
116 // Whether to filter out small laser scanner features close to the robot
117 // These can appear due to measuring errors of the sensors
119 // features with <= this number of points are ignored
121 // [mm]; only filter features where all points are within this distance from the robot
123
124 Algorithms algorithm() const override;
125 aron::data::DictPtr toAron() const override;
127 };
128
129 class LaserBasedProximity : virtual public SafetyGuard
130 {
131 public:
133
135 const core::GeneralConfig& generalConfig,
136 const core::Scene& scene,
137 const Context& ctx);
138 ~LaserBasedProximity() override = default;
139
140 SafetyGuardResult computeSafetyLimits(const Eigen::Vector2f& global_V_movement) override;
141
142 private:
143 struct DistanceAndClosestPoint
144 {
145 float distance;
146 Eigen::Vector2f closestPoint;
147
148 std::size_t clusterSize;
149
150 /// Centroid of the feature in the global frame. Only used for debug visualization.
151 Eigen::Vector2f centroid;
152
153 /// Why this feature does not constrain the velocity.
154 FilterReason filterReason;
155 };
156
157 std::optional<core::TwistLimits> safetyLimitsHumans(viz::Layer& layer) const;
158 std::optional<core::TwistLimits>
159 safetyLimitsLaserScanners(viz::Layer& layer,
160 viz::Layer& clusterLayer,
161 viz::Layer& filteredLayer,
162 const Eigen::Vector2f& global_V_movement) const;
163
164 DistanceAndClosestPoint
165 calculateMinDistance(const util::geometry::polygon_type& convexHull,
166 const core::Pose& robot_T_global,
167 const std::vector<Eigen::Vector3f>& globalPoints) const;
168
169 std::pair<core::TwistLimits, float>
170 evaluateProximityField(const ProximityFieldParams& proximityField, float minDistance) const;
171
173 featureIgnoreReason(const std::vector<Eigen::Vector3f>& featurePoints3DGlobal,
174 const std::vector<Eigen::Vector2f>& featurePoints2DGlobal,
175 const Eigen::Vector2f& centroid) const;
176
177 struct InternalVelocityLimitResult
178 {
179 core::TwistLimits twistLimits;
180 std::optional<float> minDistance;
181
182 // not necessarily the closest point according to the Euclidean distance, but the point that leads to the calculated safety limits
183 std::optional<Eigen::Vector2f> closestPoint;
184 };
185
186 /// Annotates `minDistanceToObstacles` with the reason why each feature does (not)
187 /// constrain the velocity.
188 InternalVelocityLimitResult
189 velocityLimitsDirectionDependent(const Eigen::Vector2f& global_V_movement,
190 std::vector<DistanceAndClosestPoint>& minDistanceToObstacles,
191 const Eigen::Isometry3f& global_T_robot) const;
192
193 InternalVelocityLimitResult velocityLimitsDirectionIndependent(
194 const std::vector<DistanceAndClosestPoint>& minDistanceToObstacles) const;
195
196
197 protected:
199
200 private:
201 core::GeneralConfig generalConfig;
202
203 simox::ColorMap humanColorMap_;
204 simox::ColorMap laserColorMap_;
205
206 mutable boost::circular_buffer<std::vector<memory::LaserScannerFeatures>>
207 laserScannerFeatureHistory_{5};
208 };
209} // namespace armarx::navigation::safety_guard
SafetyGuardResult computeSafetyLimits(const Eigen::Vector2f &global_V_movement) override
LaserBasedProximity(const Params &params, const core::GeneralConfig &generalConfig, const core::Scene &scene, const Context &ctx)
SafetyGuard(const core::Scene &scene, const Context &ctx)
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
Eigen::Isometry3f Pose
Definition basic_types.h:31
This file is part of ArmarX.
Definition fwd.h:55
FilterReason
Why a laser scanner feature does not constrain the velocity.
@ TooFarAway
The feature is outside the influence distance.
@ MovingAway
The robot is moving away from the feature.
@ None
The feature constrains, or is a candidate to constrain, the velocity.
@ NearFieldArtifact
Small feature close to the robot, most likely a measuring artifact of the sensor.
@ AttachedObject
The feature lies fully inside the inflated OOBB of an attached object.
@ IgnoredRegion
The feature lies fully inside one of the ignored regions.
@ Tangential
The robot passes the feature exactly tangentially.
boost::geometry::model::polygon< point_type > polygon_type
Definition geometry.h:36
This file is part of ArmarX.
double distance(const Point &a, const Point &b)
Definition point.hpp:95
static LaserBasedProximityParams FromAron(const aron::data::DictPtr &dict)