]> rtime.felk.cvut.cz Git - hubacji1/iamcar.git/blobdiff - incl/rrtbase.h
Add default sampling info setter
[hubacji1/iamcar.git] / incl / rrtbase.h
index 1f1b6f479334ff7491baace6a7cb3bc44ac27b59..9b17d44e673c772bc1d7501f215fb8940b2565eb 100644 (file)
@@ -18,26 +18,44 @@ along with I am car. If not, see <http://www.gnu.org/licenses/>.
 #ifndef RRTBASE_H
 #define RRTBASE_H
 
+#include <array>
 #include <chrono>
 #include <cmath>
 #include <pthread.h>
+#include <queue>
 #include <random>
 #include <vector>
 #include "obstacle.h"
 #include "rrtnode.h"
-#include "sample.h"
 #include "slotplanner.h"
 
 #define NOFNODES 20000
 
 #define IXSIZE 100
-#define IXSTEP (1.0 * ((VMAX) - (VMIN)) / IXSIZE)
-#define IXI(x) ({ __typeof__ (x) _x = (x); \
-                std::abs((int) floor(_x / IXSTEP)); })
 #define IYSIZE 100
-#define IYSTEP (1.0 * ((HMAX) - (HMIN)) / IYSIZE)
-#define IYI(y) ({ __typeof__ (y) _y = (y); \
-                std::abs((int) floor(_y / IYSTEP)); })
+
+#define GLVERTEX(n) ((n)->x() * glplwscale), ((n)->y() * glplhscale)
+
+// Nearest neighbor
+struct mcnn { // min-cost nearest neighbour
+        float mc;
+        RRTNode *nn;
+};
+#pragma omp declare reduction \
+        (minn: struct mcnn: omp_out = \
+         omp_in.mc < omp_out.mc ? omp_in : omp_out) \
+       initializer \
+       (omp_priv(omp_orig))
+
+// Near vertices
+#define GAMMA_RRTSTAR(card_V) ({ \
+       __typeof__ (card_V) _card_V = (card_V); \
+       pow(log(_card_V) / _card_V, 1.0/3.0); \
+})
+
+# pragma omp declare reduction \
+        (merge: std::vector<RRTNode *>: \
+         omp_out.insert(omp_out.end(), omp_in.begin(), omp_in.end()))
 
 class Cell {
         private:
@@ -63,6 +81,7 @@ class RRTBase {
 
                 std::vector<RRTNode *> nodes_;
                 std::vector<RRTNode *> dnodes_;
+                std::queue<RRTNode *> firsts_;
                 PolygonObstacle frame_;
                 std::vector<RRTNode *> samples_;
                 std::vector<CircleObstacle> *cobstacles_;
@@ -78,11 +97,18 @@ class RRTBase {
                 std::vector<float> slog_; // seconds of trajectories
                 std::vector<std::vector<RRTNode *>> tlog_; // trajectories
                 std::vector<RRTNode *> slot_cusp_; // cusp nodes in slot
-
+        protected:
                 std::default_random_engine gen_;
+                std::normal_distribution<float> ndx_;
+                std::normal_distribution<float> ndy_;
+                std::normal_distribution<float> ndh_;
         public:
                 const float GOAL_FOUND_DISTANCE = 0.2;
                 const float GOAL_FOUND_ANGLE = M_PI / 32;
+                float HMIN = -20;
+                float HMAX = 20;
+                float VMIN = -5;
+                float VMAX = 30;
 
                 ~RRTBase();
                 RRTBase();
@@ -94,9 +120,10 @@ class RRTBase {
                 std::vector<RRTNode *> &goals();
                 std::vector<RRTNode *> &nodes();
                 std::vector<RRTNode *> &dnodes();
+                std::queue<RRTNode *> &firsts();
                 PolygonObstacle &frame();
                 std::vector<RRTNode *> &samples();
-                std::vector<RRTNode *> iy_[IYSIZE];
+                std::array<std::vector<RRTNode *>, IYSIZE> iy_;
                 Cell ixy_[IXSIZE][IYSIZE];
                 std::vector<CircleObstacle> *co();
                 std::vector<SegmentObstacle> *so();
@@ -150,10 +177,12 @@ class RRTBase {
                 bool rebase(RRTNode *nr);
                 std::vector<RRTNode *> findt();
                 std::vector<RRTNode *> findt(RRTNode *n);
+                int XI(RRTNode *n);
+                int YI(RRTNode *n);
 
                 // RRT Framework
-                SamplingInfo samplingInfo_;
-                bool useSamplingInfo_ = false;
+                void defaultSamplingInfo();
+                void setSamplingInfo(SamplingInfo si);
                 RRTNode *sample();
                 float cost(RRTNode *init, RRTNode *goal);
                 RRTNode *nn(RRTNode *rs);