0
$\begingroup$

Rosanswers logo

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?


Originally posted by arunavanag on ROS Answers with karma: 277 on 2018-02-23

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by arunavanag with karma: 277 on 2018-02-24

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.