Go to the documentation of this file. 1 #include <gtest/gtest.h>
39 getInput(
"color",
color);
40 std::cout <<
"Node: " << name() <<
" has color : " <<
ToStr(
color) << std::endl;
46 return { BT::InputPort<Color>(
"color") };
54 std::string xml_txt = R
"(
55 <root BTCPP_format="4" >
56 <BehaviorTree ID="Main">
58 <Script code=" my_color := Red "/>
59 <ActionEnum name="maybe_blue" color="Blue"/>
60 <ActionEnum name="maybe_green" color="2"/>
61 <ActionEnum name="maybe_red" color="{my_color}"/>
76 for(
const auto& node : tree.subtrees.front()->nodes)
78 if(
auto enum_node =
dynamic_cast<ActionEnum*
>(node.get()))
80 if(enum_node->name() ==
"maybe_red")
84 else if(enum_node->name() ==
"maybe_green")
88 else if(enum_node->name() ==
"maybe_blue")
96 TEST(Enums, SwitchNodeWithEnum)
98 const std::string xml_txt = R
"(
99 <root BTCPP_format="4" >
100 <BehaviorTree ID="Main">
102 <Script code=" my_color := Blue "/>
103 <Switch4 variable="{my_color}"
108 <AlwaysFailure name="case_red" />
109 <AlwaysSuccess name="case_blue" />
110 <AlwaysFailure name="case_green" />
111 <AlwaysFailure name="case_undefined" />
112 <AlwaysFailure name="default_case" />
146 BT::InputPort<BatteryStatus>(
"enum",
"Name of the check"),
153 auto enum_value = getInput<BatteryStatus>(
"enum");
156 std::cout <<
"missing required input [enum]" << std::endl;
176 return { BT::InputPort<std::string>(
"check_name"), BT::InputPort<bool>(
"health") };
182 auto health = getInput<bool>(
"health");
185 std::cout <<
"missing required input [health]" << std::endl;
195 std::cerr <<
"IsHealthOk FAILED " << std::endl;
204 const std::string xml_txt = R
"(
205 <root BTCPP_format="4" >
206 <BehaviorTree ID="MainTree">
208 <Script code=" fault_status := NO_FAULT " />
209 <PrintEnum enum="{fault_status}"/>
211 <SubTree ID="FailsafeCheck"
213 trigger_fault_status="LOW_BATTERY"
214 fault_status="{=}" />
216 <PrintEnum enum="{fault_status}"/>
220 <BehaviorTree ID="FailsafeCheck">
224 _onFailure="fault_status = trigger_fault_status"/>
static BT::PortsList providedPorts()
Tree createTree(const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
static const char * ToStr(const Color &c)
NodeStatus tick() override
Method to be implemented by the user.
TEST(Enums, StrintToEnum)
NodeStatus tickWhileRunning(std::chrono::milliseconds sleep_time=std::chrono::milliseconds(10))
IsHealthOk(const std::string &name, const BT::NodeConfig &config)
std::unordered_map< std::string, PortInfo > PortsList
BT::NodeStatus tick() override
Method to be implemented by the user.
void registerNodeType(const std::string &ID, const PortsList &ports, ExtraArgs... args)
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
createTreeFromText will parse the XML directly from string. The XML needs to contain either a single ...
constexpr auto enum_value(std::size_t index) noexcept -> detail::enable_if_t< E, std::decay_t< E >>
PrintEnum(const std::string &name, const BT::NodeConfig &config)
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
ActionEnum(const std::string &name, const NodeConfig &config)
void registerBehaviorTreeFromText(const std::string &xml_text)
BT::NodeStatus tick() override
Method to be implemented by the user.
static BT::PortsList providedPorts()
static PortsList providedPorts()
void registerScriptingEnums()
registerScriptingEnums is syntactic sugar to automatically register multiple enums....
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...