Terry
Terry

Reputation: 21

Using UDP transport data to Non-ROS computer over UDP

I want to transport the data from a ROS computer to the Non-ROS computer over the UDP.

To specify my works now :

I have a LiDAR(Sick TiM561) and I can launch it by the ROS computer successfully, and I can use the "Subscriber" to get the data of the LiDAR now using roscpp which is the c++ code in the ROS. Now,I need to transport the LiDAR's data to the microbox which is a MATLAB-based computer (this PC that you can build your program in it by MATLAB). But I'm not familiar in the c++ code, could someone can suggest me or direct me how to modify the code as below and add it into my roscpp code? Thanks in advance!

For the structure, the Micro box is the client, ROS PC is server. This is the code of my roscpp:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "sensor_msgs/LaserScan.h"
void laser_msg_Callback(const sensor_msgs::LaserScan::ConstPtr& scan)
{
for (int x=0;x< scan->ranges.size();x++)
{
  ROS_INFO("I heard: [%f]", scan->ranges[x]);
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "sick_listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("scan", 811, laser_msg_Callback);
ros::spin();
return 0;
}

And this code maybe is what I need:

UdpClient client;
public IPAddress serverIP = IPAddress.Parse("140.124.35.1");
public Form1()
{
    InitializeComponent();
    client = new UdpClient();
}

public void SendData()
{
    client.Connect(serverIP, 3000);
    byte[] data = Encoding.ASCII.GetBytes("Hi, I'm new client.");
    client.Send(data, data.Length);
    DoListening();
}
public void DoListening()
{
    IPEndPoint adress = new IPEndPoint(serverIP, 3000);
    byte[] receivedbytes = client.Receive(ref adress);
    string recieved = Encoding.ASCII.GetString(receivedbytes);

    MessageBox.Show("Recieved: " + recieved);
}
private void button1_Click(object sender, EventArgs e)
{
    SendData();
}

Upvotes: 2

Views: 3472

Answers (1)

datjko
datjko

Reputation: 383

I'd think a possible way to go for you is to check out the rossereal implementations. I'm not familiar with development for microbox, probably none of the rosserial supported platforms works with it out of the box, but I thought it's what the rosserial for: to provide a ros-compliant protocol for communicating a ros server with non-ros devices. For that your ros-nodes' code don't even need to know if the client's publishers and/or subscribers are regular ros nodes running on a ros-running computer or they are mimicked by a rosserial client on a non-ros device.

When I used it, the efficiency of rosserial_windows was good for me. I was able to control a rather high resolution camera attached to a windows computer connected to a network with several ros running computers to transfer image messages from the camera with a satisfiable rate.

If none of the available rosserial implementations are compatible with microbox then you may want to check out the rosserial's "Adding Support for New Hardware" and the existing code for rosserial_embeddedlinux to implement the rosserial-like connection thru udp.

Upvotes: 1

Related Questions