Skip to content

Commit 011c1ae

Browse files
committed
Reformat.
1 parent ece8c85 commit 011c1ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1365
-1536
lines changed

motion_primitive_library

mpl_external_planner/include/mpl_external_planner/ellipsoid_planner/ellipsoid_planner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace MPL {
1515
* @brief Motion primitive planner using point cloud
1616
*/
1717
class EllipsoidPlanner : public PlannerBase<3, Waypoint3D> {
18-
public:
18+
public:
1919
/**
2020
* @brief Simple constructor
2121
* @param verbose enable print out
@@ -32,6 +32,6 @@ class EllipsoidPlanner : public PlannerBase<3, Waypoint3D> {
3232
ENV_.reset(new MPL::env_cloud(obs, r, ori, dim));
3333
}
3434
};
35-
}
35+
} // namespace MPL
3636

3737
#endif

mpl_external_planner/include/mpl_external_planner/ellipsoid_planner/ellipsoid_util.h

Lines changed: 83 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#ifndef MPL_ELLIPSOID_UTIL_H
66
#define MPL_ELLIPSOID_UTIL_H
77
#include <mpl_external_planner/ellipsoid_planner/primitive_ellipsoid_utils.h>
8-
98
#include <pcl/kdtree/kdtree_flann.h>
9+
1010
#include <boost/make_shared.hpp>
1111

1212
typedef pcl::PointXYZ PCLPoint;
@@ -18,97 +18,99 @@ typedef pcl::KdTreeFLANN<PCLPoint> KDTree;
1818
*
1919
*/
2020
class EllipsoidUtil {
21-
public:
22-
/**
23-
* @brief Simple constructor
24-
* @param r robot radius
25-
* @param h robot height, default as 0.1m
26-
*/
27-
EllipsoidUtil(decimal_t r, decimal_t h = 0.1) { axe_ = Vec3f(r, r, h); }
28-
29-
///Set obstacles
30-
void setObstacles(const vec_Vec3f& obs) {
31-
obs_.clear();
32-
for (const auto &it : obs) {
33-
if (bbox_.inside(it))
34-
obs_.push_back(it);
35-
}
21+
public:
22+
/**
23+
* @brief Simple constructor
24+
* @param r robot radius
25+
* @param h robot height, default as 0.1m
26+
*/
27+
EllipsoidUtil(decimal_t r, decimal_t h = 0.1) { axe_ = Vec3f(r, r, h); }
3628

37-
PCLPointCloud::Ptr cloud_ptr = boost::make_shared<PCLPointCloud>(toPCL(obs_));
38-
kdtree_.setInputCloud(cloud_ptr);
39-
}
40-
///Set bounding box
41-
void setBoundingBox(const Vec3f& ori, const Vec3f& dim) {
42-
Polyhedron3D Vs;
43-
Vs.add(Hyperplane3D(ori + Vec3f(0, dim(1) / 2, dim(2) / 2), -Vec3f::UnitX()));
44-
Vs.add(Hyperplane3D(ori + Vec3f(dim(0) / 2, 0, dim(2) / 2), -Vec3f::UnitY()));
45-
Vs.add(Hyperplane3D(ori + Vec3f(dim(0) / 2, dim(2) / 2, 0), -Vec3f::UnitZ()));
46-
Vs.add(Hyperplane3D(ori + dim - Vec3f(0, dim(1) / 2, dim(2) / 2), Vec3f::UnitX()));
47-
Vs.add(Hyperplane3D(ori + dim - Vec3f(dim(0) / 2, 0, dim(2) / 2), Vec3f::UnitY()));
48-
Vs.add(Hyperplane3D(ori + dim - Vec3f(dim(0) / 2, dim(1) / 2, 0), Vec3f::UnitZ()));
49-
bbox_ = Vs;
29+
/// Set obstacles
30+
void setObstacles(const vec_Vec3f &obs) {
31+
obs_.clear();
32+
for (const auto &it : obs) {
33+
if (bbox_.inside(it)) obs_.push_back(it);
5034
}
5135

52-
///Get polyhedra
53-
Polyhedron3D getBoundingBox() const {
54-
return bbox_;
55-
}
36+
PCLPointCloud::Ptr cloud_ptr =
37+
boost::make_shared<PCLPointCloud>(toPCL(obs_));
38+
kdtree_.setInputCloud(cloud_ptr);
39+
}
40+
/// Set bounding box
41+
void setBoundingBox(const Vec3f &ori, const Vec3f &dim) {
42+
Polyhedron3D Vs;
43+
Vs.add(
44+
Hyperplane3D(ori + Vec3f(0, dim(1) / 2, dim(2) / 2), -Vec3f::UnitX()));
45+
Vs.add(
46+
Hyperplane3D(ori + Vec3f(dim(0) / 2, 0, dim(2) / 2), -Vec3f::UnitY()));
47+
Vs.add(
48+
Hyperplane3D(ori + Vec3f(dim(0) / 2, dim(2) / 2, 0), -Vec3f::UnitZ()));
49+
Vs.add(Hyperplane3D(ori + dim - Vec3f(0, dim(1) / 2, dim(2) / 2),
50+
Vec3f::UnitX()));
51+
Vs.add(Hyperplane3D(ori + dim - Vec3f(dim(0) / 2, 0, dim(2) / 2),
52+
Vec3f::UnitY()));
53+
Vs.add(Hyperplane3D(ori + dim - Vec3f(dim(0) / 2, dim(1) / 2, 0),
54+
Vec3f::UnitZ()));
55+
bbox_ = Vs;
56+
}
5657

57-
///Check if a primitive is inside the SFC from \f$t: 0 \rightarrow dt\f$
58-
bool isFree(const Primitive3D &pr) {
59-
vec_E<Waypoint3D> ps = pr.sample(2);
60-
for (const auto &it : ps) {
61-
if (!bbox_.inside(it.pos))
62-
return false;
63-
}
64-
decimal_t max_v =
58+
/// Get polyhedra
59+
Polyhedron3D getBoundingBox() const { return bbox_; }
60+
61+
/// Check if a primitive is inside the SFC from \f$t: 0 \rightarrow dt\f$
62+
bool isFree(const Primitive3D &pr) {
63+
vec_E<Waypoint3D> ps = pr.sample(2);
64+
for (const auto &it : ps) {
65+
if (!bbox_.inside(it.pos)) return false;
66+
}
67+
decimal_t max_v =
6568
std::max(std::max(pr.max_vel(0), pr.max_vel(1)), pr.max_vel(2));
66-
int n = std::ceil(max_v * pr.t() / axe_(0));
67-
auto Es = sample_ellipsoids(pr, axe_, n);
69+
int n = std::ceil(max_v * pr.t() / axe_(0));
70+
auto Es = sample_ellipsoids(pr, axe_, n);
6871

69-
for (const auto &E : Es) {
70-
float radius = axe_(0);
71-
pcl::PointXYZ searchPoint;
72-
std::vector<int> pointIdxRadiusSearch;
73-
std::vector<float> pointRadiusSquaredDistance;
72+
for (const auto &E : Es) {
73+
float radius = axe_(0);
74+
pcl::PointXYZ searchPoint;
75+
std::vector<int> pointIdxRadiusSearch;
76+
std::vector<float> pointRadiusSquaredDistance;
7477

75-
searchPoint.x = E.d()(0);
76-
searchPoint.y = E.d()(1);
77-
searchPoint.z = E.d()(2);
78+
searchPoint.x = E.d()(0);
79+
searchPoint.y = E.d()(1);
80+
searchPoint.z = E.d()(2);
7881

79-
if (kdtree_.radiusSearch(searchPoint, radius, pointIdxRadiusSearch,
80-
pointRadiusSquaredDistance) > 0) {
81-
for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i)
82-
if(E.inside(Vec3f(obs_[pointIdxRadiusSearch[i]])))
83-
return false;
84-
}
82+
if (kdtree_.radiusSearch(searchPoint, radius, pointIdxRadiusSearch,
83+
pointRadiusSquaredDistance) > 0) {
84+
for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i)
85+
if (E.inside(Vec3f(obs_[pointIdxRadiusSearch[i]]))) return false;
8586
}
86-
87-
return true;
8887
}
89-
///Convert obstacle points into pcl point cloud
90-
PCLPointCloud toPCL(const vec_Vec3f &obs) {
91-
PCLPointCloud cloud;
92-
cloud.width = obs.size();
93-
cloud.height = 1;
94-
cloud.points.resize(cloud.width * cloud.height);
95-
for (unsigned int i = 0; i < obs.size(); i++) {
96-
cloud.points[i].x = obs[i](0);
97-
cloud.points[i].y = obs[i](1);
98-
cloud.points[i].z = obs[i](2);
99-
}
100-
return cloud;
88+
89+
return true;
90+
}
91+
/// Convert obstacle points into pcl point cloud
92+
PCLPointCloud toPCL(const vec_Vec3f &obs) {
93+
PCLPointCloud cloud;
94+
cloud.width = obs.size();
95+
cloud.height = 1;
96+
cloud.points.resize(cloud.width * cloud.height);
97+
for (unsigned int i = 0; i < obs.size(); i++) {
98+
cloud.points[i].x = obs[i](0);
99+
cloud.points[i].y = obs[i](1);
100+
cloud.points[i].z = obs[i](2);
101101
}
102-
private:
103-
///robot size: axe = (r, r, h)
104-
Vec3f axe_;
105-
///obstacle points
106-
vec_Vec3f obs_;
107-
///obstacles in kd tree form
108-
KDTree kdtree_;
109-
///Bounding box
110-
Polyhedron3D bbox_;
102+
return cloud;
103+
}
104+
105+
private:
106+
/// robot size: axe = (r, r, h)
107+
Vec3f axe_;
108+
/// obstacle points
109+
vec_Vec3f obs_;
110+
/// obstacles in kd tree form
111+
KDTree kdtree_;
112+
/// Bounding box
113+
Polyhedron3D bbox_;
111114
};
112115
#endif
113116

114-

mpl_external_planner/include/mpl_external_planner/ellipsoid_planner/env_cloud.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ namespace MPL {
1414
* @brief Point cloud environment
1515
*/
1616
class env_cloud : public env_base<3> {
17-
protected:
17+
protected:
1818
std::unique_ptr<EllipsoidUtil> map_util_;
1919

20-
public:
20+
public:
2121
/// Simple constructor
2222
env_cloud() {}
2323
/// Simple constructor
@@ -54,22 +54,21 @@ class env_cloud : public env_base<3> {
5454
succ_cost.clear();
5555
action_idx.clear();
5656

57-
//expanded_nodes_.push_back(curr.pos);
57+
// expanded_nodes_.push_back(curr.pos);
5858
// ws_.push_back(curr);
5959
for (int i = 0; i < (int)U_.size(); i++) {
6060
Primitive3D pr(curr, U_[i], dt_);
6161
Waypoint3D tn = pr.evaluate(dt_);
62-
if(tn == curr || !validate_primitive(pr, v_max_, a_max_, j_max_) ||
63-
!map_util_->isFree(pr))
62+
if (tn == curr || !validate_primitive(pr, v_max_, a_max_, j_max_) ||
63+
!map_util_->isFree(pr))
6464
continue;
6565
tn.t = curr.t + dt_;
6666
succ.push_back(tn);
6767
succ_cost.push_back(pr.J(pr.control()) + w_ * dt_);
6868
action_idx.push_back(i);
6969
}
70-
7170
}
7271
};
73-
}
72+
} // namespace MPL
7473

7574
#endif

mpl_external_planner/include/mpl_external_planner/ellipsoid_planner/primitive_ellipsoid_utils.h

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55
#ifndef MPL_PRIMITIVE_ELLIPSOID_UTILS_H
66
#define MPL_PRIMITIVE_ELLIPSOID_UTILS_H
7-
#include <mpl_basis/trajectory.h>
87
#include <decomp_geometry/ellipsoid.h>
8+
#include <mpl_basis/trajectory.h>
99

1010
/**
1111
* @brief estimate the ellipsoid in 3D
@@ -14,11 +14,10 @@
1414
* @param acc acceleration
1515
*/
1616
template <int Dim>
17-
Ellipsoid3D generate_ellipsoid(const Vec3f& axe,
18-
const Vecf<Dim>& pos,
19-
const Vecf<Dim>& acc) {
20-
Vec3f ellipsoid_center = Dim == 2? Vec3f(pos(0), pos(1), 0) : pos;
21-
Vec3f ellipsoid_acc = Dim == 2? Vec3f(acc(0), acc(1), 0) : acc;
17+
Ellipsoid3D generate_ellipsoid(const Vec3f& axe, const Vecf<Dim>& pos,
18+
const Vecf<Dim>& acc) {
19+
Vec3f ellipsoid_center = Dim == 2 ? Vec3f(pos(0), pos(1), 0) : pos;
20+
Vec3f ellipsoid_acc = Dim == 2 ? Vec3f(acc(0), acc(1), 0) : acc;
2221

2322
const Vec3f b3 = (ellipsoid_acc + 9.81 * Vec3f::UnitZ()).normalized();
2423
const Vec3f bc(std::cos(0), std::sin(0), 0);
@@ -35,14 +34,14 @@ Ellipsoid3D generate_ellipsoid(const Vec3f& axe,
3534
return Ellipsoid3D(C, ellipsoid_center);
3635
}
3736

38-
39-
///Sample N+1 ellipsoids along the primitive
37+
/// Sample N+1 ellipsoids along the primitive
4038
template <int Dim>
41-
vec_E<Ellipsoid3D> sample_ellipsoids(const Primitive<Dim>& pr, const Vec3f& axe, int N) {
42-
vec_E<Ellipsoid3D> Es(N+1);
39+
vec_E<Ellipsoid3D> sample_ellipsoids(const Primitive<Dim>& pr, const Vec3f& axe,
40+
int N) {
41+
vec_E<Ellipsoid3D> Es(N + 1);
4342
decimal_t dt = pr.t() / N;
44-
for(int i = 0; i <= N; i++) {
45-
const auto pt = pr.evaluate(i*dt);
43+
for (int i = 0; i <= N; i++) {
44+
const auto pt = pr.evaluate(i * dt);
4645
/*
4746
std::cout << "t:" << i*dt << std::endl;
4847
std::cout << "pos: " << pt.pos.transpose() << std::endl;
@@ -57,52 +56,52 @@ vec_E<Ellipsoid3D> sample_ellipsoids(const Primitive<Dim>& pr, const Vec3f& axe,
5756
return Es;
5857
}
5958

60-
///Sample N ellipsoids along the trajectory
59+
/// Sample N ellipsoids along the trajectory
6160
template <int Dim>
62-
vec_E<Ellipsoid3D> sample_ellipsoids(const Trajectory<Dim>& traj, const Vec3f& axe, int N) {
61+
vec_E<Ellipsoid3D> sample_ellipsoids(const Trajectory<Dim>& traj,
62+
const Vec3f& axe, int N) {
6363
vec_E<Ellipsoid3D> Es;
6464

6565
decimal_t dt = traj.getTotalTime() / N;
66-
for(decimal_t t = 0; t <= traj.getTotalTime(); t+= dt) {
66+
for (decimal_t t = 0; t <= traj.getTotalTime(); t += dt) {
6767
Command<Dim> pt;
68-
if(traj.evaluate(t, pt))
68+
if (traj.evaluate(t, pt))
6969
Es.push_back(generate_ellipsoid<Dim>(axe, pt.pos, pt.acc));
7070
}
7171

7272
return Es;
7373
}
7474

75-
///Approximate the maximum roll/pitch along the trajectory
75+
/// Approximate the maximum roll/pitch along the trajectory
7676
template <int Dim>
7777
void max_attitude(const Trajectory<Dim>& traj, int N) {
7878
decimal_t dt = traj.getTotalTime() / N;
7979
decimal_t max_roll = 0;
8080
decimal_t max_roll_time = 0;
8181
decimal_t max_pitch = 0;
8282
decimal_t max_pitch_time = 0;
83-
for(decimal_t t = 0; t <= traj.getTotalTime(); t+= dt) {
83+
for (decimal_t t = 0; t <= traj.getTotalTime(); t += dt) {
8484
Command<Dim> pt;
85-
if(traj.evaluate(t, pt)) {
86-
const Vec3f b3 = Dim == 2 ?
87-
(Vec3f(pt.acc(0), pt.acc(1), 0) +
88-
9.81 * Vec3f::UnitZ()).normalized() :
89-
(pt.acc + 9.81 * Vec3f::UnitZ()).normalized();
85+
if (traj.evaluate(t, pt)) {
86+
const Vec3f b3 =
87+
Dim == 2 ? (Vec3f(pt.acc(0), pt.acc(1), 0) + 9.81 * Vec3f::UnitZ())
88+
.normalized()
89+
: (pt.acc + 9.81 * Vec3f::UnitZ()).normalized();
9090
decimal_t roll = std::atan2(b3(1), b3(2));
91-
decimal_t pitch= std::atan2(b3(0), b3(2));
92-
if(std::fabs(roll) > std::fabs(max_roll)) {
91+
decimal_t pitch = std::atan2(b3(0), b3(2));
92+
if (std::fabs(roll) > std::fabs(max_roll)) {
9393
max_roll = roll;
9494
max_roll_time = t;
9595
}
96-
if(std::fabs(pitch) > std::fabs(max_pitch)) {
96+
if (std::fabs(pitch) > std::fabs(max_pitch)) {
9797
max_pitch = pitch;
9898
max_pitch_time = t;
9999
}
100-
101100
}
102101
}
103102

104-
printf("max roll: %f at [%f]\n", max_roll * 180/M_PI, max_roll_time);
105-
printf("max pitch: %f at [%f]\n", max_pitch * 180/M_PI, max_pitch_time);
103+
printf("max roll: %f at [%f]\n", max_roll * 180 / M_PI, max_roll_time);
104+
printf("max pitch: %f at [%f]\n", max_pitch * 180 / M_PI, max_pitch_time);
106105
}
107106

108107
#endif

0 commit comments

Comments
 (0)