Skip to content

Instantly share code, notes, and snippets.

@lucasw
Created December 16, 2019 15:14
Show Gist options
  • Save lucasw/7ee9112d0070512091cfe813536f7de7 to your computer and use it in GitHub Desktop.
Save lucasw/7ee9112d0070512091cfe813536f7de7 to your computer and use it in GitHub Desktop.
Short scripts and one liners for ros1
@lucasw
Copy link
Author

lucasw commented Dec 16, 2019

Publish a small sensor_msgs Image from the command line

rostopic pub /image sensor_msgs/Image "{header: {seq: 0, stamp: now, frame_id: 'map'}, height: 8, width: 8, encoding: 'mono8', is_bigendian: 0, step: 8, data: '00000f00000000000000000f0000000000000000000000000000000000000000'}" -r 2

To make a custom image, make an 8x8 image in Gimp then export as png.
Then get the data string:

rosrun image_publisher image_publisher test.png __name:=image
rostopic echo /image/image_raw
header: 
  seq: 100
  stamp: 
    secs: 1576515370
    nsecs: 577321503
  frame_id: "camera"
height: 8
width: 8
encoding: "bgr8"
is_bigendian: 0
step: 24
data: [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255, 255, 255, 0, 0, 0, 255, 255, 255, 178, 178, 178, 255, 255, 255, 54, 54, 54, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 18, 18, 18, 255, 255, 255, 54, 54, 54, 182, 182, 182, 255, 255, 255, 255, 255, 255, 18, 18, 18, 255, 255, 255, 255, 255, 255, 255, 255, 255, 54, 54, 54, 242, 242, 242, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
rostopic pub /image sensor_msgs/Image "{header: {seq: 0, stamp: now, frame_id: 'map'}, height: 8, width: 8, encoding: 'bgr8', is_bigendian: 0, step: 24, data: [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255, 255, 255, 0, 0, 0, 255, 255, 255, 178, 178, 178, 255, 255, 255, 54, 54, 54, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 18, 18, 18, 255, 255, 255, 54, 54, 54, 182, 182, 182, 255, 255, 255, 255, 255, 255, 18, 18, 18, 255, 255, 255, 255, 255, 255, 255, 255, 255, 54, 54, 54, 242, 242, 242, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]}" -r 2

There ought to be a way to use command line tools to convert a binary image to a long string- first convert test.png test.bin` and then something to convert binary to a string rostopic pub likes, but xxd will print hex, while rostopic pub doesn't use that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment