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

Inserting ROS code in a NON-ROS project

asked 2018-10-02 12:57:06 -0600

hassamsheikh1 gravatar image


I have a non-ros simulation running in which I receive xy-coordinates. Now I want to pass those coordinates to my ROS node. How do I short circuit my other program to do this since running the ROS package requires me to use rosrun package name filename. I can not seem to find a solution or relevant keywords for this scenario.

edit retag flag offensive close merge delete


running the ROS package requires me to use rosrun package name filename

nitpick: but that is not needed at all.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-03 02:52:34 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2018-10-02 13:09:18 -0600

A quick and dirty method to achieve this is using a system call to execute the rostopic command line utility.

The command:

rostopic pub -1 my_topic geometry_msgs/vector3 '{x: 0.1, y: 1.1, z: 2.1}'

Will publish a single message of the topic then return. You can execute this command from a non ROS c program using the system function from stdlib.h. There are better ways of achieving this but none of them are as simple as this.

It's worth noting that you can execute ROS nodes by simply executing the binary as well as using rosrun. It's just a bit trickier to find where those binaries actually exist if you're not used to the directory structure.

Hope this helps.

edit flag offensive delete link more


I just found out that if you are using ROSPY, you do not need to do any of that stuff. Just use ros code as standard python code. It will work

hassamsheikh1 gravatar image hassamsheikh1  ( 2018-10-02 13:11:05 -0600 )edit

answered 2018-10-02 13:07:33 -0600

hassamsheikh1 gravatar image

I just figured out, for ROSPY you do not need to do any of that stuff. You can simply use ros code like standard python code.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-10-02 12:57:06 -0600

Seen: 302 times

Last updated: Oct 02 '18