dwhit / 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
29 stars 15 forks source link

Add "sensor_msgs/PointCloud2" as new messages #5

Open glennliu opened 4 years ago

glennliu commented 4 years ago

Hi

I add "sensor_msgs/PointCloud2" message successful in the original ROS#. But the generated message is not compatible with your fork. It shows compile errors. Then, I tried to generate a new message with "rosbridgeclient" in your code.

But it is quite different to the original message generation. Can you please explain the main steps of using it?

Thanks

whirwind commented 4 years ago

Hello

I am doing the same things and I have already successfully received PointCloud2 messages in Unity.

You need to add new messages in the RosSharp.sln project in VisualStodio, then build it and update RosBridgeClient.dll in the Unity Project.

However, it doesn't work if I apply it to Hololens2 and it seems that it just can't receive my custom messages in Hololens2. I am confused, too.

glennliu commented 4 years ago

Hi @whirwind

Can I use the generated ros message as the original wiki explained, and add this ros message to RosSharp.sln?

I can receive pointcloud2 message in HoloLens 1/ HoloLens2, with the original siemens/ros-sharp. I'll try your solution later today and share my results.

whirwind commented 4 years ago

Hi @glennliu

Sorry I made some mistakes about my previous answer

  1. We do not need to add "PointCloud2" as new message type because it is already added by default.
  2. What we need to do is just to write our own subscriber and publisher

You said you can receive pointcloud2 message in HoloLens 1/ HoloLens2, is that real? I can do it in Unity, but I am struggling with receiving PointCloud2 message while deploying it to Hololens2. Please share your exprience if don't mind. You can check my issue here: EricVoll/ros-sharp#3

glennliu commented 4 years ago

Hi @whirwind

I didn't explain it clearly. When I use Ros# on Unity's Holographic Emulation, I can successfully receive sensor/PointCloud messages on HL1/HL2. It is actually running on Unity, instead of HL1/HL2.

On the other hand, I did more tests today. I build the package of dwhit/ros-sharp on visual studio and run it on HoloLens2 Emulator. Messages _sensormsgs/CompressedImage and _navmsgs/Odometry can be read correctly. I guess it would also be correct if it is finally deployed on HL1/HL2. I didn't meet the crash issue you mentioned.

But I still have a problem with reading _sensormsgs/PointCloud. Because the default message only supports _sensormsgs/PointCloud2, I generate _sesormsgs/PointCloud messages on Visual Studio. When I try to read the generated _sensormsgs/PointCloud messages, the rosbridge_server on ROS shows,

[INFO] [1599289865.975327]: Client connected.  1 clients total.
[ERROR] [1599289866.058728]: [Client 1] [id: /sdf_map/occ_pc:0] subscribe: Expected field type to be one of (<type 'str'>, <type 'unicode'>). Invalid value: None
[INFO] [1599289866.113138]: [Client 1] Subscribed to /vins_estimator/imu_propagate
[INFO] [1599289866.124490]: [Client 1] Subscribed to /camera/color/compressed

It occurs whenever I try to read a generated message. Do you think is it related with RosBridgeClient.ddl? Is there any other actions needed after add the new messages on Visual Studio?

Thanks

whirwind commented 4 years ago

Hi @glennliu

I subscribed other messages such as posestamped and CompressedImage. They work perfectly in both Unity and HL2 device. This is why I am confused only PointCloud or PointCloud2 fail.

Here is my script for PointCloud message generation with EricVoll/ros-sharp which is similar to dwhit/ros-sharp, but be careful that some parts of code format is different. Although I can not receive PointCloud or PointCloud2 message in HL2 device, this works well in my Unity and might help.

In VS2019 project, scripts need to be added to both RosBridgeClient and RosBridgeClientUWP(add as link) folder. And be sure to add them to corresponding folders of message type

Point32.cs to Geometry folder ```csharp using Newtonsoft.Json; namespace RosSharp.RosBridgeClient.Messages.Geometry { public class Point32 : Message { // This contains the position of a point in free space(with 32 bits of precision). // It is recommeded to use Point wherever possible instead of Point32. // // This recommendation is to promote interoperability. // // This message is designed to take up less space when sending // lots of points at once, as in the case of a PointCloud. public float x; public float y; public float z; public Point32() { this.x = 0.0f; this.y = 0.0f; this.z = 0.0f; RosMessageName = "geometry_msgs/Point32"; } } } ```
PointCloud.cs to Sensor folder ```csharp using Newtonsoft.Json; namespace RosSharp.RosBridgeClient.Messages.Sensor { public class PointCloud : Message { public Standard.Header header; public Geometry.Point32[] points; public ChannelFloat32[] channels; public PointCloud() { this.header = new Standard.Header(); this.points = new Geometry.Point32[0]; this.channels = new ChannelFloat32[0]; RosMessageName = "sensor_msgs/PointCloud"; } } } ```
ChannelFloat32.cs to Sensor folder ```csharp using Newtonsoft.Json; namespace RosSharp.RosBridgeClient.Messages.Sensor { public class ChannelFloat32 : Message { public string name; public float[] values; public ChannelFloat32() { this.name = ""; this.values = new float[0]; RosMessageName = "sensor_msgs/ChannelFloat32"; } } } ```