MRSL Motion Primitive Library  1.2
A motion primitive library for generating trajectory for mobile robots
waypoint.h
Go to the documentation of this file.
1 
6 #ifndef MPL_WAYPOINT_H
7 #define MPL_WAYPOINT_H
8 #include <bitset>
9 #include <boost/functional/hash.hpp>
10 #include <iostream>
11 
12 #include "control.h"
13 #include "data_type.h"
14 
22 template <int Dim>
23 struct Waypoint {
25  Waypoint() : control(Control::NONE) {}
31 
37  decimal_t t{0};
38 
46  union {
47  struct {
48  bool use_pos : 1;
49  bool use_vel : 1;
50  bool use_acc : 1;
51  bool use_jrk : 1;
52  bool use_yaw : 1;
53  };
55  };
56 
57  bool enable_t{false};
58 
61  void print(std::string str = "") const {
62  if (!str.empty()) std::cout << str << std::endl;
63  if (use_pos) std::cout << "pos: " << pos.transpose() << std::endl;
64  if (use_vel) std::cout << "vel: " << vel.transpose() << std::endl;
65  if (use_acc) std::cout << "acc: " << acc.transpose() << std::endl;
66  if (use_jrk) std::cout << "jrk: " << jrk.transpose() << std::endl;
67  if (use_yaw) std::cout << "yaw: " << yaw << std::endl;
68  if (enable_t) std::cout << " t: " << t << std::endl;
69 
70  if (control == Control::VEL)
71  std::cout << "use vel!" << std::endl;
72  else if (control == Control::ACC)
73  std::cout << "use acc!" << std::endl;
74  else if (control == Control::JRK)
75  std::cout << "use jrk!" << std::endl;
76  else if (control == Control::SNP)
77  std::cout << "use snp!" << std::endl;
78  else if (control == Control::VELxYAW)
79  std::cout << "use vel & yaw!" << std::endl;
80  else if (control == Control::ACCxYAW)
81  std::cout << "use acc & yaw!" << std::endl;
82  else if (control == Control::JRKxYAW)
83  std::cout << "use jrk & yaw!" << std::endl;
84  else if (control == Control::SNPxYAW)
85  std::cout << "use snp & yaw!" << std::endl;
86  else
87  std::cout << "use null!" << std::endl;
88  }
89 };
90 
92 template <int Dim>
93 std::size_t hash_value(const Waypoint<Dim>& key) {
94  std::size_t val = 0;
95  for (int i = 0; i < Dim; i++) {
96  if (key.use_pos) {
97  int id = std::round(key.pos(i) / 0.01);
98  boost::hash_combine(val, id);
99  }
100  if (key.use_vel) {
101  int id = std::round(key.vel(i) / 0.1);
102  boost::hash_combine(val, id);
103  }
104  if (key.use_acc) {
105  int id = std::round(key.acc(i) / 0.1);
106  boost::hash_combine(val, id);
107  }
108  if (key.use_jrk) {
109  int id = std::round(key.jrk(i) / 0.1);
110  boost::hash_combine(val, id);
111  }
112  }
113 
114  if (key.use_yaw) {
115  int id = std::round(key.yaw / 0.1);
116  boost::hash_combine(val, id);
117  }
118 
119  if (key.enable_t) {
120  int id = std::round(key.t / 0.1);
121  boost::hash_combine(val, id);
122  }
123 
124  return val;
125 }
126 
132 template <int Dim>
133 bool operator==(const Waypoint<Dim>& l, const Waypoint<Dim>& r) {
134  return hash_value(l) == hash_value(r);
135 }
136 
138 template <int Dim>
139 bool operator!=(const Waypoint<Dim>& l, const Waypoint<Dim>& r) {
140  return hash_value(l) != hash_value(r);
141 }
142 
145 
148 
149 #endif
bool operator!=(const Waypoint< Dim > &l, const Waypoint< Dim > &r)
Check if two waypoints are not equivalent.
Definition: waypoint.h:139
Vecf< Dim > jrk
jerk in
Definition: waypoint.h:35
decimal_t yaw
yaw
Definition: waypoint.h:36
Waypoint base class.
Definition: waypoint.h:23
bool operator==(const Waypoint< Dim > &l, const Waypoint< Dim > &r)
Check if two waypoints are equivalent.
Definition: waypoint.h:133
bool use_acc
If true, acc will be used in primitive generation.
Definition: waypoint.h:50
bool use_vel
If true, vel will be used in primitive generation.
Definition: waypoint.h:49
Waypoint()
Empty constructor.
Definition: waypoint.h:25
Control
Enum for control input.
Definition: control.h:10
Vecf< Dim > acc
acceleration in
Definition: waypoint.h:34
std::size_t hash_value(const Waypoint< Dim > &key)
Generate hash value for Waypoint class.
Definition: waypoint.h:93
Control::Control control
Control value.
Definition: waypoint.h:54
Vecf< Dim > vel
velocity in
Definition: waypoint.h:33
decimal_t t
time when reaching this waypoint in graph search
Definition: waypoint.h:37
double decimal_t
Rename the float type used in lib.
Definition: data_type.h:49
bool use_jrk
If true, jrk will be used in primitive generation.
Definition: waypoint.h:51
Defines all data types used in this lib.
bool use_yaw
If true, yaw will be used in primitive generation.
Definition: waypoint.h:52
Eigen::Matrix< decimal_t, N, 1 > Vecf
Eigen 1D float vector of size N.
Definition: data_type.h:56
Control classes.
Waypoint< 3 > Waypoint3D
Waypoint for 3D.
Definition: waypoint.h:147
Definition: control.h:8
Waypoint(Control::Control c)
Simple constructor.
Definition: waypoint.h:30
Vecf< Dim > pos
position in
Definition: waypoint.h:32
bool use_pos
If true, pos will be used in primitive generation.
Definition: waypoint.h:48
Waypoint< 2 > Waypoint2D
Waypoint for 2D.
Definition: waypoint.h:144
bool enable_t
Definition: waypoint.h:57
void print(std::string str="") const
Print all attributes.
Definition: waypoint.h:61