[Fawkes Git] branch/fzwilling/robot-memory: robot-memory: priorize computables

Frederik Zwilling zwilling at kbsg.rwth-aachen.de
Mon Dec 12 10:33:54 CET 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, fzwilling/robot-memory has been updated
        to  4eb6e2b97f9b41166ead27fb76a3896f34aefc76 (commit)
      from  bf33a688694f1bf9b4a79399b474f4a00791ba0a (commit)

http://git.fawkesrobotics.org/fawkes.git/fzwilling/robot-memory

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit 4eb6e2b97f9b41166ead27fb76a3896f34aefc76
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Thu Dec 8 18:33:00 2016 +0100
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Mon Dec 12 10:33:52 2016 +0100

    robot-memory: priorize computables
    
    Sometimes multiple computables should be executed one after another
    (e.g. getting BlackBoard data and transforming it into another frame).
    Thus we need to define the order of execution by priorities.  The higher
    the priority, the earlier the computable is executed. The default
    priority is 0.

http://git.fawkesrobotics.org/fawkes.git/commit/4eb6e2b
http://trac.fawkesrobotics.org/changeset/4eb6e2b

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 .../computables/blackboard_computable.cpp          |    6 ++++--
 .../computables/blackboard_computable.h            |    3 ++-
 .../robot-memory/computables/computable.cpp        |   12 +++++++++++-
 src/plugins/robot-memory/computables/computable.h  |    4 +++-
 .../robot-memory/computables/computables_manager.h |   10 +++++++---
 .../computables/transform_computable.cpp           |    4 +++-
 src/plugins/robot-memory/robot_memory.h            |    4 ++--
 src/plugins/robot-memory/robot_memory_thread.cpp   |    2 +-
 8 files changed, 33 insertions(+), 12 deletions(-)


- *Diffs* -------------------------------------------------------------

- *commit* 4eb6e2b97f9b41166ead27fb76a3896f34aefc76 - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Thu Dec 8 18:33:00 2016 +0100
Subject: robot-memory: priorize computables

 .../computables/blackboard_computable.cpp          |    6 ++++--
 .../computables/blackboard_computable.h            |    3 ++-
 .../robot-memory/computables/computable.cpp        |   12 +++++++++++-
 src/plugins/robot-memory/computables/computable.h  |    4 +++-
 .../robot-memory/computables/computables_manager.h |   10 +++++++---
 .../computables/transform_computable.cpp           |    4 +++-
 src/plugins/robot-memory/robot_memory.h            |    4 ++--
 src/plugins/robot-memory/robot_memory_thread.cpp   |    2 +-
 8 files changed, 33 insertions(+), 12 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/computables/blackboard_computable.cpp b/src/plugins/robot-memory/computables/blackboard_computable.cpp
index 528f80f..6361bc9 100644
--- a/src/plugins/robot-memory/computables/blackboard_computable.cpp
+++ b/src/plugins/robot-memory/computables/blackboard_computable.cpp
@@ -30,7 +30,7 @@
 using namespace fawkes;
 using namespace mongo;
 
