Can a ROS node be created outside a catkin workspa

2019-08-31 16:25发布

I want to create a ROS publisher node outside a catkin workspace. Can it be created?

标签: ros catkin
2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-31 16:54

Yes, in Python, you can write ROS nodes outside your catkin workspace.

Launch your roscore and then run the Python script in a new terminal normally like python filename and it runs as it would if you had placed in inside your catkin workspace and built and sourced it.

I have successfully created subscriber and publisher nodes and run them on an actual TurtleBot2 without the nodes being inside the catkin workspace.

I don't think the method I have described works for C++. It only works for Python. In C++ you will have to link the libraries while compiling. So, check that. For example, we do g++ filename.cpp -lm, where -lm links the math library to be used in the filename.cpp, so you might need to check how to do that. On the other hand, it is easier to just add the file in your catkin workspace or just shift to Python.

You have to include ros/ros.h and std_msgs/message_name.h where message_name is replaced by whatever message you're using in code. You might find these files somewhere or you can get the source code of the files online by searching.

查看更多
smile是对你的礼貌
3楼-- · 2019-08-31 17:15

Of course you can. Treat ROS like any other cpp library or python package.

In python you have to keep PYTHONPATH environment variable pointing to ros packages in /opt/ros/kinetic/lib/python2.7/dist-packages.

In cpp you have to tell compiler where to look for includes (/opt/ros/kinetic/include), libraries (/opt/ros/kinetic/lib) and which library to import. For the simplest application -lroscpp -lrostime -lrosconsole should be sufficient. Ex:

g++ node.cpp -o node -I/opt/ros/kinetic/include -L/opt/ros/kinetic/lib -lroscpp -lrostime -lrosconsole

Remember that you still need ros environment variables like ROS_MASTER_URI.

However, I don't know if there is an easy way to generate custom ros messages without using catkin_make and cmake files.

查看更多
登录 后发表回答