EricVoll / ros-sharp

ROS# is a set of open source software libraries and tools in C# for communicating with ROS from .NET applications, in particular Unity3D
Apache License 2.0
36 stars 7 forks source link

Application crashes on Hololens2 while trying to subscribe PointCloud2 message #3

Closed whirwind closed 3 years ago

whirwind commented 3 years ago

Hello @EricVoll

What I am doing now is to receive pointcloud from ROS and display it in hololens2. The code works fine in Unity, but it will crash if I apply it to my Hololens2 device.

I followed other subcriber scipt and wrote my own PointCloud2 subscriber. After this error happened, I deleted all processing code and just simply receive the data, but the error still exists: protected override void ReceiveMessage(Messages.Sensor.PointCloud2 message) { isMessageReceived = true; }

I also subscribed other messages like image or posestamped successfully both in Unity and Hololens2. The format of code and the way I use them are all the same. So I am confused now and do you have any advice? Thank you.

My OS is: Windows 10 Pro, ver.2004 My Unity Version is: 2019.4.2f1 with MRTK2.4 My Build Target Platform is: Hololens2

EricVoll commented 3 years ago

Hi @whirwind

thanks for creating the issue. Three questions:

  1. Do you get any error message? Have you tried attaching the Visual Studio live debugger to the running instance on HL2?
  2. Could you post your Subscriber script please? Maybe there are some code-components in there, that don't work on deployed devices.
  3. Do you (by chance) have a HL1 available to test your code? If yes, does it run there?

Best, Eric

whirwind commented 3 years ago

Hi @EricVoll

Thanks for your answer.

  1. No error message, just crash to HL2's desktop. Debugger to HL2 is too slow so I rarely use it. But today I tried it and got this: To be honest I don't understand what this means. QQ截图20200903153607

  2. Here is the code (I delete parts of processing and rendering and just simply receive data to test the problem):

Code ```csharp using UnityEngine; using TMPro; namespace RosSharp.RosBridgeClient { [RequireComponent(typeof(RosConnector))] public class PointCloud2Subscriber : Subscriber { public RgbPoint3[] Points; Vector3[] vertices; Color[] colors; int[] indices; public PointCloudRenderer pointCloudRenderer; //Subscription variable private bool isMessageReceived = false; private bool psenable = false; public string Topicname = "/husky/lidar_points"; float elapsed = 0f; public TMP_Text TestText; public ParticleSystem ps; public GameObject PS; protected override void Start() { TestText = (TMP_Text)GameObject.Find("Text (TMP) (1)").GetComponent(typeof(TMP_Text)); } private void Update() //Function to update when new messages are received { elapsed += Time.deltaTime; if (elapsed >= 1f & isMessageReceived & pointCloudRenderer != null) { elapsed = elapsed % 1f; ProcessMessage3(); } TestText.text = "isMessageReceived: " + isMessageReceived + " pointCloudRenderer:" + pointCloudRenderer; } protected override void ReceiveMessage(Messages.Sensor.PointCloud2 message) //Automatically called when new mesage received { isMessageReceived = true; } private void ProcessMessage3() { // pointCloudRenderer.Render(vertices, colors); } public void ChangeTopic(GameObject FocusedRobot) { string[] tmp = FocusedRobot.name.Split('_'); Topicname = "/" + tmp[0] + tmp[1] + "/lidar_points"; base.Topic = Topicname; base.Start(); pointCloudRenderer = FocusedRobot.transform.Find("PointCloudRender").gameObject.GetComponent(); } } } ```

And this is how I active the script:

Active ```csharp GameObject.Find("Rosconnector").AddComponent(); GameObject.Find("Rosconnector").GetComponent().ChangeTopic(FocusedRobot); ```
  1. Sorry I don't have HL1 device so I can't test this problem on HL1

Best, whirwind

EricVoll commented 3 years ago

thanks for the answers.

The code of the subscriber looks good to me - at least there are no components that might fail on UWP builds.

Have you also tried to debug it as it is explained here? This should give you the exceptions not in the IL2CPP compiled c++ code, but directly in the C# code that we can interpret much better.

whirwind commented 3 years ago

Hi

I tried to debug with C# code. App in the HL2 device crashes, too, without any error message in HL2 or VS2019. I guess it crashes when "base.Start()" or "ReceiveMessage()" function runs.

Today I also tried generate PointCloud message and receive it. In Unity it works fine again. But in HL2 this time the "ReceiveMessage()" function can't be triggered instead of crashing. However, file_server in ROS told me this topic was successfully subscribed. image

glennliu commented 3 years ago

Do you try to run it on HL2 emulator?

I have been met another exception and crash issue earlier when I try to deploy a solution on HoloLens hardware. But that was because of a wireless connection issue and it is not related with Ros#.

whirwind commented 3 years ago

@EricVoll I am new to RosSharp VS2019 project so I have a stupid question: When I add new PointCloud message type, I added scripts to RosBridgeClient project and used "add as link" to add same scripts to RosBridgeClientUWP project. Is that right way to build new RosBridgeClient.dll and RosBridgeClientUWP.dll?

@glennliu PointCloud msg type in emulator performe the same as real device: no crash but "ReceiveMessage()" can not be trigged

But PointCloud2 msg type is different: 1.no crash but "ReceiveMessage()" can not be trigged in emulator 2.crash in real device

EricVoll commented 3 years ago

sry don't have much time now. I'm currently working on updating this UWP Fork to the newest version of ROS#. Since there will be a ton of changes, this issue might resolve itself with the newer version. Do you have time to wait for the new version, or do you need a solution asap?

whirwind commented 3 years ago

Hi

Please take your time. I am looking forward to the new version.

EricVoll commented 3 years ago

@whirwind FYI: making good progress. I'm currently in the testing phase

EricVoll commented 3 years ago

@whirwind I just merged the VersionUpdate branch into the main ranch. All my tests with the new version of RosSharpUWP were successful and should work. The demo App has also been updated. If you find any new issues with the new version, feel free to create an Issue here.