25
25
import org .ros .internal .node .topic .PublisherIdentifier ;
26
26
import org .ros .node .topic .DefaultSubscriberListener ;
27
27
import org .ros .message .MessageListener ;
28
+ import org .ros .message .Duration ;
29
+ import org .ros .message .Time ;
28
30
import org .ros .internal .message .Message ;
29
31
import java .util .concurrent .TimeUnit ;
30
32
import java .util .List ;
@@ -332,20 +334,37 @@ private void connect(ConnectedNode node) {
332
334
333
335
/**
334
336
* Wait for an actionlib server to connect.
337
+ * @param timeout The maximum amount of time to wait for an action server. If
338
+ * this value is less than or equal to zero, it will wait forever until a
339
+ * server is detected.
340
+ * @return True if the action server was detected before the timeout and
341
+ * false otherwise.
335
342
*/
336
- public boolean waitForActionServerToStart () {
343
+ public boolean waitForActionServerToStart (Duration timeout ) {
337
344
boolean res = false ;
345
+ boolean gotTime = true ;
346
+ Time finalTime = node .getCurrentTime ().add (timeout );
338
347
339
- while (!res ) {
348
+ while (!res && gotTime ) {
340
349
res = goalPublisher .hasSubscribers () &&
341
350
cancelPublisher .hasSubscribers () &&
342
351
feedbackPublisherFlag &&
343
352
resultPublisherFlag &&
344
353
statusReceivedFlag ;
354
+ if (timeout .isPositive ()) {
355
+ gotTime = (node .getCurrentTime ().compareTo (finalTime ) < 0 );
356
+ }
345
357
}
346
358
return res ;
347
359
}
348
360
361
+ /**
362
+ * Wait indefinately until an actionlib server is connected.
363
+ */
364
+ public void waitForActionServerToStart () {
365
+ waitForActionServerToStart (new Duration (0 ));
366
+ }
367
+
349
368
@ Override
350
369
public void onNewPublisher (Subscriber subscriber , PublisherIdentifier publisherIdentifier ) {
351
370
//public void onNewFeedbackPublisher(Subscriber<T_ACTION_FEEDBACK> subscriber, PublisherIdentifier publisherIdentifier) {
@@ -360,9 +379,15 @@ public void onNewPublisher(Subscriber subscriber, PublisherIdentifier publisherI
360
379
}
361
380
}
362
381
382
+ /**
383
+ * Get the current state of the action goal as being tracked by the client.
384
+ * @return The state of the goal.
385
+ * @see ClientStateMachine.ClientStates
386
+ */
363
387
public int getGoalState () {
364
388
return goalManager .getGoalState ();
365
389
}
390
+
366
391
/**
367
392
* Finish the action client. Unregister publishers and listeners.
368
393
*/
0 commit comments