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()
4545 {
4646 lock ( mutex )
4747 {
48+ if ( ros2forUnity == null )
49+ LazyConstruct ( ) ;
4850 return ( nodes != null && ros2forUnity . Ok ( ) ) ;
4951 }
5052 }
Original file line number Diff line number Diff line change @@ -34,22 +34,32 @@ public class DotnetTimeSource : ITimeSource
3434
3535 private double stopwatchStartTimeStamp ;
3636
37- public DotnetTimeSource ( )
37+ private double TotalSystemTimeSeconds ( )
38+ {
39+ return TimeSpan . FromTicks ( DateTime . UtcNow . Ticks ) . TotalSeconds ;
40+ }
41+
42+ private void UpdateSystemTime ( )
3843 {
44+ systemTimeIntervalStart = TotalSystemTimeSeconds ( ) ;
3945 stopwatchStartTimeStamp = Stopwatch . GetTimestamp ( ) ;
4046 }
4147
48+ public DotnetTimeSource ( )
49+ {
50+ UpdateSystemTime ( ) ;
51+ }
52+
4253 public void GetTime ( out int seconds , out uint nanoseconds )
4354 {
4455 lock ( mutex ) // Threading
4556 {
4657 double endTimestamp = Stopwatch . GetTimestamp ( ) ;
47- var durationInSeconds = ( endTimestamp - stopwatchStartTimeStamp ) / Stopwatch . Frequency ;
58+ var durationInSeconds = endTimestamp - stopwatchStartTimeStamp ;
4859 double timeOffset = 0 ;
4960 if ( durationInSeconds >= maxUnsyncedSeconds )
5061 { // acquire DateTime to sync
51- stopwatchStartTimeStamp = Stopwatch . GetTimestamp ( ) ;
52- systemTimeIntervalStart = TimeSpan . FromTicks ( DateTime . UtcNow . Ticks ) . TotalSeconds ;
62+ UpdateSystemTime ( ) ;
5363 }
5464 else
5565 { // use Stopwatch offset
Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ public class ROS2Clock
2525{
2626 private ITimeSource _timeSource ;
2727
28- public ROS2Clock ( ) : this ( new DotnetTimeSource ( ) )
29- { // By default, use DotnetTimeSource
28+ public ROS2Clock ( ) : this ( new ROS2TimeSource ( ) )
29+ { // By default, use ROS2TimeSource
3030 }
3131
3232 public ROS2Clock ( ITimeSource ts )
You can’t perform that action at this time.
0 commit comments