ros-sharp icon indicating copy to clipboard operation
ros-sharp copied to clipboard

Add "sensor_msgs/PointCloud2" as new messages

Open glennliu opened this issue 5 years ago • 5 comments

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

glennliu avatar Aug 17 '20 09:08 glennliu

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.

whirwind avatar Sep 02 '20 19:09 whirwind

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.

glennliu avatar Sep 03 '20 02:09 glennliu

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

whirwind avatar Sep 04 '20 23:09 whirwind

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 sensor_msgs/CompressedImage and nav_msgs/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 sensor_msgs/PointCloud. Because the default message only supports sensor_msgs/PointCloud2, I generate sesor_msgs/PointCloud messages on Visual Studio. When I try to read the generated sensor_msgs/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

glennliu avatar Sep 05 '20 07:09 glennliu

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
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
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

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";
        }

 
    }
}

whirwind avatar Sep 05 '20 21:09 whirwind