28#include <ceres/ceres.h>
30#if CERES_VERSION_MAJOR >= 2 && CERES_VERSION_MINOR >= 1
31# include <ceres/manifold.h>
33# define SET_CONSTRAINT(problem, param, constraint) \
34 (problem).SetManifold((param), (constraint))
36# include <ceres/local_parameterization.h>
38# define SET_CONSTRAINT(problem, param, constraint) \
39 (problem).SetParameterization((param), (constraint))
51 return std::atan2(std::sin(a), std::cos(a));
54 static void normalizeTrajectoryAngles(std::vector<CenterPoint>& traj)
70 const T*
const c_next,
73 residual[0] =
T(
w) * (c_prev[0] -
T(2.0) * c_i[0] + c_next[0]);
74 residual[1] =
T(
w) * (c_prev[1] -
T(2.0) * c_i[1] + c_next[1]);
82 inline double smoothstep(
double edge0,
double edge1,
double x)
93 const double t = (
x - edge0) / (edge1 - edge0);
94 return t * t * (3.0 - 2.0 * t);
110 double fadeStartClearance,
111 double fadeEndClearance)
113 return 1.0 -
smoothstep(fadeStartClearance, fadeEndClearance, clearance);
154 template <
typename T>
157 const double max_dist,
158 const double clearance)
162 if (!ceres::isfinite(d_raw))
164 return T(weight) *
T(100.0);
170 const T min_allowed =
T(-3.0 * max_dist);
176 const T t = (d -
T(clearance)) /
T(max_dist);
183 const T u =
T(1.0) - t;
184 return T(weight) * u * u;
203 template <
typename T>
207 wrapper_(&node[0], &node[1], &d_raw);
232 template <
typename T>
233 bool operator()(
const T*
const c_i,
const T*
const c_ip1,
T* residual)
const
235 T mx = (c_i[0] + c_ip1[0]) /
T(2.0);
236 T my = (c_i[1] + c_ip1[1]) /
T(2.0);
268 template <
typename T>
269 bool operator()(
const T*
const c_i,
const T*
const c_ip1,
T* residual)
const
271 T sx = (
T(1.0) -
T(
t_)) * c_i[0] +
T(
t_) * c_ip1[0];
272 T sy = (
T(1.0) -
T(
t_)) * c_i[1] +
T(
t_) * c_ip1[1];
304 double max_deviation,
316 template <
typename T>
319 T dx = c_i[0] -
T(
xr_);
320 T dy = c_i[1] -
T(
yr_);
321 T d = ceres::sqrt(dx * dx + dy * dy +
T(1e-6));
355 template <
typename T>
358 residual[0] =
T(
w_) * (c_i[0] -
T(
xr_));
359 residual[1] =
T(
w_) * (c_i[1] -
T(
yr_));
374 template <
typename T>
375 bool operator()(
const T*
const c_i,
const T*
const c_ip1,
T* residual)
const
377 T dx = c_ip1[0] - c_i[0];
378 T dy = c_ip1[1] - c_i[1];
379 T dist_sq = dx * dx + dy * dy;
381 residual[0] =
T(
w) * (dist_sq - target_sq);
394 return std::hypot(b.
x - a.x, b.
y - a.y);
397 static double computeAverageSpacing(
const std::vector<CenterPoint>& traj)
402 for (
size_t i = 0; i + 1 < traj.size(); ++i)
403 sum += segment_length(traj[i], traj[i + 1]);
404 return sum / double(traj.size() - 1);
Differentiable wrapper around the standard 2-D distance-to-obstacle costmap.
This file is part of ArmarX.
double smoothstep(double edge0, double edge1, double x)
Hermite smoothstep: 0 below edge0, 1 above edge1, C1 at both ends.
double normalizeAngle(double a)
T obstacleBarrier(const T &d_raw, const double weight, const double max_dist, const double clearance)
Obstacle cost: a single parabola in the distance to the nearest obstacle.
double trackingScaleFromClearance(double clearance, double fadeStartClearance, double fadeEndClearance)
Scale for the tracking weight, from the clearance at a waypoint's reference position.
This file offers overloads of toIce() and fromIce() functions for STL container types.
ceres::SubsetParameterization SubsetConstraint
This file is part of ArmarX.
BoundedTrackingResidual(double xr, double yr, double deadzone, double max_deviation, double w_in_bounds, double w_hard)
bool operator()(const T *const c_i, T *residual) const
MidpointObstacleResidual2D(const Costmap2DWrapper &wrapper, double weight, double max_dist, double clearance)
const Costmap2DWrapper & wrapper_
bool operator()(const T *const c_i, const T *const c_ip1, T *residual) const
const Costmap2DWrapper & wrapper_
bool operator()(const T *const node, T *residual) const
ObstacleResidual2D(const Costmap2DWrapper &wrapper, double weight, double max_dist, double clearance)
bool operator()(const T *const c_prev, const T *const c_i, const T *const c_next, T *residual) const
PositionSmoothResidual(double weight=1.0)
const Costmap2DWrapper & wrapper_
bool operator()(const T *const c_i, const T *const c_ip1, T *residual) const
SegmentObstacleResidual2D(const Costmap2DWrapper &wrapper, double weight, double max_dist, double clearance, double t)
SoftTrackingResidual(double xr, double yr, double weight)
bool operator()(const T *const c_i, T *residual) const
SpacingResidual(double d_avg, double weight)
bool operator()(const T *const c_i, const T *const c_ip1, T *residual) const