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

Integrating C++/Python projects into ROS

asked 2014-10-03 10:48:31 -0500

2ROS0 gravatar image

updated 2014-10-06 10:04:00 -0500

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.

edit retag flag offensive close merge delete

Comments

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?

dornhege gravatar image dornhege  ( 2014-10-04 08:38:37 -0500 )edit

What are the pros and cons of both?

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

2ROS0 gravatar image 2ROS0  ( 2014-10-06 09:18:14 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-10-05 16:46:40 -0500

kunaltyagi gravatar image

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.

edit flag offensive delete link more

Comments

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).

2ROS0 gravatar image 2ROS0  ( 2014-10-06 10:06:24 -0500 )edit

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!

nhphuong gravatar image nhphuong  ( 2019-05-15 03:53:43 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2014-10-03 10:48:31 -0500

Seen: 1,351 times

Last updated: Oct 06 '14