0
$\begingroup$

Rosanswers logo

Hi,

I have a C++ project for robot navigation developed in Visual Studio in simulation. There is currently nothing ROS about it.

I want to first visualize my outputs in Rviz and later send output commands to my robot. The robot already has a ROS end bringup node. Are there any best practices for writing ROS wrappers or tutorials for getting C++/Python code integrated into ROS?

Thank you.

Update: Based on @dornhege comment I'm going to keep the code as separate as possible for now. Adding more details to question.. So I have a main function that generates outputs at a frequency of 4Hz. I have to do some logic and simple manipulation of this data in order to make it Rviz or robot ready.

The way I understand it, I should modify this main function to include a ROS publisher and make it into a ROS node. And then write a ROS listener that I can use to do all the manipulations to publish messages for RViz? I was wondering if it really is that simple and will there by any communication problems? Anything big things I should be wary of?

Thank you.


Originally posted by 2ROS0 on ROS Answers with karma: 1133 on 2014-10-03

Post score: 0


Original comments

Comment by dornhege on 2014-10-04:
This is a bit of a generic question. Do you want to turn the code that you have into ROS code or do you want to "only" interface ROS and keep the code as separate as possible?

Comment by 2ROS0 on 2014-10-06:
What are the pros and cons of both?

I think I'll keep the code as separate as possible for now. Question updated.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Hi

There can be a lot of ways to answer your question, and like @dornhege said, you just want to make it to ROS, or you want to make a ROS interface.

I prefer making a ROS only interface, so if someone wants to use the code on some other platform, it is easy to do so.

This is what we have:

  • A bunch of code which does Image Processing using OpenCV, and has no ROS in it. It gives a 2 point output (size of image, location of desired object)
  • A bunch of code which has a lot of logic in python to generate motion commands based on above output.

This is what we do:

  • A file vision_ros.cpp which contains subscribers and publishers and then calls the non-ROS opencv code like we call it from terminal, with one frame at a time. We earlier used sockets, so we had to change just one file.
  • Another file which uses the published data from vision_ros.cpp to pass on the information to python files by calling the respective functions.

So, the code stays in the format as it is, with little changes, is modular, and easy to port.


Originally posted by kunaltyagi with karma: 105 on 2014-10-05

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by 2ROS0 on 2014-10-06:
Thank you, that helps.

So I have c++ code that just has to be called once. And I have getter functions that give me required outputs at a good enough frequency. I just want to ROS wrap it and send those outputs to Rviz (after some small manipulations).

Comment by nhphuong on 2019-05-15:
Hi, can you share with me the part of vision_ros.cpp where it "calls the non-ROS opencv code like we call it from terminal"? I'm struggling with this part despite having the same situation as you described. All I need now is a c++ code which do 3 things consecutively:

  1. Navigate to folder containing the python file of opencv project

  2. Execute it with cmd "python3 file.py"

  3. Read the output stream of it to publish data of each line

Thanks so much for your support!

$\endgroup$

Your Answer

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