Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to subscribe to custom messages #366

Closed
5 tasks done
mul-12 opened this issue Dec 14, 2020 · 1 comment
Closed
5 tasks done

Unable to subscribe to custom messages #366

mul-12 opened this issue Dec 14, 2020 · 1 comment

Comments

@mul-12
Copy link

mul-12 commented Dec 14, 2020

  • I am at the right place and my issue is directly related to ROS#. General technical questions I would post e.g. at ROS Answers or Stack Overflow. For library-specific questions I would look for help in the corresponding library forums.
  • I have thoroughly read the Contributing Guideline and writing this issue is the right thing to do in my case.

I have a question!

  • I searched the Wiki, open and closed issues for an answer. I tried my best to find the answer by myself without success. I believe that the discussion we will have in this issue, and the solutions we might find, will help me, and likely other community members who have a similar problem.

Here is my question:
My OS is: Ubuntu 18.04
My Unity Version is: 2019.4.15
My ROS Distribution is: ROS2 (Eloquent)
My Build Target Platform is: Windows 10

I am able to subscribe to topics and receive data in Unity using ros2-web-bridge and the ROS# library provided (e.g. String, Twist). I am now attempting to subscribe to custom messages, however am not receiving the topic's data in Unity. Any help would be appreciated!

My topic ("/topic") is publishing a custom message (Num.msg) with the following data:

float64 hr
float64 timestamp 

When running the node, I can see that the topic is publishing data as expected. I can see this in rqt and when running "ros2 topic echo /topic" I get the below sample output:

hr: 452.1
timestamp: 452.2
---
hr: 453.1
timestamp: 453.2
---
hr: 454.1
timestamp: 454.2

I have followed the tutorial on How to add new message types. I have attempted Option 1 and 3 with no success. When running in Unity, I can see that Start() is called, but ReceiveMessage() is not. My message and subscriber scripts are below. I have also included a screenshot of the application running on Unity, showing TwistSubscriber working, but not MyNumSubscriber.

RosSharpMessages - Num.cs

namespace RosSharp.RosBridgeClient.MessageTypes.PyPubsub
{
    public class Num : Message
    {
        public const string RosMessageName = "tutorial_interfaces/Num";

        // int64 num
        public double hr { get; set; }
        public double timestamp { get; set; }

        public Num()
        {
            this.hr = 0.0;
            this.timestamp = 0.0;
        }

        public Num(double hr, double timestamp)
        {
            this.hr = hr;
            this.timestamp = timestamp;
        }
    }
}

RosCommunication - MyNumSubscriber.cs

using UnityEngine;
using System;

namespace RosSharp.RosBridgeClient
{
    public class MyNumSubscriber : UnitySubscriber<MessageTypes.PyPubsub.Num>
    {
        
        public double myHr;
        public double myTimestamp;


        protected override void Start()
        {
            print("start Num");
            base.Start();
        }

        protected override void ReceiveMessage(MessageTypes.PyPubsub.Num message)
        {
            // Process message data
            print("NEW MESSAGE Rx");
            myHr = message.hr;
            myTimestamp = message.timestamp;
            
        }
    }
}

Screenshot from 2020-12-14 23-44-36


I found a bug!

  • I am using the latest ROS# version available here on the master branch.
  • I am adding all required information, code and data files, screenshots and log files so that you can reproduce the problem.
@berkayalpcakal
Copy link
Contributor

Hello @mul-12,

I was able to reproduce the issue, and found the solution in the ros2-web-bridge issue board. Please see here, and here.

It seems that at the first time you run the rosbridge, some .js scripts are generated in accordance with the message definitions in your ros2 environment. If you introduce some more message definitions to your ros2 environment after running the rosbridge, generation of new .js scripts for the new message definitions are not triggered.

Simply delete the folder $your-ros2-web-bridge-path/node_modules/rclnodejs/generated/, then run the rosbridge again. You should see your custom-message-related .js files under that folder.

Eventually I was able to send/receive the custom messages within Unity via ROS# and ros2-web-bridge.

I think this issue is related to ros2-web-bridge framework.

PS: You can always import the source code of the RosBridgeClient into your Assets instead of importing the .dll file, so that you can fully debug the code. I first checked the deserialized data received from rosbridge, which includes error logs if any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants