Skip to content
Snippets Groups Projects
Unverified Commit 13bcbee1 authored by Juan Ignacio Ubeira's avatar Juan Ignacio Ubeira Committed by GitHub
Browse files

Merge pull request #264 from drigz/wait-for-master

Wait for master before getting /use_sim_time
parents e92b7b78 70e445f7
No related branches found
No related tags found
No related merge requests found
...@@ -180,17 +180,26 @@ public class DefaultNode implements ConnectedNode { ...@@ -180,17 +180,26 @@ public class DefaultNode implements ConnectedNode {
// possible during startup. // possible during startup.
registrar.start(slaveServer.toNodeIdentifier()); registrar.start(slaveServer.toNodeIdentifier());
// During startup, we wait for 1) the RosoutLogger and 2) the TimeProvider. // Wait for the logger to register with the master. This ensures the master is running before
final CountDownLatch latch = new CountDownLatch(2); // requesting the use_sim_time parameter.
final CountDownLatch rosoutLatch = new CountDownLatch(1);
log = new RosoutLogger(this); log = new RosoutLogger(this);
log.getPublisher().addListener(new DefaultPublisherListener<rosgraph_msgs.Log>() { log.getPublisher().addListener(new DefaultPublisherListener<rosgraph_msgs.Log>() {
@Override @Override
public void onMasterRegistrationSuccess(Publisher<rosgraph_msgs.Log> registrant) { public void onMasterRegistrationSuccess(Publisher<rosgraph_msgs.Log> registrant) {
latch.countDown(); rosoutLatch.countDown();
} }
}); });
try {
rosoutLatch.await();
} catch (InterruptedException e) {
signalOnError(e);
shutdown();
return;
}
boolean useSimTime = false; boolean useSimTime = false;
try { try {
useSimTime = useSimTime =
...@@ -198,24 +207,28 @@ public class DefaultNode implements ConnectedNode { ...@@ -198,24 +207,28 @@ public class DefaultNode implements ConnectedNode {
&& parameterTree.getBoolean(Parameters.USE_SIM_TIME); && parameterTree.getBoolean(Parameters.USE_SIM_TIME);
} catch (Exception e) { } catch (Exception e) {
signalOnError(e); signalOnError(e);
shutdown();
return;
} }
final CountDownLatch timeLatch = new CountDownLatch(1);
if (useSimTime) { if (useSimTime) {
ClockTopicTimeProvider clockTopicTimeProvider = new ClockTopicTimeProvider(this); ClockTopicTimeProvider clockTopicTimeProvider = new ClockTopicTimeProvider(this);
clockTopicTimeProvider.getSubscriber().addSubscriberListener( clockTopicTimeProvider.getSubscriber().addSubscriberListener(
new DefaultSubscriberListener<rosgraph_msgs.Clock>() { new DefaultSubscriberListener<rosgraph_msgs.Clock>() {
@Override @Override
public void onMasterRegistrationSuccess(Subscriber<rosgraph_msgs.Clock> subscriber) { public void onMasterRegistrationSuccess(Subscriber<rosgraph_msgs.Clock> subscriber) {
latch.countDown(); timeLatch.countDown();
} }
}); });
timeProvider = clockTopicTimeProvider; timeProvider = clockTopicTimeProvider;
} else { } else {
timeProvider = nodeConfiguration.getTimeProvider(); timeProvider = nodeConfiguration.getTimeProvider();
latch.countDown(); timeLatch.countDown();
} }
try { try {
latch.await(); timeLatch.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
signalOnError(e); signalOnError(e);
shutdown(); shutdown();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment