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

Message Semantics - Unity to ROS over ROSBridge

asked 2018-02-23 03:02:07 -0600

updated 2018-02-24 22:27:21 -0600

Hello,

I am trying to exchange my message between windows 10 Unity 20.17.2 and ROS1. I can subscribe to my ros topic and I am able to listen to messages in my unity environment sent from ros1.

for subscribing I am sending:

`{"op": "subscribe", "topic": "/talker", "type": "std_msgs/String"}`

from windows to ros1 using ros_bridge websockets.

However, when I publish I cannot see my message on my ros terminal. I advertise first:

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

which reflects over ros bridge as 1 client is connected.

Then I publish my message:

{"op": "publish", "topic": "/talker", "msg": {"data" : _my_message }}

My subscriber node: (just using straight away from the tutorial)

#include "ros/ros.h"
#include "std_msgs/String.h"

void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}

int main(int argc, char **argv)
{

  ros::init(argc, argv, "sub_node");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subscribe("talker", 0, chatterCallback);
  ros::spin();
  return 0;
}

But I never receive any message. I have converted my message into JSON as per rosbridge protocol: { "op": "publish",(optional) "id": <string>,"topic": <string>, "msg": <json>}

I am using the websocketsharp library to create my WebSocket connection, which should not really be an issue as I can listen to messages from ros and establish the connection. It should be something wrong with my publisher node or data model I am sending.

Any pointers, please?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-02-24 22:23:50 -0600

updated 2018-02-24 22:25:00 -0600

Ok, I finally figured this out. For publishing I had to enclose my string into another set of inverted comma send:

{"op": "publish", "topic": "/talker", "msg": {"data" : "_my_message " }}

basically, I used Wireshark to sniff the network, and checked my working ROS to Unity channel, and figured out what was missing on my Unity to ROS medium.

Also, I realized I was using Simple Json to convert my message to json which is not really important.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-02-23 03:02:07 -0600

Seen: 1,515 times

Last updated: Feb 24 '18