1
1
#include " behaviortree_cpp/actions/test_node.h"
2
2
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))
3
+ namespace BT
4
+ {
5
+
6
+ TestNode::TestNode (const std::string& name, const NodeConfig& config,
7
+ TestNodeConfig test_config)
8
+ : TestNode(name, config, std::make_shared<TestNodeConfig>(std::move(test_config)))
9
+ {}
10
+
11
+ TestNode::TestNode (const std::string& name, const NodeConfig& config,
12
+ std::shared_ptr<TestNodeConfig> test_config)
13
+ : StatefulActionNode(name, config), _config(std::move(test_config))
6
14
{
7
15
setRegistrationID (" TestNode" );
8
16
9
- if (_test_config. return_status == NodeStatus::IDLE)
17
+ if (_config-> return_status == NodeStatus::IDLE)
10
18
{
11
19
throw RuntimeError (" TestNode can not return IDLE" );
12
20
}
@@ -22,21 +30,21 @@ BT::TestNode::TestNode(const std::string& name, const NodeConfig& config,
22
30
executor = result.value ();
23
31
}
24
32
};
25
- prepareScript (_test_config. success_script , _success_executor);
26
- prepareScript (_test_config. failure_script , _failure_executor);
27
- prepareScript (_test_config. post_script , _post_executor);
33
+ prepareScript (_config-> success_script , _success_executor);
34
+ prepareScript (_config-> failure_script , _failure_executor);
35
+ prepareScript (_config-> post_script , _post_executor);
28
36
}
29
37
30
- BT:: NodeStatus BT:: TestNode::onStart ()
38
+ NodeStatus TestNode::onStart ()
31
39
{
32
- if (_test_config. async_delay <= std::chrono::milliseconds (0 ))
40
+ if (_config-> async_delay <= std::chrono::milliseconds (0 ))
33
41
{
34
42
return onCompleted ();
35
43
}
36
44
// convert this in an asynchronous operation. Use another thread to count
37
45
// a certain amount of time.
38
46
_completed = false ;
39
- _timer.add (std::chrono::milliseconds (_test_config. async_delay ), [this ](bool aborted) {
47
+ _timer.add (std::chrono::milliseconds (_config-> async_delay ), [this ](bool aborted) {
40
48
if (!aborted)
41
49
{
42
50
_completed.store (true );
@@ -50,7 +58,7 @@ BT::NodeStatus BT::TestNode::onStart()
50
58
return NodeStatus::RUNNING;
51
59
}
52
60
53
- BT:: NodeStatus BT:: TestNode::onRunning ()
61
+ NodeStatus TestNode::onRunning ()
54
62
{
55
63
if (_completed)
56
64
{
@@ -59,17 +67,18 @@ BT::NodeStatus BT::TestNode::onRunning()
59
67
return NodeStatus::RUNNING;
60
68
}
61
69
62
- void BT:: TestNode::onHalted ()
70
+ void TestNode::onHalted ()
63
71
{
64
72
_timer.cancelAll ();
65
73
}
66
74
67
- BT:: NodeStatus BT:: TestNode::onCompleted ()
75
+ NodeStatus TestNode::onCompleted ()
68
76
{
69
77
Ast::Environment env = { config ().blackboard , config ().enums };
70
78
71
- auto status = (_test_config.complete_func ) ? _test_config.complete_func () :
72
- _test_config.return_status ;
79
+ auto status =
80
+ (_config->complete_func ) ? _config->complete_func () : _config->return_status ;
81
+
73
82
if (status == NodeStatus::SUCCESS && _success_executor)
74
83
{
75
84
_success_executor (env);
@@ -84,3 +93,5 @@ BT::NodeStatus BT::TestNode::onCompleted()
84
93
}
85
94
return status;
86
95
}
96
+
97
+ } // namespace BT
0 commit comments