Fawkes API
Fawkes Development Version
|
21 #include "skiller_action_executor.h"
23 #include <blackboard/blackboard.h>
24 #include <config/config.h>
25 #include <golog++/model/activity.h>
26 #include <interfaces/SkillerInterface.h>
27 #include <logging/logger.h>
32 using gologpp::Transition;
44 va_start(args, format);
74 const std::string &cfg_prefix)
77 blackboard_(blackboard),
78 blackboard_owner_(false),
80 cfg_prefix_(cfg_prefix)
92 blackboard->
close(skiller_if_);
93 throw Exception(
"No writer for Skiller interface");
96 initialize_action_skill_mapping();
100 SkillerActionExecutor::initialize_action_skill_mapping()
102 std::string action_mapping_cfg_path = cfg_prefix_ +
"/action-mapping/";
103 auto cfg_iterator{config_->
search(action_mapping_cfg_path)};
104 std::map<std::string, std::string> mapping;
105 while (cfg_iterator->next()) {
106 std::string action_name{
107 std::string(cfg_iterator->path()).substr(action_mapping_cfg_path.length())};
108 mapping[action_name] = cfg_iterator->get_as_string();
110 action_skill_mapping_ = ActionSkillMapping(mapping);
135 return action_skill_mapping_.
has_mapping(activity->mapped_name());
146 throw Exception(
"Cannot execute activity '%s' with SkillerActionExecutor",
147 activity->mapped_name().c_str());
155 activity->update(Transition::Hook::FAIL);
178 return "SkillerActionExecutor";
182 SkillerActionExecutor::map_activity_to_skill(std::shared_ptr<gologpp::Activity> activity)
184 std::map<std::string, std::string> params;
185 for (
auto &arg : activity->target()->mapping().arg_mapping()) {
187 params[arg.first] =
static_cast<std::string
>(activity->mapped_arg_value(arg.first));
188 }
catch (boost::bad_get &e) {
189 throw InvalidArgumentException(
"Failed to cast parameter %s: %s",
194 std::multimap<std::string, std::string> messages;
195 if (!action_skill_mapping_.
has_mapping(activity->mapped_name())) {
196 throw Exception(std::string(
"No mapping for action " + activity->mapped_name()).c_str());
198 auto mapping{action_skill_mapping_.
map_skill(activity->mapped_name(), params, messages)};
199 for (
auto m = messages.find(
"ERROR"); m != messages.end();) {
200 throw InvalidArgumentException(
"Error occurred while mapping action '%s': %s",
201 activity->mapped_name().c_str(),
204 for (
auto m = messages.find(
"WARNING"); m != messages.end();) {
206 "Warning occurred while mapping action '%s': %s",
207 activity->mapped_name().c_str(),
219 if (!running_activity_) {
227 switch (skiller_if->status()) {
229 running_activity_->update(Transition::Hook::FINISH);
230 running_activity_.reset();
233 running_activity_->update(Transition::Hook::FAIL);
234 running_activity_.reset();
const char * name() const
Get the name of the executor; mainly used for logging.
@ BBIL_FLAG_DATA
consider data events
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
An exception that is thrown if the given arguments do not match the skill's arguments.
@ S_RUNNING
The execution is still running.
void read()
Read from BlackBoard into local copy.
InvalidArgumentException(const char *format,...)
Constructor.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
BlackBoard interface listener.
The BlackBoard abstract class.
BlackBoard * blackboard_
The blackboard to use to access the skiller.
@ S_FINAL
The skill string has been successfully processed.
Interface for configuration handling.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
bool has_mapping(const std::string &action_name) const
Check if mapping for an action exists.
bool can_execute_activity(std::shared_ptr< gologpp::Activity > activity) const override
Check if we can execute the given activity.
AcquireControlMessage Fawkes BlackBoard Interface Message.
ExecSkillMessage Fawkes BlackBoard Interface Message.
StopExecMessage Fawkes BlackBoard Interface Message.
virtual void close(Interface *interface)=0
Close interface.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
@ S_FAILED
The execution failed and cannot succeed anymore.
virtual ~SkillerActionExecutor() override
Destructor.
Fawkes library namespace.
std::shared_ptr< gologpp::Activity > running_activity_
A pointer to the currently running activity.
Logger * logger_
The logger to use for logging messages.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
Base class for all Fawkes BlackBoard interfaces.
bool has_writer() const
Check if there is a writer for the interface.
void start(std::shared_ptr< gologpp::Activity > activity) override
Start the given activity.
void stop(std::shared_ptr< gologpp::Grounding< gologpp::Action >> activity) override
Stop the activity if it is currently running.
SkillerInterface Fawkes BlackBoard Interface.
std::string map_skill(const std::string &name, const std::map< std::string, std::string > ¶ms, std::multimap< std::string, std::string > &messages) const
Perform mapping.
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
virtual void bb_interface_data_changed(Interface *) override
Update the status of the activity according to the Skiller status.
virtual const char * what() const
Get primary string.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
SkillerActionExecutor(Logger *logger, BlackBoard *blackboard, Configuration *config, const std::string &cfg_prefix)
Constructor.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
void bbil_add_data_interface(Interface *interface)
Add an interface to the data modification watch list.
Abstract class to execute a Golog++ activity.
void append_nolock_va(const char *format, va_list va)
Append messages without lock by formatted string.
bool blackboard_owner_
True if this executor is owning its blackboard.
Base class for exceptions in Fawkes.