# how to use external libraries in ROS code?

Hi,

We have a GUI that was developed using Qt and now we are planning to use ROS in our code. Is it possible to integrate ROS with our existing Qt code?

In a general sense, how do we use external libraries such as Qt, OpenGL and user built libraries with ROS code? Thank you.

edit retag close delete

Sort by » oldest newest most voted

Not in the general sense, but rather specific to your question, you can have a look at RGBD-SLAM which uses qt and opengl. The CMakeLists.txt and manifest can be found here

Check out main.cpp, qtros.h and qtros.cpp to see how we moved the ROS spinning into a subclass of QThread to run the callbacks in parallel to the Qt application's event loop.

more

great, this worked for qt. I changed my CMakelits.txt similar to the one in the package and it works perfectly. I am posting a small description on how to do it in the below answer.  ( 2011-03-16 14:00:37 -0500 )edit

For OpenGl I just add the dependency in the manifest:

    <rosdep name="opengl"/>


It is solved in the core rosdep.yaml file (rosdep wiki) My CMakelists.txt entry looks like this:

rosbuild_add_executable(${PROJECT_NAME} src/main.cpp) target_link_libraries(${PROJECT_NAME} X11 m GL GLU glut)


In addition to the original ROS CMakelists. I assume you can do the same for QT. (if not I'm interested to know)

more

@KoenBuys: by specifying opengl it worked but I got undefined references for glut functions. So I also added rosdep name="glut", it didn't help. So I manually added the target_link_libraries statement with glut to my CMakelists.txt file. Do you think this will create issues in future?  ( 2011-03-16 07:29:13 -0500 )edit
Things like the 'opengl' above are abstractions for a package name. As koenbuys mentioned, these abstractions are converted to real package names for each distro in the rosdep.yaml files. You can find the abstraction and conversions for opengl in $ROS_ROOT/rosdep.yaml. ( 2011-03-16 08:06:19 -0500 )edit$ROS_ROOT/rosdep.yaml though is the last line of defence in trying to find the abstraction-conversion. The first rosdep.yaml any package looks in is inside the package itself, if it can't satisfy an abstraction there, it then looks in the stack rosdep.yaml, then finally $ROS_ROOT/rosdep.yaml. ( 2011-03-16 08:09:12 -0500 )edit If no abstraction exists for glut, simply create your own rosdep.yaml and put it in at your stack level (look at other stack rosdep.yaml's for examples). ( 2011-03-16 08:09:49 -0500 )edit @snorri: I did create a rosdep.yaml. I used the rosdep.yaml from geometry stack. I changed the line "ubuntu: libglut3-dev" with "ubuntu: libglut", "ubuntu: freeglut", "ubuntu: libglut3". None of them worked so I ended up changing Cmakelists.txt file ( 2011-03-16 08:16:58 -0500 )edit answered 2011-03-15 23:54:14 -0500 How are you currently building your qt program (e.g. qmake .pro files)? You might have to change the build system to use the cmake qt modules, but that can do everything that something like a qmake pro file can do without too much trouble and its something we've done with our qt gui's over the last six months. Eros has some packages built from qt that you can use for illustration. Don't mind that eros is about embedded and cross-compiling, the eros_qt_tutorials package can be just as easily not cross-compiled. It also has some python scripts to populate an ros package with the basic templates for a qt, or qt-ros program. See eros_python_tools for more information on these (roscreate-qt-pkg, roscreate-qt-ros-pkg). more ## Comments @snorri: I am currently building just a makefile containing paths and rules for QT (including moc,uic). I'll look into Eros. thank you ( 2011-03-16 07:04:40 -0500 )edit answered 2011-03-16 14:07:02 -0500 @KoenBuys answer works for OpenGL. And as @Felix Endres suggested I was able to get Qt working with my ROS package. here's some more detail on how: 1. edit your manifest.xml and add <rosdep name="qt4"/> 2. edit CMakelists.txt in your package and make it look similar to CMakelists.txt -> the line file(GLOB_RECURSE QT_MOC RELATIVE${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/local/.hpp src/mainwindow.h)* should include all the header files that use Qt functionality.

-> the line file(GLOB_RECURSE QT_SOURCES RELATIVE \${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/gicp-fallback.cpp src/mainwindow.cpp src/listener.cpp) should include all the cpp files that use Qt functionality.

Let me know if you have any issues. Thanks.

more