Changes have been pushed for the repository "fawkesrobotics/fawkes".

Clone:  https://github.com/fawkesrobotics/fawkes.git
Gitweb: https://github.com/fawkesrobotics/fawkes

The branch, common/gologpp has been updated
        to  cea775521d3809604a4a6f1bb63ac0f895100020 (commit)
      from  18eecd25e0cb6ad35c3c08172b4cd373829d31ab (commit)

https://github.com/fawkesrobotics/fawkes/tree/common/gologpp

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 cea775521d3809604a4a6f1bb63ac0f895100020
Author:     Till Hofmann <hofm...@kbsg.rwth-aachen.de>
AuthorDate: Thu Oct 3 12:10:13 2019 +0200
Commit:     Till Hofmann <hofm...@kbsg.rwth-aachen.de>
CommitDate: Thu Oct 3 12:17:18 2019 +0200

    gologpp: implement action dispatcher to allow other action types
    
    Restructure action execution so we can have a number of different action
    executors (e.g., skills, communication). Each executor implements a
    function that checks whether the executor is capable of executing a
    given activity. The dispatcher iterates over all registered executors
    and gives the activity to the first executor that is able to execute the
    activity.
    
    The executor is expected to be initialized once (e.g., by opening the
    necessary blackboard interfaces) and it should be able to subsequently
    execute multiple activities, i.e., we do not create a new executor for
    every activity, but only for every type of activity.
    
    Currently, only the SkillerActionExecutor is implemented, which executes
    an activity using the skiller. Additional executors can be implemented
    by inheriting from the abstract ActionExecutor and registering the
    executor with the dispatcher.

https://github.com/fawkesrobotics/fawkes/commit/cea775521

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


- *Summary* -----------------------------------------------------------
 src/plugins/gologpp/Makefile                       |   3 +-
 src/plugins/gologpp/action_executor.cpp            |  59 +++++++
 .../{mongodb/utils.h => gologpp/action_executor.h} |  38 +++--
 src/plugins/gologpp/action_executor_dispatcher.cpp |  61 +++++++
 .../action_executor_dispatcher.h}                  |  24 ++-
 src/plugins/gologpp/gologpp_fawkes_backend.cpp     | 101 ++----------
 src/plugins/gologpp/gologpp_fawkes_backend.h       |  10 +-
 ...kes_backend.cpp => skiller_action_executor.cpp} | 181 ++++++++++-----------
 src/plugins/gologpp/skiller_action_executor.h      |  63 +++++++
 9 files changed, 329 insertions(+), 211 deletions(-)
 create mode 100644 src/plugins/gologpp/action_executor.cpp
 copy src/plugins/{mongodb/utils.h => gologpp/action_executor.h} (50%)
 create mode 100644 src/plugins/gologpp/action_executor_dispatcher.cpp
 copy src/plugins/{skiller-simulator/skiller_simulator_plugin.h => 
gologpp/action_executor_dispatcher.h} (56%)
 copy src/plugins/gologpp/{gologpp_fawkes_backend.cpp => 
skiller_action_executor.cpp} (57%)
 create mode 100644 src/plugins/gologpp/skiller_action_executor.h


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

- *commit* cea775521d3809604a4a6f1bb63ac0f895100020 - - - - - - - - - -
Author:  Till Hofmann <hofm...@kbsg.rwth-aachen.de>
Date:    Thu Oct 3 12:10:13 2019 +0200
Subject: gologpp: implement action dispatcher to allow other action types

 src/plugins/gologpp/Makefile                       |   3 +-
 src/plugins/gologpp/action_executor.cpp            |  59 +++++++
 .../{mongodb/utils.h => gologpp/action_executor.h} |  38 +++--
 src/plugins/gologpp/action_executor_dispatcher.cpp |  61 +++++++
 .../action_executor_dispatcher.h}                  |  24 ++-
 src/plugins/gologpp/gologpp_fawkes_backend.cpp     | 101 ++----------
 src/plugins/gologpp/gologpp_fawkes_backend.h       |  10 +-
 ...kes_backend.cpp => skiller_action_executor.cpp} | 181 ++++++++++-----------
 src/plugins/gologpp/skiller_action_executor.h      |  63 +++++++
 9 files changed, 329 insertions(+), 211 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/gologpp/Makefile b/src/plugins/gologpp/Makefile
