ROS libraries [closed]
Hi all, I would like to add ROS support to my own software. What libraries do I add in my makefile?
Thanks
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Hi all, I would like to add ROS support to my own software. What libraries do I add in my makefile?
Thanks
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.
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
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.
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.
If it is part of the binary you're building, the yes.
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)/~
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
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?
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.
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)Asked: 2011-02-28 16:22:45 -0600
Seen: 2,708 times
Last updated: Mar 02 '11
cannot find libraries when linking
Error importing android library into android project using rosjava.jar
what's difference between rosmake & makefile?
Specifying non-standard library path
How to build ROS nodes with other libraries?
Replacing wrapper ROS package for external library - best practices?