diff --git a/grid/factory/GridImportance.h b/grid/factory/GridImportance.h index 34d39a5..8ab6473 100644 --- a/grid/factory/GridImportance.h +++ b/grid/factory/GridImportance.h @@ -40,6 +40,9 @@ public: GridFactory fac(inv); fac.addInverted(g, z_cm); + // sanity check + Assert::isFalse(inv.getNumNodes() == 0, "inverted grid is empty!"); + // construct KNN search KNN, 3> knn(inv); @@ -194,7 +197,7 @@ public: float getWallImportance(float dist_m) { // avoid sticking too close to walls (unlikely) - static Distribution::Normal avoidWalls(0.0, 0.4); + static Distribution::Normal avoidWalls(0.0, 0.5); // favour walking near walls (likely) static Distribution::Normal stickToWalls(0.9, 0.5); diff --git a/grid/walk/GridWalkLightAtTheEndOfTheTunnel.h b/grid/walk/GridWalkLightAtTheEndOfTheTunnel.h index 45ea259..d5b4815 100644 --- a/grid/walk/GridWalkLightAtTheEndOfTheTunnel.h +++ b/grid/walk/GridWalkLightAtTheEndOfTheTunnel.h @@ -155,11 +155,14 @@ private: // update the heading-change and walked-distance next.headingChange_rad += next.heading.getRAD() - cur.heading.getRAD(); next.distanceWalked_m += walked_m; + ++((T*)next.node)->cnt; // TODO: eval only if (next.node->z_cm != cur.node->z_cm) { int i = 0; } + + // done? if (distRest_m <= 0) {return next;} diff --git a/grid/walk/GridWalkSimpleControl.h b/grid/walk/GridWalkSimpleControl.h index 82f0c6e..636646f 100644 --- a/grid/walk/GridWalkSimpleControl.h +++ b/grid/walk/GridWalkSimpleControl.h @@ -114,7 +114,7 @@ private: if (drawer.getCumProbability() < 0.1 && (--retries) >= 0) { walked_m = 0; cur = start; - WHAT THE HELL + //WHAT THE HELL if (retries == 0) { reqHeading = dChange.draw(); } continue; } diff --git a/nav/dijkstra/Dijkstra.h b/nav/dijkstra/Dijkstra.h index 9a79cc7..0180643 100644 --- a/nav/dijkstra/Dijkstra.h +++ b/nav/dijkstra/Dijkstra.h @@ -22,9 +22,10 @@ template class Dijkstra { public: - /** get the dijkstra-pendant for the given user-node */ - DijkstraNode* getNode(const T& userNode) { - return nodes[&userNode]; + /** get the dijkstra-pendant for the given user-node. null if none matches */ + DijkstraNode* getNode(const T& userNode) const { + auto it = nodes.find(&userNode); + return (unlikely(it == nodes.end())) ? (nullptr) : (it->second); } /** build shortest path from start to end using the provided wrapper-class */ diff --git a/nav/dijkstra/DijkstraPath.h b/nav/dijkstra/DijkstraPath.h index 76ef80f..fbcb34f 100644 --- a/nav/dijkstra/DijkstraPath.h +++ b/nav/dijkstra/DijkstraPath.h @@ -2,6 +2,9 @@ #define DIJKSTRAPATH_H #include "DijkstraStructs.h" +#include + +#include "../../Assertions.h" /** * describes a dijkstra-generated path between end and start. @@ -20,15 +23,30 @@ public: /** ctor from end- to start-node */ DijkstraPath(DijkstraNode* end, DijkstraNode* start) { + // sanity checks + Assert::isNotNull(end, "end-node must not be null"); + Assert::isNotNull(start, "start-node must not be null"); + // follow the path from the end to the start DijkstraNode* curNode = end; while (curNode != start) { + + // sanity check in case no path between start and end exists + Assert::isNotNull(curNode, "there is not path between start and end. did you accidentially swap start and end?"); + + // append path.push_back(curNode); curNode = curNode->previous; + } } + /** allow iteration */ + decltype(path.begin()) begin() {return path.begin();} + decltype(path.end()) end() {return path.end();} + + /** NANOFLANN: number of elements in the path */ inline int kdtree_get_point_count() const { return path.size();