Skip to content

Commit 89e978e

Browse files
pijaroadamdbrw
authored andcommitted
Fixed code bugs
1 parent 0aca167 commit 89e978e

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

src/Ros2ForUnity/Scripts/Time/DotnetTimeSource.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
// limitations under the License.
1414

1515
using System;
16-
using System.Threading;
17-
16+
using System.Diagnostics;
1817

1918
namespace ROS2
2019
{
@@ -35,12 +34,12 @@ public class DotnetTimeSource : ITimeSource
3534

3635
private double stopwatchStartTimeStamp;
3736

38-
DotnetTimeSource()
37+
public DotnetTimeSource()
3938
{
40-
stopwatchStartTimeStamp = stopwatch.GetTimestamp();
39+
stopwatchStartTimeStamp = Stopwatch.GetTimestamp();
4140
}
4241

43-
void GetTime(out int seconds, out uint nanoseconds)
42+
public void GetTime(out int seconds, out uint nanoseconds)
4443
{
4544
lock(mutex) // Threading
4645
{

src/Ros2ForUnity/Scripts/Time/ITimeSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ namespace ROS2
1818
/// <summary>
1919
/// Interace for acquiring time
2020
/// </summary>
21-
internal interface ITimeSource
21+
public interface ITimeSource
2222
{
23-
void GetTime(out int seconds, out uint nanoseconds);
23+
public void GetTime(out int seconds, out uint nanoseconds);
2424
}
2525

2626
} // namespace ROS2

src/Ros2ForUnity/Scripts/Time/ROS2Clock.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,40 @@ namespace ROS2
2323
/// </summary>
2424
public class ROS2Clock
2525
{
26-
private ITimeSource timeSource;
26+
private ITimeSource _timeSource;
2727

2828
public ROS2Clock() : this(new DotnetTimeSource())
2929
{ // By default, use DotnetTimeSource
3030
}
3131

3232
public ROS2Clock(ITimeSource ts)
3333
{
34-
timeSource = ts;
34+
_timeSource = ts;
3535
}
3636

3737
public void UpdateClockMessage(ref rosgraph_msgs.msg.Clock clockMessage)
3838
{
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;
4044
}
4145

4246
public void UpdateROSClockTime(builtin_interfaces.msg.Time time)
4347
{
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;
4553
}
4654

4755
public void UpdateROSTimestamp(ref ROS2.MessageWithHeader message)
4856
{
4957
int seconds;
5058
uint nanoseconds;
51-
timeSource.GetTime(out seconds, out nanoseconds);
59+
_timeSource.GetTime(out seconds, out nanoseconds);
5260
message.UpdateHeaderTime(seconds, nanoseconds);
5361
}
5462
}

src/Ros2ForUnity/Scripts/Time/ROS2TimeSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
using System;
15+
using UnityEngine;
1616

1717
namespace ROS2
1818
{
@@ -24,7 +24,7 @@ public class ROS2TimeSource : ITimeSource
2424
{
2525
private ROS2.Clock clock;
2626

27-
void GetTime(out int seconds, out uint nanoseconds)
27+
public void GetTime(out int seconds, out uint nanoseconds)
2828
{
2929
if (!ROS2.Ros2cs.Ok())
3030
{

src/Ros2ForUnity/Scripts/Time/TimeUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ namespace ROS2
2020
/// </summary>
2121
internal static class TimeUtils
2222
{
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)
2424
{
25-
long nanosec = (long)(seconds * 1e9);
25+
long nanosec = (long)(secondsIn * 1e9);
2626
seconds = (int)(nanosec / 1000000000);
2727
nanoseconds = (uint)(nanosec % 1000000000);
2828
}

src/Ros2ForUnity/Scripts/Time/UnityTimeSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public UnityTimeSource()
3535
mainThread = Thread.CurrentThread;
3636
}
3737

38-
void GetTime(out int seconds, out uint nanoseconds)
38+
public void GetTime(out int seconds, out uint nanoseconds)
3939
{
4040
lastReadingSecs = mainThread.Equals(Thread.CurrentThread) ? Time.timeAsDouble : lastReadingSecs;
4141
TimeUtils.TimeFromTotalSeconds(lastReadingSecs, out seconds, out nanoseconds);

0 commit comments

Comments
 (0)