Bench-MR
A Motion Planning Benchmark for Wheeled Mobile Robots
JerkMetric.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <vector>
5
6#include "../TrajectoryMetric.h"
7
8#pragma warning "The JerkMetric is not supported at the moment."
9
10#if 0
11class JerkMetric : public TMetric<JerkMetric> {
12 public:
13 static double evaluateMetric(const ompl::geometric::PathGeometric &trajectory,
14 double dt) {
16 double pjerk = 0;
17 double jerk_ = 0;
18 double Vmax = 100;
19 double T = 0;
20
21 double v_x[60000];
22 double v_y[60000];
23
24 double acc_x[60000];
25 double acc_y[60000];
26
27 double jerk_x[60000];
28 double jerk_y[60000];
29
30 int maxV = 0;
31 int j = 0;
32 unsigned long vsize = trajectory->getV().size();
33 double *vel = new double[vsize];
34 for (auto vi : trajectory->getV()) {
35 vel[j] = vi;
36 T += dt;
37 // cout<<"Vel_i: "<<vi<<endl;
38 j++;
39 }
40
41 for (int k = 0; k < vsize; k++) {
42 if (vel[k] > vel[maxV]) maxV = k;
43 }
44 Vmax = vel[maxV];
45
46 const auto path = Point::fromPath(trajectory);
47
48 if (path.size() > 3) {
49 for (std::size_t i = 0; i < path.size() - 1; i++) {
50 v_x[i] = (path[i + 1].x - path[i].x);
51 v_y[i] = (path[i + 1].y - path[i].y);
52 }
53
54 for (std::size_t i = 0; i < path.size() - 2; i++) {
55 acc_x[i] = (v_x[i + 1] - v_x[i]);
56 acc_y[i] = (v_y[i + 1] - v_y[i]);
57 }
58
61 for (std::size_t i = 1; i < path.size() - 3; i++) {
62 jerk_x[i] = (acc_x[i + 1] - acc_x[i - 1]) / (2 * dt);
63 jerk_y[i] = (acc_y[i + 1] - acc_y[i - 1]) / (2 * dt);
64 }
65
66 for (std::size_t i = 1; i < path.size() - 3; i++) {
67 pjerk += std::fabs(
68 std::sqrt(jerk_x[i] * jerk_x[i] + jerk_y[i] * jerk_y[i]) * dt);
69 }
70
71 jerk_ = -pjerk / (T * Vmax);
72 } else
73 jerk_ = 0;
74
75 // cout<<"DEBUG: jerk "<<jerk_<<endl;
76
77 // delete(vel);
78 delete[] vel;
79 return jerk_;
80 }
81
82 static const bool MoreIsBetter = false;
83};
84#endif
Definition: TrajectoryMetric.h:10
static std::vector< Point > fromPath(const ompl::geometric::PathGeometric &p, bool interpolate=false)
Definition: Primitives.cpp:25