diff --git a/Assets/UnitySensorsROS/Runtime/Scripts/Serializers/Serializer.cs b/Assets/UnitySensorsROS/Runtime/Scripts/Serializers/Serializer.cs index 09c14e37..4ca4b6e0 100644 --- a/Assets/UnitySensorsROS/Runtime/Scripts/Serializers/Serializer.cs +++ b/Assets/UnitySensorsROS/Runtime/Scripts/Serializers/Serializer.cs @@ -36,7 +36,11 @@ public void Init(string frame_id) /// public void Serialize(float time) { +#if ROS2 + int sec = (int)Math.Truncate(time); +#else uint sec = (uint)Math.Truncate(time); +# endif _header.stamp.sec = sec; _header.stamp.nanosec = (uint)((time - sec) * 1e+9); _header.seq++; diff --git a/Assets/UnitySensorsROS/Runtime/Scripts/Utils/Clock/ROSClock.cs b/Assets/UnitySensorsROS/Runtime/Scripts/Utils/Clock/ROSClock.cs index 6fca642e..666e3b31 100644 --- a/Assets/UnitySensorsROS/Runtime/Scripts/Utils/Clock/ROSClock.cs +++ b/Assets/UnitySensorsROS/Runtime/Scripts/Utils/Clock/ROSClock.cs @@ -28,7 +28,11 @@ void Start() void Update() { float time = Time.time; +#if ROS2 + int sec = (int)Math.Truncate(time); +#else uint sec = (uint)Math.Truncate(time); +# endif uint nanosec = (uint)((time - sec) * 1e+9); _message.clock.sec = sec; _message.clock.nanosec = nanosec;