From 8136e9ec81cf8c6b1e7ff39954d3ef9a72b786eb Mon Sep 17 00:00:00 2001 From: FrankE Date: Wed, 7 Sep 2016 11:51:56 +0200 Subject: [PATCH] added missing stuff --- api/DummyAPI.h | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ api/api.h | 48 +++++++++++++++++++++++++ main.cpp | 4 ++- 3 files changed, 147 insertions(+), 1 deletion(-) diff --git a/api/DummyAPI.h b/api/DummyAPI.h index cb9e17c..73b9d11 100644 --- a/api/DummyAPI.h +++ b/api/DummyAPI.h @@ -1,4 +1,100 @@ #ifndef DUMMYAPI_H #define DUMMYAPI_H +#include "api.h" + +class DummyAPI : public API { + +private: + + /** all attached listeners */ + std::vector listeners; + + int dstID = -1; + bool enabled; + std::thread thread; + std::string dataFolder; + float speed = 1.0f; + std::vector points; + + +public: + + /** ctor with the folder where the data-files reside */ + DummyAPI(const std::string& dataFolder) : dataFolder(dataFolder) { + ; + } + + void setSpeed(const float speed) { + this->speed = speed; + } + + void setTarget(const Point3 p) override { + (void) p; + throw Exception("not yet implemented!"); + } + + void setTarget(const int id) override { + + const std::string fileName = dataFolder + "/" + std::to_string(id) + ".dat"; + std::ifstream in(fileName); + + if (id == -1) {throw Exception("call setTarget(id) first!");} + if (!in.good()) {throw Exception("failed to load file: '" + fileName + "'");} + + // load + while (in.good() && !in.eof()) { + float x, y, z; + in >> x; + in >> y; + in >> z; + points.push_back(Point3(x,y,z)); + } + + } + + void startNavigation() override { + enabled = true; + dummySender(); + } + + void stopNavigation() override { + enabled = false; + thread.join(); + } + + void addListener(APIListener* l) override { + listeners.push_back(l); + } + + Point3 getDst() { + return points[points.size() - 2]; + } + +private: + + /** send dummy data using the given file */ + void dummySender() { + + // run-loop + auto run = [&] () { + + std::vector pts = points; // local copy + + while(!pts.empty() && enabled) { + Point3 cur = pts.front(); + pts.erase(pts.begin()); + for (APIListener* l : listeners) {l->onPositionUpdate(cur);} + std::this_thread::sleep_for(std::chrono::milliseconds( (int)(500/speed) )); + } + + }; + + // run + thread = std::thread(run); + + } + + +}; #endif // DUMMYAPI_H diff --git a/api/api.h b/api/api.h index 4ee2cc4..33b958b 100644 --- a/api/api.h +++ b/api/api.h @@ -1,4 +1,52 @@ #ifndef API_H #define API_H +#include +#include +#include +#include + +#include "../geo/Point3.h" + +class APIListener { + +public: + + /** dtor */ + virtual ~APIListener() {;} + + /** the currently estimated path to the target has changed */ + virtual void onPathUpdate(const std::vector& curPath) = 0; + + /** the currently estimated position has changed */ + virtual void onPositionUpdate(const Point3 curPos) = 0; + +}; + +class API { + +public: + + /** dtor */ + virtual ~API() {;} + + /** set the desired target by using the given position */ + virtual void setTarget(const Point3 p) = 0; + + /** set the desired target by using the given POI-ID */ + virtual void setTarget(const int id) = 0; + + /** start the navigation process */ + virtual void startNavigation() = 0; + + /** stop the navigation process */ + virtual void stopNavigation() = 0; + + /** attach as listener to the API */ + virtual void addListener(APIListener* l) = 0; + +}; + + + #endif // API_H diff --git a/main.cpp b/main.cpp index 51db809..7e30379 100755 --- a/main.cpp +++ b/main.cpp @@ -19,7 +19,9 @@ int main(int argc, char** argv) { // skip all tests starting with LIVE_ ::testing::GTEST_FLAG(filter) = "-*.LIVE_*"; - ::testing::GTEST_FLAG(filter) = "*Grid.*"; + ::testing::GTEST_FLAG(filter) = "*GridWalk2HeadingControl*"; + + //::testing::GTEST_FLAG(filter) = "*Grid.*"; //::testing::GTEST_FLAG(filter) = "*Dijkstra.*"; //::testing::GTEST_FLAG(filter) = "*LogDistanceCeilingModel*";