@@ -37,15 +37,24 @@ Please note:
37
37
- The __ static__ method ` requiredNodeParameters() ` contains a single key/value pair.
38
38
The string "default message" is the default value.
39
39
40
- - Parameters MUST be accessed using the method __ getParam()__ .
40
+ - Parameters MUST be accessed using the method ` getParam() ` , preferably in the
41
+ ` tick() ` method, since this value may change over time.
41
42
42
- ``` c++ hl_lines="4 10 22 "
43
+ ``` c++ hl_lines="5 9 18 "
43
44
class SaySomething : public ActionNodeBase
44
45
{
45
46
public:
47
+ // There must be a constructor with this signature
46
48
SaySomething(const std::string& name, const NodeParameters& params):
47
49
ActionNodeBase(name, params) {}
48
50
51
+ // It is mandatory to define this static method.
52
+ static const NodeParameters& requiredNodeParameters()
53
+ {
54
+ static NodeParameters params = {{"message","default message"}};
55
+ return params;
56
+ }
57
+
49
58
virtual NodeStatus tick() override
50
59
{
51
60
std::string msg;
@@ -57,15 +66,7 @@ public:
57
66
std::cout << "Robot says: " << msg << std::endl;
58
67
return BT::NodeStatus::SUCCESS;
59
68
}
60
-
61
69
virtual void halt() override {}
62
-
63
- // It is mandatory to define this static method.
64
- static const NodeParameters& requiredNodeParameters()
65
- {
66
- static NodeParameters params = {{"message","default message"}};
67
- return params;
68
- }
69
70
};
70
71
```
71
72
@@ -83,19 +84,21 @@ struct Pose2D
83
84
84
85
If we want the method ` getParam() ` to be able to parse a string
85
86
and store its value into a Pose2D, we must provide our own specialization
86
- of ` convertFromString<>() ` .
87
+ of ` convertFromString<T >() ` .
87
88
88
89
In this case, we want to represent Pose2D as three real numbers separated by
89
90
semicolons.
90
91
91
- ``` c++ hl_lines="5"
92
+ ``` c++ hl_lines="6"
93
+ // use this namespace
92
94
namespace BT {
93
95
94
96
// This template specialization is needed if you want
95
97
// to AUTOMATICALLY convert a NodeParameter into a Pose2D
96
- template <> Pose2D convertFromString(const std::string& key)
98
+ template <> Pose2D BT:: convertFromString(const std::string& key)
97
99
{
98
- // Three real numbers separated by semicolons
100
+ // Three real numbers separated by semicolons.
101
+ // You may use <boost/algorithm/string/split.hpp> if you prefer
99
102
auto parts = BT::splitString(key, ';');
100
103
if( parts.size() != 3)
101
104
{
@@ -109,9 +112,11 @@ template <> Pose2D convertFromString(const std::string& key)
109
112
return output;
110
113
}
111
114
}
115
+
116
+ } // end naespace
112
117
```
113
118
114
- We now define a synchronous ActionNode called __ MoveBaseAction__ .
119
+ We now define a __ asynchronous __ ActionNode called __ MoveBaseAction__ .
115
120
116
121
The method ` getParam() ` will call the function ` convertFromString<Pose2D>() ` under the hood;
117
122
alternatively, we can use the latter directly, for instance to convert the default
@@ -139,7 +144,7 @@ public:
139
144
Pose2D goal;
140
145
if( getParam<Pose2D>("goal", goal) == false )
141
146
{
142
- auto default_goal_value = requiredNodeParameters().at("goal");
147
+ auto default_goal = requiredNodeParameters().at("goal");
143
148
goal = BT::convertFromString<Pose2D>( default_goal_value );
144
149
}
145
150
@@ -149,14 +154,15 @@ public:
149
154
halt_requested_ = false;
150
155
151
156
int count = 0;
152
- // "compute" for 250 milliseconds or until halt_requested_ is true
157
+ // "compute" for 250 milliseconds or until halt_requested_
153
158
while( !halt_requested_ && count++ < 25)
154
159
{
155
160
SleepMilliseconds(10);
156
161
}
157
162
158
163
std::cout << "[ MoveBase: FINISHED ]" << std::endl;
159
- return halt_requested_ ? NodeStatus::SUCCESS : NodeStatus::SUCCESS;
164
+ return halt_requested_ ? NodeStatus::FAILURE :
165
+ NodeStatus::SUCCESS;
160
166
}
161
167
162
168
virtual void halt() override
0 commit comments