0
$\begingroup$

Rosanswers logo

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


Originally posted by joe.s on ROS Answers with karma: 162 on 2014-08-19

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by ahendrix with karma: 47576 on 2014-08-19

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by joe.s on 2014-08-20:
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)

Comment by ahendrix on 2014-08-20:
I'm not terribly familiar with the python sockets library, but that looks like a good start.

Comment by Muda on 2017-07-19:
Hi, I know this post is old but did you manage to get this working by any chance???

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

Comment by ahendrix on 2017-07-19:
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.

$\endgroup$

Your Answer

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