-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcost_functors.hpp
70 lines (61 loc) · 1.64 KB
/
cost_functors.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <boost/geometry.hpp>
// puts cost on leaving a polygon
template <typename POINT_T, typename POLYGON_T>
struct PolygonCostFunctor
{
const POLYGON_T poly;
PolygonCostFunctor(const POLYGON_T &poly) : poly{poly}
{
}
bool operator()(const double *p0, double *residual) const
{
const POINT_T pt(p0[0], p0[1]);
bool is_inside = boost::geometry::within(pt, this->poly);
residual[0] = is_inside ? 0 : boost::geometry::distance(pt, this->poly);
return true;
}
};
// puts cost on deviation of desired flight height
struct ElevationCostFunctor
{
const double elevation_des;
ElevationCostFunctor(const double &elevation_des) : elevation_des{elevation_des}
{
}
template <typename T>
bool operator()(const T *const p0, T *residual) const
{
residual[0] = (T(elevation_des) - p0[1]);
return true;
}
};
// puts cost on acceleration
struct AccCostFunctor
{
AccCostFunctor() {}
template <typename T>
bool operator()(const T *const p0, const T *const p1, const T *const p2, T *residual) const
{
for (int i = 0; i < 2; ++i)
{
residual[i] = p0[i] - T(2) * p1[i] + p2[i];
}
return true;
}
};
// puts cost on jerk
struct JerkCostFunctor
{
JerkCostFunctor() {}
template <typename T>
bool operator()(const T *const p0, const T *const p1,
const T *const p2, const T *const p3,
T *residual) const
{
for (int i = 0; i < 2; ++i)
{
residual[i] = (-p0[i] + T(3) * p1[i] - T(3) * p2[i] + p3[i]);
}
return true;
}
};