ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Unity Mavros client disconnects automatically

asked 2017-10-05 15:13:42 -0500

hermonir gravatar image

updated 2017-10-06 02:30:31 -0500

gvdhoorn gravatar image

I'm using ROSBridgeLib in Unity3D 2017.1 to connect to ROS on Ubuntu.

The turtlesim project works fine. I can control the turtle from Unity. I wrote a test subscriber to see talker messages ("/chatter") and it works fine as well.

When I tried connecting to mavros topics, for example "/mavros/global_position/compass_hdg", ROSBridge immediately disconnects the client. It says:

[INFO] [1505825883.664602]: [Client 21] Subscribed to /mavros/global_position/compass_hdg [INFO] [1505825883.910471]: Client disconnected. 0 clients total.

Here is my subscriber code:

using ROSBridgeLib;
using ROSBridgeLib.std_msgs;
using ROSBridgeLib.turtlesim;
using System.Collections;
using SimpleJSON;
using UnityEngine;

public class MavrosGlobalpositionCompassHdg : ROSBridgeSubscriber {

    public new static string GetMessageTopic() {
        return "/mavros/global_position/compass_hdg";
    }  

    public new static string GetMessageType() {
        return "std_msgs/Float64";
    }

    public new static ROSBridgeMsg ParseMessage(JSONNode msg) {
        return new Float64Msg(msg);
    }

    public new static void CallBack(ROSBridgeMsg msg) {
        Float64Msg hdg = (Float64Msg) msg;
        Debug.Log("MAVROS message: " + hdg.ToString());
    }
}

Thanks for any help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-10-09 02:41:16 -0500

hermonir gravatar image

Fixed it.

The problem was in Float64Msg.cs in ROSBridgeLib. Inside Float64Msg(JSONNode msg), it tried parsing a json string as a double. Here is the fixed method:

public Float64Msg(JSONNode msg) {
    _data = double.Parse(msg["data"]);
}
edit flag offensive delete link more

Comments

If you feel this is a problem with ROSBridgeLib it would be nice if you could report it to the authors, so they can include the fix in their sources.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-09 03:40:05 -0500 )edit

+1 for reporting back and telling us the solution btw.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-09 03:40:21 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-10-05 15:13:42 -0500

Seen: 323 times

Last updated: Oct 09 '17