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

Publish message across UDP to a user defined port

asked 2014-08-19 13:46:40 -0600

joe.s gravatar image

I'm creating a node that will be subscribing to another node and then publishing a message. This message will need to be sent to a user defined IP address/ port combination and contain plain-text to be parsed by a non-ROS enabled Raspberry Pi listening on that port.

Outside of having to publish a text string to a port, I believe this should be a fairly standard Pub/Sub node. I see this page regarding UDPROS but there seems to be little, new information.

Does anyone have any suggestions?

The message needs to be of this format:

(sent to an IP address/ Port combination) 100 0
101 -1
102 100
103 0
104 0
105 0
106 0

That is to say, six lines, with each line having the first three characters be an ID number and the next three be either -1, 0, 100 (aka "do nothing", "move to 0% open", "move to 100% open").

I know that publishing to a port is pretty trivial in Python and only a little more complicated in C++... but how would that translate to ROS messages?

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-08-19 20:24:19 -0600

ahendrix gravatar image

You should really just be using raw UDP sockets here. (Or running ROS on your Pi)

ROS publishers and subscribers are explicitly set up to automatically discover and establish connections between one another, and can't be configured to connect to arbitrary network endpoints. It's very difficult to receive messages from a ROS node without implementing your own ROS client library.

The various ROS publishers and subscribers also have a custom serialization and deserialization protocol that is intentionally hidden from the user - unless you're implementing a full ROS client library, you shouldn't need to worry about it.

edit flag offensive delete link more

Comments

I think I'm doing this correctly:

UDP_IP = "127.0.0.1" #debug
UDP_PORT = 9000
Program_Name = "./handcontrol"
define_pos= ilimb_define_pos.split(" ")
    print define_pos
    Digit_ID = define_pos[0]
    Command = define_pos[1]

    Message = "%s %d %s\n"%(Program_Name, Digid_ID, Command)            

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.sendto(Message, (UDP_IP, UDP_PORT))

    rospy.loginfo(Message)
    #pub.publish(Message)
joe.s gravatar image joe.s  ( 2014-08-20 16:47:59 -0600 )edit

I'm not terribly familiar with the python sockets library, but that looks like a good start.

ahendrix gravatar image ahendrix  ( 2014-08-20 17:00:40 -0600 )edit

Hi, I know this post is old but did you manage to get this working by any chance???

Thanks in advance!!!!!!!!!!!!

Muda gravatar image Muda  ( 2017-07-19 06:29:14 -0600 )edit

It looks like the OP got this working with the code sample provided. If you're having trouble I suggest you ask a new question.

ahendrix gravatar image ahendrix  ( 2017-07-19 10:35:37 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-08-19 13:46:40 -0600

Seen: 3,184 times

Last updated: Aug 19 '14