6#include "../base/PlannerSettings.h"
20 static double evMetric(std::vector<Point> path,
bool visualize =
false) {
21 double x1, x2, x3, y1, y2, y3, v1x, v2x, v1y, v2y, v1, v2;
25 size_t traj_size = path.size();
34 if (traj_size < 3)
return 0;
38 for (
int i = 0; i < (traj_size - 2); i++) {
46 if (i >= path.size())
return maxK;
49 }
while (distance(x1, y1, x2, y2) < 0.3);
53 if (i >= path.size())
return maxK;
56 }
while (distance(x2, y2, x3, y3) < 0.3);
59 if (x1 == x2 && y1 == y2 || x2 == x3 && y2 == y3)
continue;
63 if (x1 == x3 && y1 == y3) {
64 OMPL_WARN(
"Undefined curvature. Skipping three steps...");
70 (std::pow(x3, 2.) * (-y1 + y2) + std::pow(x2, 2.) * (y1 - y3) -
71 (std::pow(x1, 2.) + (y1 - y2) * (y1 - y3)) * (y2 - y3)) /
72 (2. * (x3 * (-y1 + y2) + x2 * (y1 - y3) + x1 * (-y2 + y3)));
74 (-(std::pow(x2, 2.) * x3) + std::pow(x1, 2.) * (-x2 + x3) +
75 x3 * (std::pow(y1, 2.) - std::pow(y2, 2.)) +
76 x1 * (std::pow(x2, 2.) - std::pow(x3, 2.) + std::pow(y2, 2.) -
78 x2 * (std::pow(x3, 2.) - std::pow(y1, 2.) + std::pow(y3, 2.))) /
79 (2. * (x3 * (y1 - y2) + x1 * (y2 - y3) + x2 * (-y1 + y3)));
82 double radius = std::sqrt(std::pow(x1 - cx, 2.) + std::pow(y1 - cy, 2.));
83 double ki = 1. / radius;
87 if (visualize && ki > 0.5) {
89 x1, y1, QColor(255,
std::max(0, (
int)(255 - ki * 10)), 0, 50), .8);
91 x2, y2, QColor(255,
std::max(0, (
int)(255 - ki * 10)), 0, 50), .8);
93 x3, y3, QColor(255,
std::max(0, (
int)(255 - ki * 10)), 0, 50), .8);
98 if (ki > maxK) maxK = ki;
110 double,
bool visualize =
false) {
122 double,
bool visualize =
false) {
129 std::vector<double> traj_y) {
130 double x1, x2, x3, y1, y2, y3, v1x, v2x, v1y, v2y, v1, v2, k_i;
134 size_t traj_size = traj_x.size();
137 if (traj_size == 0) {
143 if (traj_size < 3)
return 0;
147 for (
int i = 0; i < (traj_size - 2); i++) {
157 if (x1 == x2 && y1 == y2 || x2 == x3 && y2 == y3)
continue;
161 if (x1 == x3 && y1 == y3) {
162 OMPL_WARN(
"Undefined curvature. Skipping three steps...");
171 v1 = sqrt(v1x * v1x + v1y * v1y);
172 v2 = sqrt(v2x * v2x + v2y * v2y);
173 v1x = (0.5 * v1x * (v1 + v2)) / v1;
174 v1y = (0.5 * v1y * (v1 + v2)) / v1;
175 v2x = (0.5 * v2x * (v1 + v2)) / v2;
176 v2y = (0.5 * v2y * (v1 + v2)) / v2;
184 k_i = 2 * fabs((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) /
185 (sqrt(((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) *
186 ((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1)) *
187 ((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2))));
189 if (k_i > maxK) maxK = k_i;
198 static double distance(
double x1,
double y1,
double x2,
double y2) {
199 return std::sqrt(std::pow(x2 - x1, 2.) + std::pow(y2 - y1, 2.));
Definition: MaxCurvatureMetric.h:13
static double evaluateMetric(const ompl::control::PathControl &trajectory, double, bool visualize=false)
Computes the maximum curvature of the given trajectory.
Definition: MaxCurvatureMetric.h:121
static const bool MoreIsBetter
Definition: MaxCurvatureMetric.h:195
static double evMetric(std::vector< Point > path, bool visualize=false)
Computes the maximum curvature of the given trajectory.
Definition: MaxCurvatureMetric.h:20
static double evaluateMetric(const ompl::geometric::PathGeometric &trajectory, double, bool visualize=false)
Computes the maximum curvature of the given trajectory.
Definition: MaxCurvatureMetric.h:109
static double evaluateMetric(std::vector< double > traj_x, std::vector< double > traj_y)
Definition: MaxCurvatureMetric.h:128
static void drawNode(const ompl::base::State *state, const QColor &color=Qt::red, double radius=0.3, bool drawArrow=true)
Definition: QtVisualizer.cpp:147
Definition: TrajectoryMetric.h:10
double max(const std::vector< double > &values)
Definition: PathStatistics.hpp:79
static std::vector< Point > fromPath(const ompl::geometric::PathGeometric &p, bool interpolate=false)
Definition: Primitives.cpp:25