0
$\begingroup$

I have a custom ROS1 Test.msg message which I use in roscpp Noetic:

uint8[] a
uint8[] b

I use uint8[] to represent strings, because I can't use simple string type in my custom message and I have read that char was deprecated: "char: deprecated alias for uint8" as per https://wiki.ros.org/msg.

When I try to publish a new message of type Test with rostopic echo [TAB][TAB] autocomplete, the following appears:

rostopic pub /myTopic Test "a: !!binary ""
b: !!binary """

How can I use this !!binary "" YAML tag to input a simple string like "test" in the message contents (I can not modify the message definition).

$\endgroup$

1 Answer 1

0
$\begingroup$

You can do something like this in bash to convert a string to an uint8 array:

rostopic pub /myTopic Test \
  "a: [ \
    $(echo "Hello" | xxd -p -c 1 | xargs -I{} printf "%d\n" 0x{} | paste -sd,) \
  ]"

This will give you

---
a: [72, 101, 108, 108, 111, 10]
---
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.