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

ROS libraries [closed]

asked 2011-02-28 16:22:45 -0600

aswin gravatar image

Hi all, I would like to add ROS support to my own software. What libraries do I add in my makefile?

Thanks

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by SL Remy
close date 2017-07-21 00:30:37.046784

Comments

aswin, please update your question instead of replying in answers below.
tfoote gravatar image tfoote  ( 2011-03-02 10:44:05 -0600 )edit
And others you can also update your answers as aswin updates his question.
tfoote gravatar image tfoote  ( 2011-03-02 10:44:24 -0600 )edit

10 Answers

Sort by ยป oldest newest most voted
5

answered 2011-03-02 10:47:34 -0600

tfoote gravatar image

The best place to start for understanding how to integrate with ROS is to go through the ROS tutorials They will help you learn how to use ROS and what ROS provides. Once you have that understanding adding ROS to your existing code should be relatively easy.

edit flag offensive delete link more
4

answered 2011-03-01 12:14:20 -0600

aswin gravatar image

Hi, I think the following should do. Building your own files as a library and then linking it.

rosbuild_add_library(Util src/libTF.cpp src/Pose3DCache.cpp src/Pose3D.cpp) rosbuild_add_executable(testTF src/test/main.cpp) target_link_libraries(testTF Util)

Thanks

edit flag offensive delete link more
2

answered 2011-02-28 19:03:04 -0600

sam gravatar image

You may need to install ROS first. And use "roscreate-pkg pkg_name std_msgs rospy roscpp" to create basic package using ros libraries. If you want to edit in makefile, use cmake (CMakeLists.txt) in your project.

edit flag offensive delete link more
0

answered 2011-03-01 00:24:44 -0600

sam gravatar image

hi~ Have you noticed that my source file also doesn't have any ROS header files include? It means you don't have to change any source file code you have. What you have to do is only change cmake configuration like the example I provided. And finally you just have to add link to ros by type :

cd "your ros project directory(you have to change this)";
export ROS_PACKAGE_PATH=$PWD:$ROS_PACKAGE_PATH;
rosmake;

And you will be able to compile all of your original source code with ROS cmake utilities. If later you want to use ROS tools, you can add any header files you like.

edit flag offensive delete link more
0

answered 2011-03-01 21:27:04 -0600

dornhege gravatar image

If it is part of the binary you're building, the yes.

edit flag offensive delete link more
-1

answered 2011-02-28 19:43:53 -0600

aswin gravatar image

Hi, Thanks for the reply. I have installed ROS. But how do I compile using the normal g++ compiler. Consider I have the following makefile. Assume hellomake.cc has some ROS code. What do i have to change. What extra LIBS should i add?

Thanks again.

IDIR =../include CC=gcc CFLAGS=-I$(IDIR)

ODIR=obj LDIR =../lib

LIBS=-lm -lgsl

_DEPS = hellomake.h DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

_OBJ = hellomake.o hellofunc.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))

$(ODIR)/%.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS)

hellomake: $(OBJ) gcc -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean

clean: rm -f $(ODIR)/.o *~ core $(INCDIR)/~

edit flag offensive delete link more
-1

answered 2011-02-28 23:04:25 -0600

aswin gravatar image

Hi Sam, Thanks for the work around and detailed reply. Unfortunately I have over 30 non-ROS source files. If there is no other choice, I'll have to do this.

Cheers

edit flag offensive delete link more
-1

answered 2011-03-01 11:14:50 -0600

aswin gravatar image

Hi, In your example t.c is an executable right. What if I want to compile a utility source file? Do I still use rosbuild_add_executable?

edit flag offensive delete link more
-1

answered 2011-03-02 10:49:47 -0600

aswin gravatar image

Hi all, Thanks for your replies, it works now. I compiled my source files as a library (say util.lib) using rosbuild_add_library and then linked third party libraries to util.lib using target_link_libraries.

edit flag offensive delete link more
-1

answered 2011-02-28 21:55:52 -0600

sam gravatar image

