Bench-MR
A Motion Planning Benchmark for Wheeled Mobile Robots
AOLMetric.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <iostream>
5#include <limits>
6#include <vector>
7
9#include "base/Primitives.h"
13
14#include <ompl/geometric/PathGeometric.h>
15#include <ompl/control/PathControl.h>
16
17#if QT_SUPPORT
18#include "gui/QtVisualizer.h"
19#endif
20
21class AOLMetric : public TMetric<AOLMetric> {
22 public:
36 static inline double max_curvature = std::numeric_limits<double>::max();
37
38 static double evMetric(const std::vector<Point>& path,
39 bool visualize = false) {
40 double path_length = PlannerUtils::totalLength(path);
41 double total_yaw_change = 0;
42
43 auto prev = path.begin();
44 auto current = prev;
45 auto next = prev;
46 while (next != path.end()) {
47 // advance until current point != prev point, i.e., skip duplicates
48 if (prev->distance(*current) <= 0) {
49 ++current;
50 ++next;
51 }
52 else if (current->distance(*next) <= 0) {
53 ++next;
54 }
55 else {
56 const double yaw_prev = PlannerUtils::slope(*prev, *current);
57 const double yaw_next = PlannerUtils::slope(*current, *next);
58
59 // compute angle difference in [0, pi)
60 // close to pi -> cusp; 0 -> straight line; inbetween -> curve
61 const double yaw_change =
62 std::abs(PlannerUtils::normalizeAngle(yaw_next - yaw_prev));
63
64 // both in [-pi, pi]
65 /* std::cout << yaw_prev << " " << yaw_next << " " << yaw_change << std::endl; */
66
67 total_yaw_change += yaw_change;
68
69 prev = current;
70 current = next;
71 ++next;
72 }
73 }
74
75 return total_yaw_change / path_length;
76 }
77
78 static double evaluateMetric(const ompl::geometric::PathGeometric& trajectory,
79 double, bool visualize = false) {
80 const auto path = Point::fromPath(trajectory);
81 return evMetric(path, visualize);
82 }
83
84 static double evaluateMetric(const ompl::control::PathControl& trajectory,
85 double, bool visualize = false) {
86 const auto path = Point::fromPath(trajectory);
87 return evMetric(path, visualize);
88 }
89
90 static const bool MoreIsBetter = false;
91
92 private:
93 static double distance(double x1, double y1, double x2, double y2) {
94 return std::sqrt(std::pow(x2 - x1, 2.) + std::pow(y2 - y1, 2.));
95 }
96};
Definition: AOLMetric.h:21
static double totalLength(const std::vector< Point > &path)
Compute total length of a path.
Definition: PlannerUtils.hpp:499
static double slope(const N &x1, const N &y1, const N &x2, const N &y2)
Compute the angular slope between two points.
Definition: PlannerUtils.hpp:39
static double normalizeAngle(double angle)
Normalize angle in radians to the interval .
Definition: PlannerUtils.hpp:572
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