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

How can I publish hexadecimal values?

asked 2011-07-06 06:21:18 -0600

Khiya gravatar image

updated 2011-07-07 15:19:58 -0600

Eric Perko gravatar image


I haven't been able to find this on the ROS wiki: If I would like to create a publisher for hexadecimal, what type of message would I use? Specifically, I would like to publish this list to the \commands topic:

0x00 0x01 0x1F 0x7F

. I would then write a subscriber to \commands that took the hex values and sent them one by one to a serial port, where my motor controller understood them as motor commands and acted accordingly. I don't think they would publish under int32, would they?



edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-07-06 06:38:35 -0600

seanarm gravatar image

updated 2011-07-06 06:39:25 -0600

You could create a custom message that contains:

uint8[] commands

where 'commands' would contain your sequence of bytes.

edit flag offensive delete link more


Thanks. So there's no simple way of publishing hex numbers on a ROS topic?
Khiya gravatar image Khiya  ( 2011-07-06 07:20:40 -0600 )edit
I don't think you can get much simpler than this.
arebgun gravatar image arebgun  ( 2011-07-06 07:47:57 -0600 )edit
Thanks a lot then!
Khiya gravatar image Khiya  ( 2011-07-07 01:47:30 -0600 )edit
@Khiya, any number can be hex. It's just a matter of interpreting/printing it that way. It's actually sent across as binary of course. rostopic echo interprets it as a decimal number if it's an int, but you could just as easily print it as hex with `printf( "%x", value );`
Asomerville gravatar image Asomerville  ( 2011-07-07 16:11:27 -0600 )edit
Again, thanks you all. It hadn't quite clicked that hex is always just a sort of shorthand for binary. I appreciate your patience!
Khiya gravatar image Khiya  ( 2011-07-11 03:40:26 -0600 )edit

Question Tools


Asked: 2011-07-06 06:21:18 -0600

Seen: 1,848 times

Last updated: Jul 07 '11