@@ -147,6 +147,15 @@ class FollowPath: public CoroActionNode, public TestNode
147
147
148
148
// -------------------------------------
149
149
150
+ template <typename Original, typename Casted>
151
+ void TryDynamicCastPtr (Original* ptr, Casted*& destination)
152
+ {
153
+ if ( dynamic_cast <Casted*>(ptr) )
154
+ {
155
+ destination = dynamic_cast <Casted*>(ptr);
156
+ }
157
+ }
158
+
150
159
/* ***************TESTS START HERE***************************/
151
160
152
161
TEST (Navigationtest, MoveBaseReocvery)
@@ -160,6 +169,8 @@ TEST(Navigationtest, MoveBaseReocvery)
160
169
161
170
auto tree = buildTreeFromText (factory, xml_text);
162
171
172
+ // Need to retrieve the node pointers with dynamic cast
173
+ // In a normal application you would NEVER want to do such a thing.
163
174
IsStuck *first_stuck_node = nullptr ;
164
175
IsStuck *second_stuck_node = nullptr ;
165
176
BackUpAndSpin* back_spin_node = nullptr ;
@@ -169,25 +180,17 @@ TEST(Navigationtest, MoveBaseReocvery)
169
180
for (auto & node: tree.nodes )
170
181
{
171
182
auto ptr = node.get ();
172
- if ( dynamic_cast <IsStuck*>(ptr) )
183
+
184
+ if ( !first_stuck_node )
173
185
{
174
- if ( !first_stuck_node )
175
- {
176
- first_stuck_node = dynamic_cast <IsStuck*>(ptr);
177
- }
178
- else {
179
- second_stuck_node = dynamic_cast <IsStuck*>(ptr);
180
- }
181
- }
182
- else if ( dynamic_cast <BackUpAndSpin*>(ptr) ){
183
- back_spin_node = dynamic_cast <BackUpAndSpin*>(ptr);
184
- }
185
- else if ( dynamic_cast <ComputePathToPose*>(ptr) ){
186
- compute_node = dynamic_cast <ComputePathToPose*>(ptr);
186
+ TryDynamicCastPtr (ptr, first_stuck_node);
187
187
}
188
- else if ( dynamic_cast <FollowPath*>(ptr) ) {
189
- follow_node = dynamic_cast <FollowPath*> (ptr);
188
+ else {
189
+ TryDynamicCastPtr (ptr, second_stuck_node );
190
190
}
191
+ TryDynamicCastPtr (ptr, back_spin_node);
192
+ TryDynamicCastPtr (ptr, follow_node);
193
+ TryDynamicCastPtr (ptr, compute_node);
191
194
}
192
195
193
196
ASSERT_TRUE ( first_stuck_node );
@@ -196,15 +199,15 @@ TEST(Navigationtest, MoveBaseReocvery)
196
199
ASSERT_TRUE ( compute_node );
197
200
ASSERT_TRUE ( follow_node );
198
201
202
+ std::cout << " -----------------------" << std::endl;
203
+
204
+ // First case: not stuck, everything fine.
199
205
NodeStatus status = NodeStatus::IDLE;
200
206
201
207
auto deadline = Now () + Milliseconds (100 );
202
208
203
209
first_stuck_node->setExpectedResult (false );
204
210
205
- std::cout << " -----------------------" << std::endl;
206
- // First case: not stuck, everything fine.
207
-
208
211
while ( status == NodeStatus::IDLE || status == NodeStatus::RUNNING )
209
212
{
210
213
status = tree.root_node ->executeTick ();
@@ -225,19 +228,23 @@ TEST(Navigationtest, MoveBaseReocvery)
225
228
ASSERT_FALSE ( follow_node->wasHalted () );
226
229
227
230
std::cout << " -----------------------" << std::endl;
231
+
232
+ // Second case: get stuck after a while
233
+
234
+ // Initialize evrything first
228
235
first_stuck_node->resetTickCount ();
229
236
second_stuck_node->resetTickCount ();
230
237
compute_node->resetTickCount ();
231
238
follow_node->resetTickCount ();
232
239
back_spin_node->resetTickCount ();
233
-
234
240
status = NodeStatus::IDLE;
235
-
236
241
int cycle = 0 ;
237
242
deadline = Now () + Milliseconds (100 );
243
+
238
244
while ( status == NodeStatus::IDLE || status == NodeStatus::RUNNING )
239
245
{
240
- if ( cycle++ == 5 )
246
+ // At the fifth cycle get stucked
247
+ if ( ++cycle == 5 )
241
248
{
242
249
first_stuck_node->setExpectedResult (true );
243
250
second_stuck_node->setExpectedResult (true );
0 commit comments