8#include <Eigen/Geometry>
26 trajectory(trajectory), costmap3d(costmap3d), params(params)
35 for (
const auto& p : traj)
40 Eigen::Vector3f(
static_cast<float>(p.x),
static_cast<float>(p.y), 0.0f)} *
41 Eigen::AngleAxisf{
static_cast<float>(p.theta), Eigen::Vector3f::UnitZ()};
42 gp.
velocity =
static_cast<float>(p.v);
49 std::vector<CenterPoint>
52 std::vector<CenterPoint> traj;
53 for (
const auto& gp : gtraj.
points())
56 p.
x = gp.waypoint.pose.translation().x();
57 p.
y = gp.waypoint.pose.translation().y();
58 const auto& R = gp.waypoint.pose.rotation();
59 p.
theta = std::atan2(R(1, 0), R(0, 0));
67 queryDistance(
const Costmap3DWrapper& wrapper,
double x,
double y,
double theta)
70 wrapper(&
x, &y, &theta, &out);
78 pushWaypointsToSafeZone(std::vector<CenterPoint>& traj,
79 const Costmap3DWrapper& wrapper,
86 const std::vector<std::pair<double, double>> neighbours = {
93 {stepSize, -stepSize},
94 {-stepSize, stepSize},
95 {-stepSize, -stepSize},
98 auto isInsideBounds = [&costmap](
double x,
double y) ->
bool
100 const auto local = costmap.origin().inverse() *
101 Eigen::Vector2f{
static_cast<float>(x),
static_cast<float>(y)};
102 const auto& bounds = costmap.getLocalSceneBounds();
103 return local.x() >= bounds.min.x() && local.x() <= bounds.max.x() &&
104 local.y() >= bounds.min.y() && local.y() <= bounds.max.y();
107 for (
int idx = 1; idx + 1 <
static_cast<int>(traj.size()); ++idx)
110 double bestDist = queryDistance(wrapper, p.x, p.y, p.theta);
112 if (bestDist >= clearance)
115 for (
int iter = 0; iter < maxIterations; ++iter)
119 bool improved =
false;
121 for (
const auto& [dx, dy] : neighbours)
123 double candX = p.x + dx;
124 double candY = p.y + dy;
125 if (!isInsideBounds(candX, candY))
127 double candDist = queryDistance(wrapper, candX, candY, p.theta);
128 if (candDist > bestDist)
146 if (bestDist >= clearance)
157 std::vector<CenterPoint> traj;
165 pushWaypointsToSafeZone(traj,
169 params.hill_climb_step_size,
170 params.hill_climb_max_iterations);
175 std::vector<CenterPoint> traj_targets = traj;
183 ARMARX_INFO <<
"Smoothed trajectory is collision-free.";
187 ARMARX_WARNING <<
"Smoothed trajectory still has collision after pre-processing.";
190 for (
int i = 0; i < static_cast<int>(traj.size()); ++i)
192 ARMARX_DEBUG << std::fixed << std::setprecision(3) <<
"i=" << i <<
" : x=" << traj[i].x
193 <<
" y=" << traj[i].y <<
" theta=" << traj[i].theta <<
" v=" << traj[i].v;
TrajectoryCollisionCheckResult check(const core::GlobalTrajectory &trajectory, bool logDetails=false) const
Smoothing(const core::GlobalTrajectory &trajectory, const Costmap3D &costmap3d, const Params ¶ms)
io::SmoothingParams Params
OptimizationResult optimize()
const std::vector< GlobalTrajectoryPoint > & points() const
std::vector< GlobalTrajectoryPoint > & mutablePoints()
#define ARMARX_INFO
The normal logging level.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
This file is part of ArmarX.
This file is part of ArmarX.
void optimizeTrajectoryCeres(std::vector< CenterPoint > &traj, const Costmap3DWrapper &costmap_wrapper, const std::vector< CenterPoint > &traj_targets, const io::SmoothingParams &opts)
std::vector< CenterPoint > toCenterTrajectory(const armarx::navigation::core::GlobalTrajectory >raj)
armarx::navigation::core::GlobalTrajectory toGlobalTrajectory(const std::vector< CenterPoint > &traj)
This file offers overloads of toIce() and fromIce() functions for STL container types.
bool isCollisionFree() const