index 9d939481c..b87a45f10 100644
--- a/src/plugins/gologpp/Makefile
+++ b/src/plugins/gologpp/Makefile
@@ -17,7 +17,8 @@ include $(BASEDIR)/etc/buildsys/config.mk
 
 LIBS_gologpp = fawkescore fawkesutils fawkesblackboard \
            fawkesinterface SkillerInterface
-OBJS_gologpp = plugin.o execution_thread.o gologpp_fawkes_backend.o 
exog_manager.o
+OBJS_gologpp = plugin.o execution_thread.o gologpp_fawkes_backend.o 
exog_manager.o \
+                                                        action_executor.o 
skiller_action_executor.o action_executor_dispatcher.o
 
 OBJS_all    = $(OBJS_gologpp)
 PLUGINS_all = $(PLUGINDIR)/gologpp.so
diff --git a/src/plugins/gologpp/gologpp_fawkes_backend.cpp 
b/src/plugins/gologpp/gologpp_fawkes_backend.cpp
index ede98d4e7..7228572c0 100644
--- a/src/plugins/gologpp/gologpp_fawkes_backend.cpp
+++ b/src/plugins/gologpp/gologpp_fawkes_backend.cpp
@@ -21,11 +21,10 @@
 
 #include "gologpp_fawkes_backend.h"
 
+#include "skiller_action_executor.h"
+
 #include <golog++/model/activity.h>
 #include <golog++/model/transition.h>
