From b7f168eea1386744a5e0423fbfdfa2f6af3bcecd Mon Sep 17 00:00:00 2001 From: Ahmet Soyyigit Date: Tue, 4 Feb 2025 08:56:14 -0600 Subject: [PATCH] Dothe expensive publishing operation in a seperate thread to resolve bottleneck. --- .../AWSIM/Scripts/Sensors/Camera/CameraRos2Publisher.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Assets/AWSIM/Scripts/Sensors/Camera/CameraRos2Publisher.cs b/Assets/AWSIM/Scripts/Sensors/Camera/CameraRos2Publisher.cs index b7aebf554..303322c48 100644 --- a/Assets/AWSIM/Scripts/Sensors/Camera/CameraRos2Publisher.cs +++ b/Assets/AWSIM/Scripts/Sensors/Camera/CameraRos2Publisher.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; using ROS2; +using System.Threading.Tasks; namespace AWSIM { @@ -84,9 +85,12 @@ void UpdateMessagesAndPublish(CameraSensor.OutputData outputData) imageMsg.Header.Stamp = timeMsg; cameraInfoMsg.Header.Stamp = timeMsg; + // Publish to ROS2 - imagePublisher.Publish(imageMsg); - cameraInfoPublisher.Publish(cameraInfoMsg); + var taskBoth = Task.Run(() => { + imagePublisher.Publish(imageMsg); + cameraInfoPublisher.Publish(cameraInfoMsg); + }); } private void UpdateImageMsg(CameraSensor.OutputData data)