updated 2011-02-28 22:19:03 -0600

Because embedded ROS node in your program maybe hard (how hard I don't know~XD), so if we try to think another way that we can try to embedded other libs in ROS node to get the same outcome. Because ROS node also use main...return 0, so you can add any function you like in ROS node just you write your normal program without ROS utilties. And link all the libraries to ROS node (Cmake).

I can show one example:
If my program is written in opengl. It maybe hard to embedded ROS in my opengl program. So I create a normal ROS package, put all the opengl program in that ROS node, and link opengl libs in CMakeLists.txt. That my CMakeLists.txt is

 cmake_minimum_required(VERSION 2.4.6)
 include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
 # Set the build type.  Options are:
 #  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
 #  Debug          : w/ debug symbols, w/o optimization
 #  Release        : w/o debug symbols, w/ optimization
 #  RelWithDebInfo : w/ debug symbols, w/ optimization
 #  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
 #set(ROS_BUILD_TYPE RelWithDebInfo)

 rosbuild_init()

 #set the default path for built executables to the "bin" directory
 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
 #set the default path for built libraries to the "lib" directory
 set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

 #uncomment if you have defined messages
 #rosbuild_genmsg()
 #uncomment if you have defined services
 #rosbuild_gensrv()

 #common commands for building c++ executables and libraries
 #rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
 #target_link_libraries(${PROJECT_NAME} another_library)
 #rosbuild_add_boost_directories()
 #rosbuild_link_boost(${PROJECT_NAME} thread)
 #rosbuild_add_executable(example examples/example.cpp)
 #target_link_libraries(example ${PROJECT_NAME})
 rosbuild_add_executable(opengl_test src/t.c)
 target_link_libraries(opengl_test /usr/lib/libGL.so)
 target_link_libraries(opengl_test /usr/lib/libX11.a)
 target_link_libraries(opengl_test /usr/lib/libX11.so)

And the opengl code is (just the normal opengl program):

 //t.c
 #include <stdio.h>
 #include <stdlib.h>     
 #include <GL/glx.h>    /* this includes the necessary X      headers */
 #include <GL/gl.h>

 #include <X11/X.h>    /* X11 constant (e.g. TrueColor) */
 #include <X11/keysym.h>

 static int snglBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, None};
 static int dblBuf[]  = {GLX_RGBA, GLX_DEPTH_SIZE, 16,      GLX_DOUBLEBUFFER, None};

 Display   *dpy;
 Window     win;
 GLfloat    xAngle = 42.0, yAngle = 82.0, zAngle = 112.0;
 GLboolean  doubleBuffer = GL_TRUE;

 void fatalError(char *message)
 {
   fprintf(stderr, "main: %s\n", message);
   exit(1);
 }

 void redraw(void)
 {
   static GLboolean   displayListInited = GL_FALSE;

   if (displayListInited)
   {
     /* if display list already exists, just execute it */
     glCallList(1);
   }
   else
   {
     /* otherwise compile and execute to create the display list      */
     glNewList(1, GL_COMPILE_AND_EXECUTE);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

     /* front face */
     glBegin(GL_QUADS);
       glColor3f(0.0, 0.7, 0.1);  /* green */
       glVertex3f(-1.0, 1.0, 1.0);
       glVertex3f(1.0, 1.0, 1.0);
       glVertex3f(1.0, -1.0, 1.0);
       glVertex3f(-1.0, -1.0, 1.0);

       /* back face */
       glColor3f(0.9, 1.0, 0.0);  /* yellow */
       glVertex3f(-1.0, 1.0, -1.0);
       glVertex3f(1.0, 1.0, -1.0);
       glVertex3f(1.0, -1.0, -1.0);
       glVertex3f(-1.0, -1.0, -1.0);

       /* top side face */
       glColor3f(0.2, 0.2, 1.0);  /* blue */
       glVertex3f(-1.0, 1.0 ...
(more)
edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-02-28 16:22:45 -0600

Seen: 2,715 times

Last updated: Mar 02 '11