Running a cpp program outside ROS and publishing messages

asked 2018-11-21 06:52:11 -0500

MSK gravatar image

Hi, I am trying to case specific drone which uses image processing, the code I built works ideally when it is a standalone but becomes terribly slow when run within ROS core. I would like to know whether there is any method of running the CPP code outside ROS yet be able to publish messages.

PS: I need the publishing part to send commands and operate the drone

edit retag flag offensive close merge delete


Pedantic and not an answer, but:

but becomes terribly slow when run within ROS core

ROS nodes do not run inside ROS core. They are stand-alone programs, just like other Linux binaries.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-21 13:50:58 -0500 )edit

But I have tested it in such a way, first as a standalone code and then with rosrun. I thought rosrun means it is running within the ros framework.

MSK gravatar image MSK  ( 2018-11-21 23:21:51 -0500 )edit

Technically, there is no way to "run <something> inside/within the ROS framework". That would imply that your entire control flow is taken over. That is not how typical ROS nodes work.

They are just programs that happen to use topics/services/actions for input-output.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-22 00:09:37 -0500 )edit

I'm not doubting what you saw, but perhaps, to avoid an xy-problem, you can give us a little bit more information about your setup.

How does your non-ROS program work? Does it interface directly with your camera for instance? How is this done in your ROS-based one? Etc.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-22 00:10:49 -0500 )edit

You can run your executable any way you want, they will behave the same given the conditions are the same. rosrun <package> <executable> will be the same with ./path/to/executable with some ROS python scripts wrapped around it. Most likely, your code is either faster because it doesn't receive anything (if other nodes are not running) and doesn't do anything or you are printing so much with ROS logging that it slows you down

OzzieTheHead gravatar image OzzieTheHead  ( 2021-05-06 10:29:54 -0500 )edit