-#include <interfaces/SkillerInterface.h>
-
-#include <sstream>
 
 namespace fawkes_gpp {
 
@@ -54,28 +53,12 @@ GologppFawkesBackend::GologppFawkesBackend(GologppThread 
*main_thread,
   logger_(logger),
   blackboard_(blackboard)
 {
-       try {
-               skiller_if_ = 
blackboard_->open_for_reading<SkillerInterface>("Skiller");
-       } catch (Exception &e) {
-               logger_->log_error(name(), "Failed to open skiller interface: 
%s", e.what_no_backtrace());
-       }
-       bbil_add_data_interface(skiller_if_);
-       blackboard_->register_listener(this, BlackBoard::BBIL_FLAG_DATA);
-       skiller_if_->read();
-       if (!skiller_if_->has_writer()) {
-               blackboard->unregister_listener(this);
-               blackboard->close(skiller_if_);
-               throw Exception("No writer for Skiller interface");
-       }
-       skiller_if_->msgq_enqueue(new 
SkillerInterface::AcquireControlMessage());
-       initialize_action_skill_mapping();
+       action_dispatcher_.register_executor(
+         std::make_shared<SkillerActionExecutor>(logger, blackboard, config));
 }
 
 GologppFawkesBackend::~GologppFawkesBackend()
 {
-       skiller_if_->msgq_enqueue(new 
SkillerInterface::ReleaseControlMessage());
-       blackboard_->unregister_listener(this);
-       blackboard_->close(skiller_if_);
 }
 
 /** Preempt the currently running activity.
@@ -107,84 +90,20 @@ GologppFawkesBackend::time() const noexcept
 void
 GologppFawkesBackend::execute_activity(shared_ptr<Activity> a)
 {
-       if (running_activity_) {
-               stop_running_activity();
-       }
-
-       std::string skill_string{map_activity_to_skill(a)};
-       skiller_if_->msgq_enqueue(new 
SkillerInterface::ExecSkillMessage(skill_string.c_str()));
+       stop_running_activity();
+       auto executor = action_dispatcher_.get_executor(a);
+       executor->start(a);
        running_activity_ = a;
 }
 
 void
 GologppFawkesBackend::stop_running_activity()
 {
-       skiller_if_->msgq_enqueue(new SkillerInterface::StopExecMessage());
-       running_activity_.reset();
-}
-
-void
-GologppFawkesBackend::bb_interface_data_changed(Interface *iface) throw()
-{
-       if (!running_activity_) {
-               return;
-       }
-       SkillerInterface *skiller_if = dynamic_cast<SkillerInterface *>(iface);
-       if (!skiller_if) {
-               return;
-       }
-       skiller_if->read();
-       switch (skiller_if->status()) {
-       case SkillerInterface::S_FINAL:
-               running_activity_->update(Transition::Hook::FINISH);
+       if (running_activity_) {
+               auto executor = 
action_dispatcher_.get_executor(running_activity_);
+               executor->stop(running_activity_);
                running_activity_.reset();
-               break;
-       case SkillerInterface::S_FAILED: 
running_activity_->update(Transition::Hook::FAIL); break;
-       case SkillerInterface::S_RUNNING: 
running_activity_->update(Transition::Hook::START); break;
-       default: break;
-       }
-}
-
-std::string
-GologppFawkesBackend::map_activity_to_skill(std::shared_ptr<Activity> activity)
-{
-       std::map<std::string, std::string> params;
-       for (auto &arg : activity->target()->mapping().arg_mapping()) {
-               params[arg.first] = 
activity->mapped_arg_value(arg.first).to_string("");
-       }
-       std::multimap<std::string, std::string> messages;
-       if (!action_skill_mapping_.has_mapping(activity->mapped_name())) {
-               throw Exception(std::string("No mapping for action " + 
activity->mapped_name()).c_str());
-       }
-       auto mapping{action_skill_mapping_.map_skill(activity->mapped_name(), 
params, messages)};
-       for (auto m = messages.find("ERROR"); m != messages.end();) {
-               logger_->log_error(name(),
-                                  "Error occurred while mapping action '%s': 
%s",
-                                  activity->mapped_name().c_str(),
-                                  m->second.c_str());
-       }
-       for (auto m = messages.find("WARNING"); m != messages.end();) {
-               logger_->log_warn(name(),
-                                 "Warning occurred while mapping action '%s': 
%s",
-                                 activity->mapped_name().c_str(),
-                                 m->second.c_str());
-       }
-       return mapping;
-}
-
-void
-GologppFawkesBackend::initialize_action_skill_mapping()
-{
-       // TODO: use const for config prefix
-       std::string                        action_mapping_cfg_path = 
"/plugins/gologpp/action-mapping/";
-       auto                               
cfg_iterator{config_->search(action_mapping_cfg_path)};
-       std::map<std::string, std::string> mapping;
-       while (cfg_iterator->next()) {
-               std::string action_name{
-                 
std::string(cfg_iterator->path()).substr(action_mapping_cfg_path.length())};
-               mapping[action_name] = cfg_iterator->get_as_string();
        }
-       action_skill_mapping_ = ActionSkillMapping(mapping);
 }
 
 const char *
diff --git a/src/plugins/gologpp/gologpp_fawkes_backend.h 
b/src/plugins/gologpp/gologpp_fawkes_backend.h
index 0b3047012..619a538cf 100644
--- a/src/plugins/gologpp/gologpp_fawkes_backend.h
+++ b/src/plugins/gologpp/gologpp_fawkes_backend.h
@@ -22,14 +22,14 @@
 #ifndef FAWKES_GOLOGPP_FAWKES_BACKEND_H_
 #define FAWKES_GOLOGPP_FAWKES_BACKEND_H_
 
+#include "action_executor.h"
+#include "action_executor_dispatcher.h"
 #include "execution_thread.h"
 
 #include <aspect/clock.h>
-#include <blackboard/interface_listener.h>
 #include <config/config.h>
 #include <golog++/model/platform_backend.h>
 #include <logging/logger.h>
-#include <utils/misc/map_skill.h>
 
 namespace fawkes {
 class SkillerInterface;
@@ -51,14 +51,10 @@ public:
        virtual void preempt_activity(std::shared_ptr<gologpp::Transition> t) 
override;
        virtual gologpp::Clock::time_point time() const noexcept override;
 
-       virtual void bb_interface_data_changed(fawkes::Interface *) throw() 
override;
-
 private:
        virtual void execute_activity(std::shared_ptr<gologpp::Activity>) 
override;
        void         stop_running_activity();
-       void         initialize_action_skill_mapping();
        const char * name();
-       std::string  map_activity_to_skill(std::shared_ptr<gologpp::Activity> 
activity);
 
        GologppThread *                    main_thread_;
        fawkes::SkillerInterface *         skiller_if_;
@@ -66,7 +62,7 @@ private:
        fawkes::Logger *                   logger_;
        fawkes::BlackBoard *               blackboard_;
        std::shared_ptr<gologpp::Activity> running_activity_;
-       fawkes::ActionSkillMapping         action_skill_mapping_;
+       ActionExecutorDispatcher           action_dispatcher_;
 };
 
 } // namespace fawkes_gpp



_______________________________________________
fawkes-commits mailing list
fawkes-commits@lists.kbsg.rwth-aachen.de
https://lists.kbsg.rwth-aachen.de/listinfo/fawkes-commits

Reply via email to