-BlackboardComputable::BlackboardComputable(RobotMemory* robot_memory, fawkes::BlackBoard* blackboard, fawkes::Logger* logger)
+BlackboardComputable::BlackboardComputable(RobotMemory* robot_memory, fawkes::BlackBoard* blackboard, fawkes::Logger* logger, fawkes::Configuration* config)
 {
   robot_memory_ = robot_memory;
   blackboard_ = blackboard;
@@ -38,7 +38,9 @@ BlackboardComputable::BlackboardComputable(RobotMemory* robot_memory, fawkes::Bl
 
   //register computable
   Query query = fromjson("{interface:{$exists:true}}");
-  computable = robot_memory_->register_computable(query, "robmem.blackboard", &BlackboardComputable::compute_interfaces, this);
+  int priority = config->get_int("plugins/robot-memory/computables/blackboard/priority");
+  float caching_time = config->get_float("plugins/robot-memory/computables/blackboard/caching-time");
+  computable = robot_memory_->register_computable(query, "robmem.blackboard", &BlackboardComputable::compute_interfaces, this, caching_time, priority);
 }
 
 BlackboardComputable::~BlackboardComputable()
diff --git a/src/plugins/robot-memory/computables/blackboard_computable.h b/src/plugins/robot-memory/computables/blackboard_computable.h
index 6019c20..fe0d622 100644
--- a/src/plugins/robot-memory/computables/blackboard_computable.h
+++ b/src/plugins/robot-memory/computables/blackboard_computable.h
@@ -25,6 +25,7 @@
 #include "../robot_memory.h"
 #include <blackboard/blackboard.h>
 #include <aspect/logging.h>
+#include <config/config.h>
 
 /** @class BlackboardComputable  blackboard_computable.h
  *
@@ -33,7 +34,7 @@
 class BlackboardComputable
 {
   public:
-    BlackboardComputable(RobotMemory* robot_memory, fawkes::BlackBoard* blackboard, fawkes::Logger* logger);
+    BlackboardComputable(RobotMemory* robot_memory, fawkes::BlackBoard* blackboard, fawkes::Logger* logger, fawkes::Configuration* config);
     virtual ~BlackboardComputable();
 
   private:
diff --git a/src/plugins/robot-memory/computables/computable.cpp b/src/plugins/robot-memory/computables/computable.cpp
index b8ac359..81ccd20 100644
--- a/src/plugins/robot-memory/computables/computable.cpp
+++ b/src/plugins/robot-memory/computables/computable.cpp
@@ -30,13 +30,14 @@ using namespace mongo;
  * @author Frederik Zwilling
  */
 
-Computable::Computable(Query query_to_compute, std::string collection, const boost::function<std::list<BSONObj> (BSONObj, std::string)> &compute_function, double caching_time)
+Computable::Computable(Query query_to_compute, std::string collection, const boost::function<std::list<BSONObj> (BSONObj, std::string)> &compute_function, double caching_time, int priority)
 {
   this->compute_function = compute_function;
   this->query_to_compute = query_to_compute;
   this->collection = collection;
   //convert caching time to milliseconds
   this->caching_time = (int) (caching_time * 1000.0);
+  this->priority = priority;
 }
 
 Computable::~Computable()
@@ -90,4 +91,13 @@ std::string Computable::get_collection()
   return collection;
 }
 
+/**
+ * Gets the priority of the computable
+ * @return The query
+ */
+int Computable::get_priority()
+{
+  return priority;
+}
+
 
diff --git a/src/plugins/robot-memory/computables/computable.h b/src/plugins/robot-memory/computables/computable.h
index 1783367..18ab3ff 100644
--- a/src/plugins/robot-memory/computables/computable.h
+++ b/src/plugins/robot-memory/computables/computable.h
@@ -28,18 +28,20 @@
 class Computable
 {
   public:
-    Computable(mongo::Query query_to_compute, std::string collection, const boost::function<std::list<mongo::BSONObj> (mongo::BSONObj, std::string)> &compute_function, double caching_time = 0.0);
+    Computable(mongo::Query query_to_compute, std::string collection, const boost::function<std::list<mongo::BSONObj> (mongo::BSONObj, std::string)> &compute_function, double caching_time = 0.0, int priority = 0);
     virtual ~Computable();
 
     std::list<mongo::BSONObj> compute(mongo::BSONObj query);
     mongo::Query get_query();
     std::string get_collection();
+    int get_priority();
 
   private:
     boost::function<std::list<mongo::BSONObj> (mongo::BSONObj, std::string)> compute_function;
     mongo::Query query_to_compute;
     std::string collection;
     int caching_time; //in milliseconds
+    int priority;
 };
 
 #endif /* FAWKES_SRC_PLUGINS_ROBOT_MEMORY_COMPUTABLE_H_ */
diff --git a/src/plugins/robot-memory/computables/computables_manager.h b/src/plugins/robot-memory/computables/computables_manager.h
index c4edb8b..b9bde3c 100644
--- a/src/plugins/robot-memory/computables/computables_manager.h
+++ b/src/plugins/robot-memory/computables/computables_manager.h
@@ -56,10 +56,14 @@ class ComputablesManager
      * @return Computable Object pointer used for removing it
      */
     template<typename T>
