@@ -95,42 +95,101 @@ TEST_F(GoalUpdaterTestFixture, test_tick)
95
95
</root>)" ;
96
96
97
97
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 );
98
100
99
101
// create new goal and set it on blackboard
100
102
geometry_msgs::msg::PoseStamped goal;
101
103
goal.header .stamp = node_->now ();
102
104
goal.pose .position .x = 1.0 ;
103
105
config_->blackboard ->set (" goal" , goal);
104
106
105
- // tick until node succeeds
106
- while (tree_->rootNode ()->status () != BT::NodeStatus::SUCCESS) {
107
- tree_->rootNode ()->executeTick ();
108
- }
109
-
107
+ // tick tree without publishing updated goal and get updated_goal
108
+ tree_->rootNode ()->executeTick ();
110
109
geometry_msgs::msg::PoseStamped updated_goal;
111
110
config_->blackboard ->get (" updated_goal" , updated_goal);
111
+ }
112
112
113
- EXPECT_EQ (updated_goal, goal);
113
+ TEST_F (GoalUpdaterTestFixture, test_older_goal_update)
114
+ {
115
+ // create tree
116
+ std::string xml_txt =
117
+ R"(
118
+ <root main_tree_to_execute = "MainTree" >
119
+ <BehaviorTree ID="MainTree">
120
+ <GoalUpdater input_goal="{goal}" output_goal="{updated_goal}">
121
+ <AlwaysSuccess/>
122
+ </GoalUpdater>
123
+ </BehaviorTree>
124
+ </root>)" ;
125
+
126
+ tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText (xml_txt, config_->blackboard ));
127
+ auto goal_updater_pub =
128
+ node_->create_publisher <geometry_msgs::msg::PoseStamped>(" goal_update" , 10 );
129
+
130
+ // create new goal and set it on blackboard
131
+ geometry_msgs::msg::PoseStamped goal;
132
+ goal.header .stamp = node_->now ();
133
+ goal.pose .position .x = 1.0 ;
134
+ config_->blackboard ->set (" goal" , goal);
114
135
136
+ // publish updated_goal older than goal
115
137
geometry_msgs::msg::PoseStamped goal_to_update;
116
- goal_to_update.header .stamp = node_-> now ( );
138
+ goal_to_update.header .stamp = rclcpp::Time (goal. header . stamp ) - rclcpp::Duration ( 1 , 0 );
117
139
goal_to_update.pose .position .x = 2.0 ;
118
140
141
+ goal_updater_pub->publish (goal_to_update);
142
+ tree_->rootNode ()->executeTick ();
143
+ geometry_msgs::msg::PoseStamped updated_goal;
144
+ config_->blackboard ->get (" updated_goal" , updated_goal);
145
+
146
+ // expect to succeed and not update goal
147
+ EXPECT_EQ (tree_->rootNode ()->status (), BT::NodeStatus::SUCCESS);
148
+ EXPECT_EQ (updated_goal, goal);
149
+ }
150
+
151
+ TEST_F (GoalUpdaterTestFixture, test_get_latest_goal_update)
152
+ {
153
+ // create tree
154
+ std::string xml_txt =
155
+ R"(
156
+ <root main_tree_to_execute = "MainTree" >
157
+ <BehaviorTree ID="MainTree">
158
+ <GoalUpdater input_goal="{goal}" output_goal="{updated_goal}">
159
+ <AlwaysSuccess/>
160
+ </GoalUpdater>
161
+ </BehaviorTree>
162
+ </root>)" ;
163
+
164
+ tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText (xml_txt, config_->blackboard ));
119
165
auto goal_updater_pub =
120
166
node_->create_publisher <geometry_msgs::msg::PoseStamped>(" goal_update" , 10 );
121
167
122
- auto start = node_->now ();
123
- while ((node_->now () - start).seconds () < 0.5 ) {
124
- tree_->rootNode ()->executeTick ();
125
- goal_updater_pub->publish (goal_to_update);
168
+ // create new goal and set it on blackboard
169
+ geometry_msgs::msg::PoseStamped goal;
170
+ goal.header .stamp = node_->now ();
171
+ goal.pose .position .x = 1.0 ;
172
+ config_->blackboard ->set (" goal" , goal);
126
173
127
- rclcpp::spin_some (node_);
128
- }
174
+ // publish updated_goal older than goal
175
+ geometry_msgs::msg::PoseStamped goal_to_update_1;
176
+ goal_to_update_1.header .stamp = node_->now ();
177
+ goal_to_update_1.pose .position .x = 2.0 ;
178
+
179
+ geometry_msgs::msg::PoseStamped goal_to_update_2;
180
+ goal_to_update_2.header .stamp = node_->now ();
181
+ goal_to_update_2.pose .position .x = 3.0 ;
129
182
183
+ goal_updater_pub->publish (goal_to_update_1);
184
+ goal_updater_pub->publish (goal_to_update_2);
185
+ tree_->rootNode ()->executeTick ();
186
+ geometry_msgs::msg::PoseStamped updated_goal;
130
187
config_->blackboard ->get (" updated_goal" , updated_goal);
131
188
132
- EXPECT_NE (updated_goal, goal);
133
- EXPECT_EQ (updated_goal, goal_to_update);
189
+ // expect to succeed
190
+ EXPECT_EQ (tree_->rootNode ()->status (), BT::NodeStatus::SUCCESS);
191
+ // expect to update goal with latest goal update
192
+ EXPECT_EQ (updated_goal, goal_to_update_2);
134
193
}
135
194
136
195
int main (int argc, char ** argv)
0 commit comments