File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ public bool Ok()
45
45
{
46
46
lock ( mutex )
47
47
{
48
+ if ( ros2forUnity == null )
49
+ LazyConstruct ( ) ;
48
50
return ( nodes != null && ros2forUnity . Ok ( ) ) ;
49
51
}
50
52
}
Original file line number Diff line number Diff line change @@ -34,22 +34,32 @@ public class DotnetTimeSource : ITimeSource
34
34
35
35
private double stopwatchStartTimeStamp ;
36
36
37
- public DotnetTimeSource ( )
37
+ private double TotalSystemTimeSeconds ( )
38
+ {
39
+ return TimeSpan . FromTicks ( DateTime . UtcNow . Ticks ) . TotalSeconds ;
40
+ }
41
+
42
+ private void UpdateSystemTime ( )
38
43
{
44
+ systemTimeIntervalStart = TotalSystemTimeSeconds ( ) ;
39
45
stopwatchStartTimeStamp = Stopwatch . GetTimestamp ( ) ;
40
46
}
41
47
48
+ public DotnetTimeSource ( )
49
+ {
50
+ UpdateSystemTime ( ) ;
51
+ }
52
+
42
53
public void GetTime ( out int seconds , out uint nanoseconds )
43
54
{
44
55
lock ( mutex ) // Threading
45
56
{
46
57
double endTimestamp = Stopwatch . GetTimestamp ( ) ;
47
- var durationInSeconds = ( endTimestamp - stopwatchStartTimeStamp ) / Stopwatch . Frequency ;
58
+ var durationInSeconds = endTimestamp - stopwatchStartTimeStamp ;
48
59
double timeOffset = 0 ;
49
60
if ( durationInSeconds >= maxUnsyncedSeconds )
50
61
{ // acquire DateTime to sync
51
- stopwatchStartTimeStamp = Stopwatch . GetTimestamp ( ) ;
52
- systemTimeIntervalStart = TimeSpan . FromTicks ( DateTime . UtcNow . Ticks ) . TotalSeconds ;
62
+ UpdateSystemTime ( ) ;
53
63
}
54
64
else
55
65
{ // use Stopwatch offset
Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ public class ROS2Clock
25
25
{
26
26
private ITimeSource _timeSource ;
27
27
28
- public ROS2Clock ( ) : this ( new DotnetTimeSource ( ) )
29
- { // By default, use DotnetTimeSource
28
+ public ROS2Clock ( ) : this ( new ROS2TimeSource ( ) )
29
+ { // By default, use ROS2TimeSource
30
30
}
31
31
32
32
public ROS2Clock ( ITimeSource ts )
You can’t perform that action at this time.
0 commit comments