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"
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
41 SetBlackboardNode(
const std::string& name,
const NodeConfig& config)
44 setRegistrationID(
"SetBlackboard");
47 static PortsList providedPorts()
49 return { InputPort(
"value",
"Value to be written into the output_key"),
50 BidirectionalPort(
"output_key",
"Name of the blackboard entry where the "
51 "value should be written") };
57 std::string output_key;
58 if(!getInput(
"output_key", output_key))
60 throw RuntimeError(
"missing port [output_key]");
63 const std::string value_str = config().input_ports.at(
"value");
65 StringView stripped_key;
69 config().blackboard->getEntry(output_key);
71 if(isBlackboardPointer(value_str, &stripped_key))
73 const auto input_key = std::string(stripped_key);
75 config().blackboard->getEntry(input_key);
79 throw RuntimeError(
"Can't find the port referred by [value]");
84 std::unique_lock src_lock(src_entry->entry_mutex);
85 out_value = src_entry->value;
86 const TypeInfo src_info = src_entry->info;
90 config().blackboard->createEntry(output_key, src_info);
91 dst_entry = config().blackboard->getEntry(output_key);
96 out_value =
BT::
Any(value_str);
104 if(dst_entry && out_value.isString())
108 std::unique_lock dst_lock(dst_entry->entry_mutex);
109 const TypeInfo dst_info = dst_entry->info;
111 if(dst_info.type() !=
typeid(std::string))
115 out_value = dst_info.parseString(out_value.cast<std::string>());
117 catch(
const std::exception& e)
119 throw LogicError(
"Can't convert string [", out_value.cast<std::string>(),
120 "] to type [",
BT::demangle(dst_info.type()),
"]: ", e.what());
125 config().blackboard->set(output_key, out_value);
Definition: safe_any.hpp:57
The Blackboard is the mechanism used by BehaviorTrees to exchange typed data.
Definition: blackboard.h:39
Definition: exceptions.h:48
The SetBlackboard is action used to store a string into an entry of the Blackboard specified in "outp...
Definition: set_blackboard_node.h:39
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
Definition: action_node.h:57
Definition: basic_types.h:377
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34
Definition: blackboard.h:55
Definition: tree_node.h:105