Skip to content

Commit 6e967a1

Browse files
author
Ernesto Corbellini
committed
Added timeout to the wait for server.
1 parent 16e33d4 commit 6e967a1

File tree

1 file changed

+27
-2
lines changed
  • src/rosjava_actionlib/rosjava_actionlib/src/main/java/com/github/ekumen/rosjava_actionlib

1 file changed

+27
-2
lines changed

src/rosjava_actionlib/rosjava_actionlib/src/main/java/com/github/ekumen/rosjava_actionlib/ActionClient.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.ros.internal.node.topic.PublisherIdentifier;
2626
import org.ros.node.topic.DefaultSubscriberListener;
2727
import org.ros.message.MessageListener;
28+
import org.ros.message.Duration;
29+
import org.ros.message.Time;
2830
import org.ros.internal.message.Message;
2931
import java.util.concurrent.TimeUnit;
3032
import java.util.List;
@@ -332,20 +334,37 @@ private void connect(ConnectedNode node) {
332334

333335
/**
334336
* 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.
335342
*/
336-
public boolean waitForActionServerToStart() {
343+
public boolean waitForActionServerToStart(Duration timeout) {
337344
boolean res = false;
345+
boolean gotTime = true;
346+
Time finalTime = node.getCurrentTime().add(timeout);
338347

339-
while (!res) {
348+
while (!res && gotTime) {
340349
res = goalPublisher.hasSubscribers() &&
341350
cancelPublisher.hasSubscribers() &&
342351
feedbackPublisherFlag &&
343352
resultPublisherFlag &&
344353
statusReceivedFlag;
354+
if (timeout.isPositive()) {
355+
gotTime = (node.getCurrentTime().compareTo(finalTime) < 0);
356+
}
345357
}
346358
return res;
347359
}
348360

361+
/**
362+
* Wait indefinately until an actionlib server is connected.
363+
*/
364+
public void waitForActionServerToStart() {
365+
waitForActionServerToStart(new Duration(0));
366+
}
367+
349368
@Override
350369
public void onNewPublisher(Subscriber subscriber, PublisherIdentifier publisherIdentifier) {
351370
//public void onNewFeedbackPublisher(Subscriber<T_ACTION_FEEDBACK> subscriber, PublisherIdentifier publisherIdentifier) {
@@ -360,9 +379,15 @@ public void onNewPublisher(Subscriber subscriber, PublisherIdentifier publisherI
360379
}
361380
}
362381

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+
*/
363387
public int getGoalState() {
364388
return goalManager.getGoalState();
365389
}
390+
366391
/**
367392
* Finish the action client. Unregister publishers and listeners.
368393
*/

0 commit comments

Comments
 (0)