Skip to content

Commit 261c3a8

Browse files
authored
Merge pull request #36 from Field-Robotics-Japan/hotfix/ros2_header
Hotfix ros2 header
2 parents 30bec3d + a199dac commit 261c3a8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Assets/UnitySensorsROS/Runtime/Scripts/Serializers/Serializer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,28 @@ public void Init(string frame_id)
2828
{
2929
_header = new HeaderMsg();
3030
_header.frame_id = frame_id;
31+
#if ROS2
32+
#else
3133
_header.seq = 0;
34+
#endif
3235
}
3336

3437
/// <summary>
3538
/// シリアライズ関数
3639
/// </summary>
3740
public void Serialize(float time)
3841
{
42+
#if ROS2
43+
int sec = (int)Math.Truncate(time);
44+
#else
3945
uint sec = (uint)Math.Truncate(time);
46+
# endif
4047
_header.stamp.sec = sec;
4148
_header.stamp.nanosec = (uint)((time - sec) * 1e+9);
49+
#if ROS2
50+
#else
4251
_header.seq++;
52+
#endif
4353
}
4454
}
4555
}

Assets/UnitySensorsROS/Runtime/Scripts/Utils/Clock/ROSClock.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ void Start()
2828
void Update()
2929
{
3030
float time = Time.time;
31+
#if ROS2
32+
int sec = (int)Math.Truncate(time);
33+
#else
3134
uint sec = (uint)Math.Truncate(time);
35+
# endif
3236
uint nanosec = (uint)((time - sec) * 1e+9);
3337
_message.clock.sec = sec;
3438
_message.clock.nanosec = nanosec;

0 commit comments

Comments
 (0)