Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Commit 591f71d

Browse files
committed
simtime: use time=0 by default
This is the behaviour documented here: http://wiki.ros.org/Clock#Using_Simulation_Time_from_the_.2BAC8-clock_Topic If the /use_sim_time parameter is set, the ROS Time API will return time=0 until it has received a value from the /clock topic. Then, the time will only be updated on receipt of a message from the /clock topic, and will stay constant between updates. This resolves a NullPointerException when a node logs from its onStart method and use_sim_time is true.
1 parent e92b7b7 commit 591f71d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rosjava/src/main/java/org/ros/time/ClockTopicTimeProvider.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ public Subscriber<rosgraph_msgs.Clock> getSubscriber() {
5757

5858
@Override
5959
public Time getCurrentTime() {
60-
Preconditions.checkNotNull(clock);
60+
// When using simulation time, the ROS Time API will return time=0 until it has received a
61+
// message from the /clock topic.
62+
if (clock == null) {
63+
return new Time();
64+
}
65+
6166
synchronized (mutex) {
6267
return new Time(clock.getClock());
6368
}

0 commit comments

Comments
 (0)