Smoothing.cpp
Go to the documentation of this file.
1#include "Smoothing.h"
2
3#include <iomanip>
4#include <ios>
5#include <vector>
6
7#include <Eigen/Geometry>
8
11
17
19{
21 const Costmap3D& costmap3d,
22 const Params& params) :
23 trajectory(trajectory), costmap3d(costmap3d), params(params)
24 {
25 }
26
27 // convert back to global trajectory
29 toGlobalTrajectory(const std::vector<CenterPoint>& traj)
30 {
32 for (const auto& p : traj)
33 {
35 gp.waypoint.pose =
36 Eigen::Translation3f{Eigen::Vector3f(p.x, p.y, 0.0)} *
37 Eigen::AngleAxisf{static_cast<float>(p.theta), Eigen::Vector3f::UnitZ()};
38 gp.velocity = 200;
39 gtraj.mutablePoints().push_back(gp);
40 }
41 return gtraj;
42 }
43
44 // convert global trajectory to trajectory for smoothing
45 std::vector<CenterPoint>
47 {
48 std::vector<CenterPoint> traj;
49 for (const auto& gp : gtraj.points())
50 {
52 p.x = gp.waypoint.pose.translation().x();
53 p.y = gp.waypoint.pose.translation().y();
54 p.theta = gp.waypoint.pose.rotation().eulerAngles(0, 1, 2)[2];
55 p.v = gp.velocity;
56 traj.push_back(p);
57 }
58 return traj;
59 }
60
61 Smoothing::OptimizationResult
63 {
64 Costmap3DWrapper costmapWrapper{costmap3d};
65
66 // Convert trajectory (currently only a shortcut - not the correct trajectory is used)
67 std::vector<CenterPoint> traj;
68 std::vector<CenterPoint> traj_orig;
69 {
70 traj = toCenterTrajectory(trajectory);
71 traj_orig = traj;
72 }
73
74 optimizeTrajectoryCeres(traj, costmapWrapper, traj_orig, params);
75
76 for (int i = 0; i < static_cast<int>(traj.size()); ++i)
77 {
78 ARMARX_DEBUG << std::fixed << std::setprecision(3) << "i=" << i << " : x=" << traj[i].x
79 << " y=" << traj[i].y << " theta=" << traj[i].theta << " v=" << traj[i].v;
80 }
81
82 return {.trajectory = toGlobalTrajectory(traj)};
83 }
84
85 std::vector<core::GlobalTrajectoryPoint>
87 {
88 std::vector<core::GlobalTrajectoryPoint> collisionPoints;
89 for (const auto& p : centerTrajectory.points())
90 {
91 bool inCollision = costmap3d.isInCollision(
92 conv::to2D(p.waypoint.pose.translation()),
93 costmap3d.closestRotationFromDegrees(
94 costmap3d.rotationDegrees(conv::to2D(p.waypoint.pose))));
95 if (inCollision)
96 {
97 ARMARX_INFO << "Collision detected at position "
98 << VAROUT(conv::to2D(p.waypoint.pose).translation());
99 collisionPoints.push_back(p);
100 }
101 }
102 ARMARX_INFO << "Trajectory is "
103 << (collisionPoints.empty() ? "collision-free." : "in collision!");
104 return collisionPoints;
105 }
106
107
108} // namespace armarx::navigation::algorithms::orientation_aware::smoothing
#define VAROUT(x)
Smoothing(const core::GlobalTrajectory &trajectory, const Costmap3D &costmap3d, const Params &params)
Definition Smoothing.cpp:20
std::vector< core::GlobalTrajectoryPoint > checkCenterTrajectory(core::GlobalTrajectory &centerTrajectory) const
Definition Smoothing.cpp:86
const std::vector< GlobalTrajectoryPoint > & points() const
std::vector< GlobalTrajectoryPoint > & mutablePoints()
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
std::vector< CenterPoint > toCenterTrajectory(const armarx::navigation::core::GlobalTrajectory &gtraj)
Definition Smoothing.cpp:46
armarx::navigation::core::GlobalTrajectory toGlobalTrajectory(const std::vector< CenterPoint > &traj)
Definition Smoothing.cpp:29
void optimizeTrajectoryCeres(std::vector< CenterPoint > &traj, const Costmap3DWrapper &costmap_wrapper, const std::vector< CenterPoint > &traj_original, const io::SmoothingParams &opts)
Definition residuals.h:375
std::vector< Eigen::Vector2f > to2D(const std::vector< Eigen::Vector3f > &v)
Definition eigen.cpp:29