ObstacleAwareVelocityLimit.cpp
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 * @date 2026
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
23
24#include <algorithm>
25#include <cmath>
26
27#include <range/v3/range/conversion.hpp>
28#include <range/v3/view/transform.hpp>
29
31
33{
34
36 const Parameters& params) :
37 costmap_(costmap), params_(params)
38 {
39 ARMARX_CHECK_GREATER(params_.obstacleMaxDistance, 0.F)
40 << "The obstacle distance the limit is normalized by must be positive.";
41 }
42
43 float
44 ObstacleAwareVelocityLimit::atDistance(const float obstacleDistance) const
45 {
46 const float clippedDistance =
47 std::clamp(obstacleDistance, 0.F, params_.obstacleMaxDistance);
48
49 const float proximity = std::pow(1.F - clippedDistance / params_.obstacleMaxDistance,
50 params_.obstacleCostExponent);
51
52 return params_.maxVelocity / (1.F + params_.obstacleDistanceWeight * proximity);
53 }
54
55 float
56 ObstacleAwareVelocityLimit::at(const Eigen::Vector2f& position) const
57 {
58 // A masked-out cell carries no distance information. Treating it as zero clearance is the
59 // conservative choice and matches what SPFA's final velocity clamp has always done.
60 return atDistance(costmap_.value(position).value_or(0.F));
61 }
62
63 std::vector<float>
65 {
66 const auto limitAt = [this](const core::Position& position) -> float
67 { return at(Eigen::Vector2f{position.head<2>()}); };
68
69 return positions | ranges::views::transform(limitAt) | ranges::to_vector;
70 }
71
74 {
75 return params_;
76 }
77
78} // namespace armarx::navigation::algorithms
ObstacleAwareVelocityLimit(const Costmap &costmap, const Parameters &params)
float at(const Eigen::Vector2f &position) const
The limit at a position in the costmap's global frame.
float atDistance(float obstacleDistance) const
The limit for a given distance to the closest obstacle [mm].
#define ARMARX_CHECK_GREATER(lhs, rhs)
This macro evaluates whether lhs is greater (>) than rhs and if it turns out to be false it will thro...
This file is part of ArmarX.
std::vector< Position > Positions
Definition basic_types.h:37
Eigen::Vector3f Position
Definition basic_types.h:36