File tree Expand file tree Collapse file tree 6 files changed +24
-17
lines changed
src/Ros2ForUnity/Scripts/Time Expand file tree Collapse file tree 6 files changed +24
-17
lines changed Original file line number Diff line number Diff line change 13
13
// limitations under the License.
14
14
15
15
using System ;
16
- using System . Threading ;
17
-
16
+ using System . Diagnostics ;
18
17
19
18
namespace ROS2
20
19
{
@@ -35,12 +34,12 @@ public class DotnetTimeSource : ITimeSource
35
34
36
35
private double stopwatchStartTimeStamp ;
37
36
38
- DotnetTimeSource ( )
37
+ public DotnetTimeSource ( )
39
38
{
40
- stopwatchStartTimeStamp = stopwatch . GetTimestamp ( ) ;
39
+ stopwatchStartTimeStamp = Stopwatch . GetTimestamp ( ) ;
41
40
}
42
41
43
- void GetTime ( out int seconds , out uint nanoseconds )
42
+ public void GetTime ( out int seconds , out uint nanoseconds )
44
43
{
45
44
lock ( mutex ) // Threading
46
45
{
Original file line number Diff line number Diff line change @@ -18,9 +18,9 @@ namespace ROS2
18
18
/// <summary>
19
19
/// Interace for acquiring time
20
20
/// </summary>
21
- internal interface ITimeSource
21
+ public interface ITimeSource
22
22
{
23
- void GetTime ( out int seconds , out uint nanoseconds ) ;
23
+ public void GetTime ( out int seconds , out uint nanoseconds ) ;
24
24
}
25
25
26
26
} // namespace ROS2
Original file line number Diff line number Diff line change @@ -23,32 +23,40 @@ namespace ROS2
23
23
/// </summary>
24
24
public class ROS2Clock
25
25
{
26
- private ITimeSource timeSource ;
26
+ private ITimeSource _timeSource ;
27
27
28
28
public ROS2Clock ( ) : this ( new DotnetTimeSource ( ) )
29
29
{ // By default, use DotnetTimeSource
30
30
}
31
31
32
32
public ROS2Clock ( ITimeSource ts )
33
33
{
34
- timeSource = ts ;
34
+ _timeSource = ts ;
35
35
}
36
36
37
37
public void UpdateClockMessage ( ref rosgraph_msgs . msg . Clock clockMessage )
38
38
{
39
- _timeSource . GetTime ( out clockMessage . Clock_ . Sec , out clockMessage . Clock_ . Nanosec ) ;
39
+ int seconds ;
40
+ uint nanoseconds ;
41
+ _timeSource . GetTime ( out seconds , out nanoseconds ) ;
42
+ clockMessage . Clock_ . Sec = seconds ;
43
+ clockMessage . Clock_ . Nanosec = nanoseconds ;
40
44
}
41
45
42
46
public void UpdateROSClockTime ( builtin_interfaces . msg . Time time )
43
47
{
44
- timeSource . GetTime ( out time . Sec , out time . Nanosec ) ;
48
+ int seconds ;
49
+ uint nanoseconds ;
50
+ _timeSource . GetTime ( out seconds , out nanoseconds ) ;
51
+ time . Sec = seconds ;
52
+ time . Nanosec = nanoseconds ;
45
53
}
46
54
47
55
public void UpdateROSTimestamp ( ref ROS2 . MessageWithHeader message )
48
56
{
49
57
int seconds ;
50
58
uint nanoseconds ;
51
- timeSource . GetTime ( out seconds , out nanoseconds ) ;
59
+ _timeSource . GetTime ( out seconds , out nanoseconds ) ;
52
60
message . UpdateHeaderTime ( seconds , nanoseconds ) ;
53
61
}
54
62
}
Original file line number Diff line number Diff line change 12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- using System ;
15
+ using UnityEngine ;
16
16
17
17
namespace ROS2
18
18
{
@@ -24,7 +24,7 @@ public class ROS2TimeSource : ITimeSource
24
24
{
25
25
private ROS2 . Clock clock ;
26
26
27
- void GetTime ( out int seconds , out uint nanoseconds )
27
+ public void GetTime ( out int seconds , out uint nanoseconds )
28
28
{
29
29
if ( ! ROS2 . Ros2cs . Ok ( ) )
30
30
{
Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ namespace ROS2
20
20
/// </summary>
21
21
internal static class TimeUtils
22
22
{
23
- void TimeFromTotalSeconds ( in double seconds , out int seconds , out uint nanoseconds )
23
+ public static void TimeFromTotalSeconds ( in double secondsIn , out int seconds , out uint nanoseconds )
24
24
{
25
- long nanosec = ( long ) ( seconds * 1e9 ) ;
25
+ long nanosec = ( long ) ( secondsIn * 1e9 ) ;
26
26
seconds = ( int ) ( nanosec / 1000000000 ) ;
27
27
nanoseconds = ( uint ) ( nanosec % 1000000000 ) ;
28
28
}
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public UnityTimeSource()
35
35
mainThread = Thread . CurrentThread ;
36
36
}
37
37
38
- void GetTime ( out int seconds , out uint nanoseconds )
38
+ public void GetTime ( out int seconds , out uint nanoseconds )
39
39
{
40
40
lastReadingSecs = mainThread . Equals ( Thread . CurrentThread ) ? Time . timeAsDouble : lastReadingSecs ;
41
41
TimeUtils . TimeFromTotalSeconds ( lastReadingSecs , out seconds , out nanoseconds ) ;
You can’t perform that action at this time.
0 commit comments