File tree Expand file tree Collapse file tree 4 files changed +43
-18
lines changed
include/behaviortree_cpp/actions Expand file tree Collapse file tree 4 files changed +43
-18
lines changed Original file line number Diff line number Diff line change @@ -157,3 +157,34 @@ int main(int argc, char** argv)
157157
158158 return 0 ;
159159}
160+
161+ /* Expecte output:
162+
163+ ----- Nodes fullPath() -------
164+ Sequence::1
165+ talk
166+ mysub
167+ mysub/Sequence::4
168+ mysub/action_subA
169+ mysub/action_subB
170+ set_message
171+ SaySomething::8
172+ counting
173+ SaySomething::10
174+ SaySomething::11
175+ SaySomething::12
176+
177+ ------ Output (original) ------
178+ Robot says: hello world
179+ Robot says: the original message
180+ Robot says: 1
181+ Robot says: 2
182+ Robot says: 3
183+
184+ ------ Output (substituted) ------
185+ DummySaySomething: hello world
186+ DummyAction substituting node with fullPath(): mysub/action_subA
187+ DummyAction substituting node with fullPath(): mysub/action_subB
188+ Robot says: message SUBSTITUTED
189+
190+ */
Original file line number Diff line number Diff line change @@ -64,21 +64,14 @@ struct TestNodeConfig
6464class TestNode : public BT ::StatefulActionNode
6565{
6666public:
67- TestNode (const std::string& name, const NodeConfig& config,
68- TestNodeConfig test_config = {})
69- : StatefulActionNode(name, config), _test_config(std::move(test_config))
70- {
71- setRegistrationID (" TestNode" );
72- }
67+ TestNode (const std::string& name, const NodeConfig& config, TestNodeConfig test_config);
7368
7469 static PortsList providedPorts ()
7570 {
7671 return {};
7772 }
7873
79- void setConfig (const TestNodeConfig& config);
80-
81- private:
74+ protected:
8275 virtual NodeStatus onStart () override ;
8376
8477 virtual NodeStatus onRunning () override ;
Original file line number Diff line number Diff line change 11#include " behaviortree_cpp/actions/test_node.h"
22
3- void BT::TestNode::setConfig (const TestNodeConfig& config)
3+ BT::TestNode::TestNode (const std::string& name, const NodeConfig& config,
4+ TestNodeConfig test_config)
5+ : StatefulActionNode(name, config), _test_config(std::move(test_config))
46{
5- if (config.return_status == NodeStatus::IDLE)
7+ setRegistrationID (" TestNode" );
8+
9+ if (_test_config.return_status == NodeStatus::IDLE)
610 {
711 throw RuntimeError (" TestNode can not return IDLE" );
812 }
9- _test_config = config;
1013
1114 auto prepareScript = [](const std::string& script, auto & executor) {
1215 if (!script.empty ())
@@ -19,9 +22,9 @@ void BT::TestNode::setConfig(const TestNodeConfig& config)
1922 executor = result.value ();
2023 }
2124 };
22- prepareScript (config .success_script , _success_executor);
23- prepareScript (config .failure_script , _failure_executor);
24- prepareScript (config .post_script , _post_executor);
25+ prepareScript (_test_config .success_script , _success_executor);
26+ prepareScript (_test_config .failure_script , _failure_executor);
27+ prepareScript (_test_config .post_script , _post_executor);
2528}
2629
2730BT::NodeStatus BT::TestNode::onStart ()
Original file line number Diff line number Diff line change @@ -334,9 +334,7 @@ std::unique_ptr<TreeNode> BehaviorTreeFactory::instantiateTreeNode(
334334 else if (const auto test_config = std::get_if<TestNodeConfig>(&rule))
335335 {
336336 // second case, the varian is a TestNodeConfig
337- auto test_node = new TestNode (name, config);
338- test_node->setConfig (*test_config);
339-
337+ auto test_node = new TestNode (name, config, *test_config);
340338 node.reset (test_node);
341339 substituted = true ;
342340 break ;
You can’t perform that action at this time.
0 commit comments