12 #include <unordered_map> 27 (state.
pos - this->
goal_node_.pos).
template lpNorm<Eigen::Infinity>() <=
32 .
template lpNorm<Eigen::Infinity>() <= this->
tol_vel_;
35 .
template lpNorm<Eigen::Infinity>() <= this->
tol_acc_;
37 goaled = std::abs(state.
yaw - this->goal_node_.yaw) <= this->
tol_yaw_;
39 auto pns =
map_util_->rayTrace(state.
pos, this->goal_node_.pos);
40 for (
const auto &it : pns) {
41 if (
map_util_->isOccupied(it))
return false;
49 const auto pn =
map_util_->floatToInt(pt);
62 for (
int i = 0; i < Dim; i++) {
65 int n = std::ceil(max_v * pr.
t() /
map_util_->getRes());
67 for (
const auto &pt : pts) {
92 for (
int i = 0; i < Dim; i++) {
95 int n = std::max(5, (
int)std::ceil(max_v * pr.
t() /
map_util_->getRes()));
106 return std::numeric_limits<decimal_t>::infinity();
118 return std::numeric_limits<decimal_t>::infinity();
120 return std::numeric_limits<decimal_t>::infinity();
121 if (this->
wyaw_ > 0 && pt.use_yaw) {
122 const auto v = pt.vel.template topRows<2>();
123 if (v.norm() > 1e-5) {
125 1 - v.normalized().dot(
Vec2f(cos(pt.yaw), sin(pt.yaw)));
126 c += this->
wyaw_ * v_value * dt;
148 std::vector<decimal_t> &succ_cost,
149 std::vector<int> &action_idx)
const {
155 for (
unsigned int i = 0; i < this->
U_.size(); i++) {
161 tn.
t = curr.
t + this->
dt_;
164 if (!std::isinf(cost)) {
165 cost += this->calculate_intrinsic_cost(pr);
169 succ_cost.push_back(cost);
170 action_idx.push_back(i);
192 const int n = std::ceil(this->
v_max_ * total_time /
map_util_->getRes());
193 const auto pts = traj.
sample(n);
195 std::vector<decimal_t> costs;
200 for (
const auto &pt : pts) {
201 if (pt.t >= t)
break;
212 costs.push_back(this->
w_ * t + potential_cost);
213 printf(
"t: %.2f, cost: %f\n", t, costs.back());
217 printf(
"total cost: %f\n", total_cost);
220 int id = t / this->
dt_;
222 std::make_pair(traj.
evaluate(t), total_cost - costs[id]));
233 const auto pts = traj.
sample(n);
235 for (
const auto &pt : pts) {
243 return std::numeric_limits<decimal_t>::infinity();
249 return std::numeric_limits<decimal_t>::infinity();
251 return std::numeric_limits<decimal_t>::infinity();
259 printf(
"++++++++++++++++++++ env_map ++++++++++++++++++\n");
260 printf(
"+ w: %.2f +\n", this->
w_);
261 printf(
"+ wyaw: %.2f +\n", this->
wyaw_);
262 printf(
"+ dt: %.2f +\n", this->
dt_);
263 printf(
"+ t_max: %.2f +\n", this->
t_max_);
264 printf(
"+ v_max: %.2f +\n", this->
v_max_);
265 printf(
"+ a_max: %.2f +\n", this->
a_max_);
266 printf(
"+ j_max: %.2f +\n", this->
j_max_);
267 printf(
"+ yaw_max: %.2f +\n", this->
yaw_max_);
268 printf(
"+ U num: %zu +\n", this->
U_.size());
269 printf(
"+ tol_pos: %.2f +\n", this->
tol_pos_);
270 printf(
"+ tol_vel: %.2f +\n", this->
tol_vel_);
271 printf(
"+ tol_acc: %.2f +\n", this->
tol_acc_);
272 printf(
"+ tol_yaw: %.2f +\n", this->
tol_yaw_);
273 printf(
"+heur_ignore_dynamics: %d +\n",
276 printf(
"+ potential_weight: %.2f +\n",
279 printf(
"+ gradient_weight: %.2f +\n",
282 printf(
"+ use_prior_traj: true +\n");
283 printf(
"++++++++++++++++++++ env_map ++++++++++++++++++\n");
vec_E< std::pair< Waypoint< Dim >, decimal_t > > prior_traj_
Prior trajectory.
Definition: env_base.h:398
Waypoint< Dim > evaluate(decimal_t time) const
Evaluate Waypoint at time .
Definition: trajectory.h:67
std::vector< bool > search_region_
Valid search region (tunnel constraint)
Definition: env_base.h:400
decimal_t tol_vel_
tolerance of velocity for goal region, 0 means no tolerance
Definition: env_base.h:376
vec_E< Primitive< Dim > > expanded_edges_
expanded edges for debug
Definition: env_base.h:404
Definition: map_util.h:12
decimal_t wyaw_
weight of yaw
Definition: env_base.h:372
decimal_t yaw
yaw
Definition: waypoint.h:36
void set_gradient_weight(decimal_t w)
Set gradient weight.
Definition: env_map.h:178
decimal_t traverse_trajectory(const Trajectory< Dim > &traj) const
traverse trajectory
Definition: env_map.h:229
std::vector< int8_t > potential_map_
Potential map, optional.
Definition: env_map.h:290
Waypoint base class.
Definition: waypoint.h:23
decimal_t potential_weight_
Weight of potential value.
Definition: env_map.h:294
decimal_t getTotalTime() const
Get the total duration of Trajectory.
Definition: trajectory.h:300
void set_potential_weight(decimal_t w)
Set potential weight.
Definition: env_map.h:186
vec_E< VecDf > U_
Array of constant control input.
Definition: env_base.h:394
decimal_t tol_acc_
tolerance of acceleration for goal region, 0 means no tolerance
Definition: env_base.h:378
Trajectory class.
Definition: trajectory.h:43
decimal_t tol_yaw_
tolerance of yaw for goal region, 0 means no tolerance
Definition: env_base.h:380
void set_gradient_map(const vec_E< Vecf< Dim >> &map)
Set gradient map.
Definition: env_map.h:175
bool is_goal(const Waypoint< Dim > &state) const
Check if state hit the goal region, use L-1 norm.
Definition: env_map.h:25
vec_E< Vecf< Dim > > gradient_map_
Gradient map, optional.
Definition: env_map.h:292
decimal_t traverse_primitive(const Primitive< Dim > &pr) const
Accumulate the cost along the primitive.
Definition: env_map.h:90
Waypoint< Dim > evaluate(decimal_t t) const
Return Waypoint at time .
Definition: primitive.h:321
decimal_t yaw_max_
max yaw
Definition: env_base.h:388
Vecf< Dim > acc
acceleration in
Definition: waypoint.h:34
std::vector< T, Eigen::aligned_allocator< T > > vec_E
Pre-allocated std::vector for Eigen using vec_E.
Definition: data_type.h:53
decimal_t v_max_
max velocity
Definition: env_base.h:382
Vecf< Dim > vel
velocity in
Definition: waypoint.h:33
void get_succ(const Waypoint< Dim > &curr, vec_E< Waypoint< Dim >> &succ, std::vector< decimal_t > &succ_cost, std::vector< int > &action_idx) const
Get successor.
Definition: env_map.h:147
decimal_t gradient_weight_
Weight of gradient value.
Definition: env_map.h:296
decimal_t t
time when reaching this waypoint in graph search
Definition: waypoint.h:37
decimal_t t() const
Return duration .
Definition: primitive.h:336
decimal_t t_max_
max time
Definition: env_base.h:390
Eigen::Matrix< int, N, 1 > Veci
Eigen 1D int vector of size N.
Definition: data_type.h:59
void info()
Print out params.
Definition: env_map.h:258
double decimal_t
Rename the float type used in lib.
Definition: data_type.h:49
decimal_t dt_
duration of primitive
Definition: env_base.h:392
decimal_t j_max_
max jerk
Definition: env_base.h:386
void set_prior_trajectory(const Trajectory< Dim > &traj)
Set prior trajectory.
Definition: env_map.h:189
vec_Vecf< Dim > expanded_nodes_
expanded nodes for debug
Definition: env_base.h:402
vec_E< Command< Dim > > sample(int N) const
Sample N+1 Command along trajectory using uniformed time.
Definition: trajectory.h:230
bool is_free(const Primitive< Dim > &pr) const
Check if the primitive is in free space.
Definition: env_map.h:60
Vecf< 2 > Vec2f
Eigen 1D float vector of size 2.
Definition: data_type.h:76
Waypoint< Dim > goal_node_
Goal node.
Definition: env_base.h:396
decimal_t max_vel(int k) const
Return max velocity along one axis.
Definition: primitive.h:353
decimal_t a_max_
max acceleration
Definition: env_base.h:384
bool validate_primitive(const Primitive< Dim > &pr, decimal_t mv=0, decimal_t ma=0, decimal_t mj=0, decimal_t myaw=0)
Check if the max velocity magnitude is within the threshold.
Definition: primitive.h:450
Eigen::Matrix< decimal_t, N, 1 > Vecf
Eigen 1D float vector of size N.
Definition: data_type.h:56
Base environment class.
Definition: env_base.h:17
std::shared_ptr< MapUtil< Dim > > map_util_
Collision checking util.
Definition: env_map.h:288
decimal_t w_
weight of time cost
Definition: env_base.h:370
bool heur_ignore_dynamics_
if enabled, ignore dynamics when calculate heuristic
Definition: env_base.h:368
vec_E< Waypoint< Dim > > sample(int N) const
Sample N+1 Waypoints using uniformed time.
Definition: primitive.h:415
Voxel map environment.
Definition: env_map.h:19
env_map(std::shared_ptr< MapUtil< Dim >> map_util)
Constructor with map util as input.
Definition: env_map.h:22
Primitive class.
Definition: primitive.h:206
Definition: map_util.h:20
Vecf< Dim > pos
position in
Definition: waypoint.h:32
decimal_t tol_pos_
tolerance of position for goal region, 0.5 is the default
Definition: env_base.h:374
bool is_free(const Vecf< Dim > &pt) const
Check if a point is in free space.
Definition: env_map.h:48
void set_potential_map(const std::vector< int8_t > &map)
Set potential map.
Definition: env_map.h:181