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)
157
157
158
158
return 0 ;
159
159
}
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
64
64
class TestNode : public BT ::StatefulActionNode
65
65
{
66
66
public:
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);
73
68
74
69
static PortsList providedPorts ()
75
70
{
76
71
return {};
77
72
}
78
73
79
- void setConfig (const TestNodeConfig& config);
80
-
81
- private:
74
+ protected:
82
75
virtual NodeStatus onStart () override ;
83
76
84
77
virtual NodeStatus onRunning () override ;
Original file line number Diff line number Diff line change 1
1
#include " behaviortree_cpp/actions/test_node.h"
2
2
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))
4
6
{
5
- if (config.return_status == NodeStatus::IDLE)
7
+ setRegistrationID (" TestNode" );
8
+
9
+ if (_test_config.return_status == NodeStatus::IDLE)
6
10
{
7
11
throw RuntimeError (" TestNode can not return IDLE" );
8
12
}
9
- _test_config = config;
10
13
11
14
auto prepareScript = [](const std::string& script, auto & executor) {
12
15
if (!script.empty ())
@@ -19,9 +22,9 @@ void BT::TestNode::setConfig(const TestNodeConfig& config)
19
22
executor = result.value ();
20
23
}
21
24
};
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);
25
28
}
26
29
27
30
BT::NodeStatus BT::TestNode::onStart ()
Original file line number Diff line number Diff line change @@ -334,9 +334,7 @@ std::unique_ptr<TreeNode> BehaviorTreeFactory::instantiateTreeNode(
334
334
else if (const auto test_config = std::get_if<TestNodeConfig>(&rule))
335
335
{
336
336
// 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);
340
338
node.reset (test_node);
341
339
substituted = true ;
342
340
break ;
You can’t perform that action at this time.
0 commit comments