-    Computable* register_computable(mongo::Query query_to_compute, std::string collection, std::list<mongo::BSONObj>(T::*compute_func)(mongo::BSONObj, std::string), T *obj, double caching_time = 0.0)
+    Computable* register_computable(mongo::Query query_to_compute, std::string collection, std::list<mongo::BSONObj>(T::*compute_func)(mongo::BSONObj, std::string), T *obj, double caching_time = 0.0, int priority = 0)
     {
-      Computable* comp = new Computable(query_to_compute, collection, boost::bind(compute_func, obj, _1, _2), caching_time);
-      computables.push_back(comp);
+      Computable* comp = new Computable(query_to_compute, collection, boost::bind(compute_func, obj, _1, _2), caching_time, priority);
+      //sort it into the right position
+      std::list<Computable*>::iterator pos = computables.begin();
+      while(pos != computables.end() && priority < (*pos)->get_priority())
+        pos++;
+      computables.insert(pos, comp);
       return comp;
     }
 
diff --git a/src/plugins/robot-memory/computables/transform_computable.cpp b/src/plugins/robot-memory/computables/transform_computable.cpp
index 6e87f18..fce603c 100644
--- a/src/plugins/robot-memory/computables/transform_computable.cpp
+++ b/src/plugins/robot-memory/computables/transform_computable.cpp
@@ -39,9 +39,11 @@ TransformComputable::TransformComputable(RobotMemory* robot_memory, fawkes::tf::
   //register computable
   Query query = fromjson("{frame:{$exists:true},allow_tf:true}");
   std::vector<std::string>  collections = config->get_strings("plugins/robot-memory/computables/transform/collections");
+  int priority = config->get_int("plugins/robot-memory/computables/transform/priority");
+  float caching_time = config->get_float("plugins/robot-memory/computables/transform/caching-time");
   for(std::string col : collections)
   {
-    computables.push_back(robot_memory_->register_computable(query, col, &TransformComputable::compute_transform, this));
+    computables.push_back(robot_memory_->register_computable(query, col, &TransformComputable::compute_transform, this, caching_time, priority));
   }
 }
 
diff --git a/src/plugins/robot-memory/robot_memory.h b/src/plugins/robot-memory/robot_memory.h
index 2deb923..5944e07 100644
--- a/src/plugins/robot-memory/robot_memory.h
+++ b/src/plugins/robot-memory/robot_memory.h
@@ -102,9 +102,9 @@ class RobotMemory
      * @return Computable Object pointer used for removing it
      */
     template<typename T>
-    Computable* register_computable(mongo::Query query_to_compute, std::string collection, std::list<mongo::BSONObj>(T::*compute_func)(mongo::BSONObj, std::string), T *obj, double caching_time = 0.0)
+    Computable* register_computable(mongo::Query query_to_compute, std::string collection, std::list<mongo::BSONObj>(T::*compute_func)(mongo::BSONObj, std::string), T *obj, double caching_time = 0.0, int priority = 0)
     {
-      return computables_manager_->register_computable(query_to_compute, collection, compute_func, obj, caching_time);
+      return computables_manager_->register_computable(query_to_compute, collection, compute_func, obj, caching_time, priority);
     }
     void remove_computable(Computable* computable);
 
diff --git a/src/plugins/robot-memory/robot_memory_thread.cpp b/src/plugins/robot-memory/robot_memory_thread.cpp
index fb2559a..d4b3566 100644
--- a/src/plugins/robot-memory/robot_memory_thread.cpp
+++ b/src/plugins/robot-memory/robot_memory_thread.cpp
@@ -60,7 +60,7 @@ RobotMemoryThread::init()
   robot_memory_inifin_.set_robot_memory(robot_memory);
 
   //register computables
-  blackboard_computable = new BlackboardComputable(robot_memory, blackboard, logger);
+  blackboard_computable = new BlackboardComputable(robot_memory, blackboard, logger, config);
   transform_computable = new TransformComputable(robot_memory, tf_listener, logger, config);
 }
 




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list