From: Jiri Vlasak Date: Fri, 19 Mar 2021 11:04:46 +0000 (+0100) Subject: Add tmp steered X-Git-Tag: v0.6.0~2^2~2 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/hubacji1/rrts.git/commitdiff_plain/fc09e0199ab174e1544bf69d063e944993624656 Add tmp steered --- diff --git a/api/rrts.h b/api/rrts.h index f4f1f58..f5e2978 100644 --- a/api/rrts.h +++ b/api/rrts.h @@ -169,6 +169,7 @@ class RRTS { */ void set_sample_uniform_circle(); protected: + std::vector tmp_steered_; bool finishit = false; double path_cost_before_opt_ = 9999; @@ -197,6 +198,7 @@ class RRTS { virtual RRTNode *nn(RRTNode &t); virtual std::vector nv(RRTNode &t); void steer(RRTNode &f, RRTNode &t); + void tmp_steer(RRTNode &f, RRTNode &t); virtual void steer1(RRTNode &f, RRTNode &t); virtual void steer2(RRTNode &f, RRTNode &t); /*! \brief Join steered nodes to RRT data structure @@ -204,6 +206,7 @@ class RRTS { \param f RRT node to join steered nodes to. */ void join_steered(RRTNode *f); + void join_tmp_steered(RRTNode *f); virtual bool goal_found(RRTNode &f); // RRT* procedures bool connect(); diff --git a/src/rrts.cc b/src/rrts.cc index 10d60fd..9d750e4 100644 --- a/src/rrts.cc +++ b/src/rrts.cc @@ -7,6 +7,17 @@ template int sgn(T val) { return (T(0) < val) - (val < T(0)); } +double edist(RRTNode const& n1, RRTNode const& n2) +{ + auto dx = n2.x() - n1.x(); + auto dy = n2.y() - n1.y(); + return sqrt(dx*dx + dy*dy); +} +double edist(RRTNode const* n1, RRTNode const* n2) +{ + return edist(*n1, *n2); +} + RRTNode::RRTNode() { } @@ -323,6 +334,14 @@ void RRTS::steer(RRTNode &f, RRTNode &t) ReedsSheppStateSpace rsss(this->bc.mtr()); rsss.sample(q0, q1, 0.2, cb_rs_steer, &this->steered()); } +void RRTS::tmp_steer(RRTNode &f, RRTNode &t) +{ + this->tmp_steered_.clear(); + double q0[] = {f.x(), f.y(), f.h()}; + double q1[] = {t.x(), t.y(), t.h()}; + ReedsSheppStateSpace rsss(this->bc.mtr()); + rsss.sample(q0, q1, 0.2, cb_rs_steer, &this->tmp_steered_); +} void RRTS::steer1(RRTNode &f, RRTNode &t) { @@ -345,6 +364,17 @@ void RRTS::join_steered(RRTNode *f) f = t; } } +void RRTS::join_tmp_steered(RRTNode *f) +{ + while (this->tmp_steered_.size() > 0) { + this->store_node(this->tmp_steered_.front()); + RRTNode *t = &this->nodes().back(); + t->p(f); + t->c(this->cost_build(*f, *t)); + this->tmp_steered_.erase(this->tmp_steered_.begin()); + f = t; + } +} bool RRTS::goal_found(RRTNode &f) { @@ -380,6 +410,18 @@ bool RRTS::connect() cost = this->cost_search(*n, *t); } } + // steer from f->t and then continue with the steered. + this->tmp_steer(*f, *t); + if (this->tmp_steered_.size() > 0) { + auto col = this->collide_tmp_steered_from(*f); + if (std::get<0>(col)) + return false; + this->join_tmp_steered(f); + f = &this->nodes().back(); + } + if (edist(f, t) > 0.2) + return false; + // cont. this->store_node(this->steered().front()); t = &this->nodes().back(); t->p(f);