26
26
#include " nav2_behavior_tree/utils/test_action_server.hpp"
27
27
#include " nav2_behavior_tree/plugins/decorator/goal_updater_node.hpp"
28
28
29
+ typedef std::vector<geometry_msgs::msg::PoseStamped> Goals;
29
30
30
31
class GoalUpdaterTestFixture : public ::testing::Test
31
32
{
@@ -88,26 +89,29 @@ TEST_F(GoalUpdaterTestFixture, test_tick)
88
89
R"(
89
90
<root BTCPP_format="4">
90
91
<BehaviorTree ID="MainTree">
91
- <GoalUpdater input_goal="{goal}" output_goal="{updated_goal}">
92
+ <GoalUpdater input_goal="{goal}" input_goals="{goals}" output_goal="{updated_goal}" output_goals="{updated_goals }">
92
93
<AlwaysSuccess/>
93
94
</GoalUpdater>
94
95
</BehaviorTree>
95
96
</root>)" ;
96
97
97
98
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText (xml_txt, config_->blackboard ));
98
- auto goal_updater_pub =
99
- node_->create_publisher <geometry_msgs::msg::PoseStamped>(" goal_update" , 10 );
100
99
101
100
// create new goal and set it on blackboard
102
101
geometry_msgs::msg::PoseStamped goal;
102
+ Goals goals;
103
103
goal.header .stamp = node_->now ();
104
104
goal.pose .position .x = 1.0 ;
105
+ goals.push_back (goal);
105
106
config_->blackboard ->set (" goal" , goal);
107
+ config_->blackboard ->set (" goals" , goals);
106
108
107
109
// tick tree without publishing updated goal and get updated_goal
108
110
tree_->rootNode ()->executeTick ();
109
111
geometry_msgs::msg::PoseStamped updated_goal;
112
+ Goals updated_goals;
110
113
EXPECT_TRUE (config_->blackboard ->get (" updated_goal" , updated_goal));
114
+ EXPECT_TRUE (config_->blackboard ->get (" updated_goals" , updated_goals));
111
115
}
112
116
113
117
TEST_F (GoalUpdaterTestFixture, test_older_goal_update)
@@ -117,7 +121,7 @@ TEST_F(GoalUpdaterTestFixture, test_older_goal_update)
117
121
R"(
118
122
<root BTCPP_format="4">
119
123
<BehaviorTree ID="MainTree">
120
- <GoalUpdater input_goal="{goal}" output_goal="{updated_goal}">
124
+ <GoalUpdater input_goal="{goal}" input_goals="{goals}" output_goal="{updated_goal}" output_goals="{updated_goals }">
121
125
<AlwaysSuccess/>
122
126
</GoalUpdater>
123
127
</BehaviorTree>
@@ -126,26 +130,38 @@ TEST_F(GoalUpdaterTestFixture, test_older_goal_update)
126
130
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText (xml_txt, config_->blackboard ));
127
131
auto goal_updater_pub =
128
132
node_->create_publisher <geometry_msgs::msg::PoseStamped>(" goal_update" , 10 );
133
+ auto goals_updater_pub =
134
+ node_->create_publisher <nav2_msgs::msg::PoseStampedArray>(" goals_update" , 10 );
129
135
130
136
// create new goal and set it on blackboard
131
137
geometry_msgs::msg::PoseStamped goal;
138
+ Goals goals;
132
139
goal.header .stamp = node_->now ();
133
140
goal.pose .position .x = 1.0 ;
141
+ goals.push_back (goal);
134
142
config_->blackboard ->set (" goal" , goal);
143
+ config_->blackboard ->set (" goals" , goals);
135
144
136
145
// publish updated_goal older than goal
137
146
geometry_msgs::msg::PoseStamped goal_to_update;
147
+ nav2_msgs::msg::PoseStampedArray goals_to_update;
138
148
goal_to_update.header .stamp = rclcpp::Time (goal.header .stamp ) - rclcpp::Duration (1 , 0 );
139
149
goal_to_update.pose .position .x = 2.0 ;
150
+ goals_to_update.header .stamp = goal_to_update.header .stamp ;
151
+ goals_to_update.poses .push_back (goal_to_update);
140
152
141
153
goal_updater_pub->publish (goal_to_update);
154
+ goals_updater_pub->publish (goals_to_update);
142
155
tree_->rootNode ()->executeTick ();
143
156
geometry_msgs::msg::PoseStamped updated_goal;
157
+ Goals updated_goals;
144
158
EXPECT_TRUE (config_->blackboard ->get (" updated_goal" , updated_goal));
159
+ EXPECT_TRUE (config_->blackboard ->get (" updated_goals" , updated_goals));
145
160
146
161
// expect to succeed and not update goal
147
162
EXPECT_EQ (tree_->rootNode ()->status (), BT::NodeStatus::SUCCESS);
148
163
EXPECT_EQ (updated_goal, goal);
164
+ EXPECT_EQ (updated_goals, goals);
149
165
}
150
166
151
167
TEST_F (GoalUpdaterTestFixture, test_get_latest_goal_update)
@@ -155,7 +171,7 @@ TEST_F(GoalUpdaterTestFixture, test_get_latest_goal_update)
155
171
R"(
156
172
<root BTCPP_format="4">
157
173
<BehaviorTree ID="MainTree">
158
- <GoalUpdater input_goal="{goal}" output_goal="{updated_goal}">
174
+ <GoalUpdater input_goal="{goal}" input_goals="{goals}" output_goal="{updated_goal}" output_goals="{updated_goals }">
159
175
<AlwaysSuccess/>
160
176
</GoalUpdater>
161
177
</BehaviorTree>
@@ -164,32 +180,48 @@ TEST_F(GoalUpdaterTestFixture, test_get_latest_goal_update)
164
180
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText (xml_txt, config_->blackboard ));
165
181
auto goal_updater_pub =
166
182
node_->create_publisher <geometry_msgs::msg::PoseStamped>(" goal_update" , 10 );
183
+ auto goals_updater_pub =
184
+ node_->create_publisher <nav2_msgs::msg::PoseStampedArray>(" goals_update" , 10 );
167
185
168
186
// create new goal and set it on blackboard
169
187
geometry_msgs::msg::PoseStamped goal;
188
+ Goals goals;
170
189
goal.header .stamp = node_->now ();
171
190
goal.pose .position .x = 1.0 ;
191
+ goals.push_back (goal);
172
192
config_->blackboard ->set (" goal" , goal);
193
+ config_->blackboard ->set (" goals" , goals);
173
194
174
195
// publish updated_goal older than goal
175
196
geometry_msgs::msg::PoseStamped goal_to_update_1;
197
+ nav2_msgs::msg::PoseStampedArray goals_to_update_1;
176
198
goal_to_update_1.header .stamp = node_->now ();
177
199
goal_to_update_1.pose .position .x = 2.0 ;
200
+ goals_to_update_1.header .stamp = goal_to_update_1.header .stamp ;
201
+ goals_to_update_1.poses .push_back (goal_to_update_1);
178
202
179
203
geometry_msgs::msg::PoseStamped goal_to_update_2;
204
+ nav2_msgs::msg::PoseStampedArray goals_to_update_2;
180
205
goal_to_update_2.header .stamp = node_->now ();
181
206
goal_to_update_2.pose .position .x = 3.0 ;
207
+ goals_to_update_2.header .stamp = goal_to_update_2.header .stamp ;
208
+ goals_to_update_2.poses .push_back (goal_to_update_2);
182
209
183
210
goal_updater_pub->publish (goal_to_update_1);
211
+ goals_updater_pub->publish (goals_to_update_1);
184
212
goal_updater_pub->publish (goal_to_update_2);
213
+ goals_updater_pub->publish (goals_to_update_2);
185
214
tree_->rootNode ()->executeTick ();
186
215
geometry_msgs::msg::PoseStamped updated_goal;
216
+ Goals updated_goals;
187
217
EXPECT_TRUE (config_->blackboard ->get (" updated_goal" , updated_goal));
218
+ EXPECT_TRUE (config_->blackboard ->get (" updated_goals" , updated_goals));
188
219
189
220
// expect to succeed
190
221
EXPECT_EQ (tree_->rootNode ()->status (), BT::NodeStatus::SUCCESS);
191
222
// expect to update goal with latest goal update
192
223
EXPECT_EQ (updated_goal, goal_to_update_2);
224
+ EXPECT_EQ (updated_goals, goals_to_update_2.poses );
193
225
}
194
226
195
227
int main (int argc, char ** argv)
0 commit comments