ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Unable to publish message to ROS Bridge from Unity [closed]

asked 2018-01-04 19:25:57 -0500

updated 2018-01-04 19:29:54 -0500

Hello,

I am trying to follow example from the submodule developed here which is a git submodule of unityros I was checking my interface by sending string message, however, my final intention is to send an array of float values coming from slider position I have.

I did have success in receiving messages from ROS side using the rosbridge by subscribing to the topic. But the other way round I cannot understand why this is not working.

Presently I am trying this:

#if UNITY_EDITOR
    void Start(){

        ros = new ROSBridgeLib.ROSBridgeWebSocketConnection("ws://192.168.142.67", 9090);
        ros.AddPublisher(typeof(ROSCommsSlider));           
    }
#endif
#if UNITY_EDITOR
    private void OnApplicationQuit(){
        if (ros != null) {
            ros.Disconnect();
        }
    }
#endif

#if UNITY_EDITOR
    public void my_func() {

    }
#endif

    // Update is called once per frame
    void Update() {
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.C))
        {
            ros.Connect();
        }

        //ros.Render();
        ROSBridgeLib.std_msgs.StringMsg ms = new ROSBridgeLib.std_msgs.StringMsg("checking_connection");
        ros.Publish(ROSCommsSlider.GetMessageTopic(), ms);
#endif
}

my ROSCommsSlider looks like this:

public class ROSCommsSlider : ROSBridgeLib.ROSBridgePublisher {
    // my class for sending message to ROSbridge
    public static string GetMessageTopic()
    {
        return "/joint_values";
    }
        public static string GetMessageType()
    {
        return "std_msgs/String";
    }

    public static string ToYAMLString(ROSBridgeLib.std_msgs.StringMsg msg)
    {
        return msg.ToYAMLString();
    }

    public new static ROSBridgeMsg ParseMessage(JSONNode msg)
    {
        return new ROSBridgeLib.std_msgs.StringMsg(msg);
    }

}

When I run the ros bridge, for some reason it is creating 3 client connection instance, but however, it doesn't send in the string to my topic when I do:

rostopic echo /joint_values

I made sure I am sending this string as per rosbridge protocol

 Sending {"op": "advertise", "topic": "/joint_values", "type": "std_msgs/String"}

UnityEngine.Debug:Log(Object)
ROSBridgeLib.ROSBridgeWebSocketConnection:Run() (at Assets/ROSBridgeLib/ROSBridgeWebSocketConnection.cs:195)

and an error:

InvalidOperationException: The current state of the connection is not Open.
WebSocketSharp.WebSocket.Send (System.String data)
ROSBridgeLib.ROSBridgeWebSocketConnection.Publish (System.String topic, .ROSBridgeMsg msg) (at Assets/ROSBridgeLib/ROSBridgeWebSocketConnection.cs:264)
ROSCommsMain.Update () (at Assets/Scripts/ROSCommsMain.cs:73)

which I don't understand why as under my rosbridge shows: Clients Connected.

Additionally, I receive this Null Reference Issue when close the unity editor play.

NullReferenceException: Object reference not set to an instance of an object

ROSBridgeLib.ROSBridgeWebSocketConnection.Disconnect () (at Assets/ROSBridgeLib/ROSBridgeWebSocketConnection.cs:170)
ROSCommsMain.OnApplicationQuit () (at Assets/Scripts/ROSCommsMain.cs:27)
edit retag flag offensive reopen merge delete

Closed for the following reason too localized by gvdhoorn
close date 2018-01-05 02:47:51.081402

Comments

This question is quite specific to a single package that is used in niche situations. The chances that ROS Answers visitors have experience with this is small. I would not expect any answers.

I would actually recommend to post this on the issue tracker of the pkg you're trying to use.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-05 02:42:40 -0500 )edit

@gvdhoorn thanks, I will do so.

arunavanag gravatar image arunavanag  ( 2018-01-05 02:44:24 -0500 )edit
1

If you do post an issue, please post a comment here linking us to that issue, so we keep things connected and future readers can find possible solutions.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-05 02:47:39 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-01-04 23:00:48 -0500

jihoonl gravatar image

Recently, siemens announced to rossharp to use ROS together with unity. I suggest to try this.

https://github.com/siemens/ros-sharp

edit flag offensive delete link more

Comments

I have a had a look at it before, but haven't yet tried out yet. I believe they are using the same websocket library as well, that is websocket-sharp.

arunavanag gravatar image arunavanag  ( 2018-01-05 01:37:42 -0500 )edit

I have tried the package from Siemens and it's working quite well (Could do a URDF-Import and send joint_state-messages from ROS to Unity to move the robot). BTW: Hello Jihoon ;)

NEngelhard gravatar image NEngelhard  ( 2018-01-05 02:46:29 -0500 )edit

Can I use this package to send message from unity to ROS? all the tutorials, point towards ROS to unity direction. I could do that with my existing code. I had issues sending message from unity to ROS.

arunavanag gravatar image arunavanag  ( 2018-01-05 02:48:09 -0500 )edit

They publish images from a virtual camera in unity to ROS, so it should work, but I haven't tried it yet.

NEngelhard gravatar image NEngelhard  ( 2018-01-05 05:51:43 -0500 )edit

Hi @NEngelhard I having hard time building it as an asset. I am unable to use ROS-Sharp at all.

How did you have it import ROSSharp and build it for ur project. Because websocketsharp rosbridgeclient and other dll files having issues with .net version mis match.

arunavanag gravatar image arunavanag  ( 2018-01-10 03:53:33 -0500 )edit

Reference: Issue 33 ;

Issue 21

arunavanag gravatar image arunavanag  ( 2018-01-10 03:53:41 -0500 )edit

Which Windows and ROS Versions are you using?

NEngelhard gravatar image NEngelhard  ( 2018-01-11 02:51:27 -0500 )edit

Windows 10 , ROS kinetic

arunavanag gravatar image arunavanag  ( 2018-01-11 02:56:44 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-01-04 19:25:57 -0500

Seen: 3,226 times

Last updated: Jan 04 '18