0
$\begingroup$

I'm relatively new to ROS2 and have been relying on tutorials and online resources to navigate my learning journey. Currently, I'm trying to send an image via a service request, but despite my efforts, I haven't been successful.

The idea is simple, the request is empty and the response is an image.

If any of you have experience or knowledge in this area and could provide some guidance, or advice, or even share code examples, I would be immensely grateful. Your assistance would greatly contribute to my understanding and progress with ROS2.

Thank you all in advance for your time and support!

$\endgroup$

1 Answer 1

0
$\begingroup$

I'd leave you with a roadmap since you do not specify what type of language you are using, and if you have any other constraints.

You'd have to start by creating a custom service. There are a lot of tutorials online about creating your services, but the ROS 2 official documentation is the most useful to me. You'll find the tutorials for C++ and Python there.

If we choose to call the service MyCustomImage, then the MyCustomImage.srv file would look something like this:

---
sensor_msgs/Image response

The above block essentially translates the requirement

the request is empty and the response is an image

into ROS 2 terms.

From there on, you can continue to follow the creating a custom service tutorial for the implementation of the server and client nodes (these are language-specific, although the underlying concept translates to both of them).

The basic structure of your server node (the node which provides the image) would be "to read a particular device/file for an image, to convert the image to the sensor_msgs/Image format, and return the response". This is what would need to be defined in the service callback.

Similarly, the client node (the one that requests the server for an image), would call the MyCustomImage service and receive the response. From there you choose what to do with your image data.

NOTE: You can simplify your life by using the cv_bridge package to convert your OpenCV images to ROS 2 sensor_msgs/Image messages, but this is out of the scope, as you have not specified if you are using OpenCV or not.

$\endgroup$
2
  • $\begingroup$ Hi ssarkar, sorry for the lack of information. I'm using C++ and OpenCV. I'm already using the cv_bridge, but I'm having some troubles to create de srv and edit the cmakelist properly.. Every time I build I got some errors. Do you have any code example that creates a new srv? $\endgroup$
    – Heron Saba
    Commented Apr 15 at 11:42
  • $\begingroup$ It's better if you can edit your post to upload the code sample you have written, and also a log of the error you are getting - this will help attract more eyeballs to your problem $\endgroup$
    – ssarkar
    Commented Apr 15 at 13:24

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.