2
3
4
5
6
7
8
9
10
11
13#ifndef ACTION_SETBLACKBOARD_NODE_H
14#define ACTION_SETBLACKBOARD_NODE_H
16#include "behaviortree_cpp/action_node.h"
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
39 SetBlackboardNode(
const std::string& name,
const NodeConfig& config)
42 setRegistrationID(
"SetBlackboard");
45 static PortsList providedPorts()
47 return { InputPort(
"value",
"Value to be written into the output_key"),
48 BidirectionalPort(
"output_key",
"Name of the blackboard entry where the "
49 "value should be written") };
55 std::string output_key;
56 if(!getInput(
"output_key", output_key))
58 throw RuntimeError(
"missing port [output_key]");
61 const std::string value_str = config().input_ports.at(
"value");
63 StringView stripped_key;
67 config().blackboard->getEntry(output_key);
69 if(isBlackboardPointer(value_str, &stripped_key))
71 const auto input_key = std::string(stripped_key);
73 config().blackboard->getEntry(input_key);
77 throw RuntimeError(
"Can't find the port referred by [value]");
81 config().blackboard->createEntry(output_key, src_entry->info);
82 dst_entry = config().blackboard->getEntry(output_key);
85 out_value = src_entry->value;
89 out_value =
BT::
Any(value_str);
97 if(dst_entry && dst_entry->info.type() !=
typeid(std::string) && out_value.isString())
101 out_value = dst_entry->info.parseString(out_value.cast<std::string>());
103 catch(
const std::exception& e)
105 throw LogicError(
"Can't convert string [", out_value.cast<std::string>(),
106 "] to type [", BT::demangle(dst_entry->info.type()),
111 config().blackboard->set(output_key, out_value);
Definition: safe_any.hpp:50
The Blackboard is the mechanism used by BehaviorTrees to exchange typed data.
Definition: blackboard.h:35
The SetBlackboard is action used to store a string into an entry of the Blackboard specified in "outp...
Definition: set_blackboard_node.h:37
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
Definition: action_node.h:57
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34
Definition: blackboard.h:51
Definition: tree_node.h:105