Compilare un ROS Package

Descrizione: Questo tutorial comprende la toolchain (ovvero un insieme di programmi usati nello sviluppo di un prodotto) per compilare un package.

Livello Tutorial: PRINCIPIANTE

Prossimo Tutorial: Capire i ROS Nodes

Compilazione dei Package

Purché tutte le dipendenze di sistema del tuo package sono state installate, possiamo ora compilare il tuo nuovo package.

Nota: Se hai installato ROS usando apt o qualche altro package manager, dovresti già avere tutte le tue dipendenze.

Prima di continuare, ricorda di reperire il setup file del tuo ambiente se non lo hai già fatto. Su Ubuntu significa digitare:

$ source /opt/ros/groovy/setup.bash

Usare catkin_make

catkin_make è un tool da command line che aggiunge qualche comodità allo standard catkin workflow. Puoi immaginare che catkin_make combina le chiamate al cmake e make nello standard CMake workflow.

Uso:

# In a catkin workspace
$ catkin_make [make_targets] [-DCMAKE_VARIABLES=...]

Per le persone che non hanno familiarità con lo standard CMake workflow, esso si articola come segue:

Nota: Se si eseguono i comandi di seguito, esso non funzionerà, in quanto questo è solo un esempio di come CMake generalmente lavora.

# In a CMake project
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install  # (optionally)

Questo processo è eseguito per ogni CMake project. Invece i catkin projects possono essere compilati insieme nei workspaces. La compilazione da zero di molti package di catkin in un workspace segue questo workflow:

# In a catkin workspace
$ catkin_make
$ catkin_make install  # (optionally)

I comandi sopra compileranno alcuni catkin projects trovati nel folder src. Questo segue le raccomandazioni formulate da REP128. Se il tuo codice sorgente è in un luogo differente, come my_src allora bisogna chiamare il catkin_make come di seguito:

Nota: Se si eseguono i comandi di seguito, esso non funzionerà perché la directory my_src non esiste.

# In a catkin workspace
$ catkin_make --source my_src
$ catkin_make install --source my_src  # (optionally)

Per usi più avanzati di catkin_make vedi la documentazione: catkin/commands/catkin_make

Compilare il tuo Package

Per i lettori di questa pagina che sono in procinto di compilare i propri codici, si prega anche di dare un'occhiata al tutorial successivo (C++)/(Python) dal momento che potrebbe essere necessario modificare CMakeLists.txt.

Dovresti già avere un catkin workspace e un nuovo catkin package chiamato beginner_tutorials dal tutorial precedente, Creazione di un Package. Vai all'interno del catkin workspace se non ci sei già e guarda nel folder src:

$ cd ~/catkin_ws/
$ ls src
  • beginner_tutorials/  CMakeLists.txt@

Dovresti vedere che c'é un folder chiamato beginner_tutorials che hai creato con catkin_create_pkg nel precedente tutorial. Ora possiamo compilare quel package usando catkin_make:

$ catkin_make

Dovresti vedere un sacco di output da cmake e make, che dovrebbe essere simile a questo:

  • Base path: /home/user/catkin_ws
    Source space: /home/user/catkin_ws/src
    Build space: /home/user/catkin_ws/build
    Devel space: /home/user/catkin_ws/devel
    Install space: /home/user/catkin_ws/install
    ####
    #### Running command: "cmake /home/user/catkin_ws/src
    -DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel
    -DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install" in "/home/user/catkin_ws/build"
    ####
    -- The C compiler identification is GNU 4.2.1
    -- The CXX compiler identification is Clang 4.0.0
    -- Checking whether C compiler has -isysroot
    -- Checking whether C compiler has -isysroot - yes
    -- Checking whether C compiler supports OSX deployment target flag
    -- Checking whether C compiler supports OSX deployment target flag - yes
    -- Check for working C compiler: /usr/bin/gcc
    -- Check for working C compiler: /usr/bin/gcc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Using CATKIN_DEVEL_PREFIX: /tmp/catkin_ws/devel
    -- Using CMAKE_PREFIX_PATH: /opt/ros/groovy
    -- This workspace overlays: /opt/ros/groovy
    -- Found PythonInterp: /usr/bin/python (found version "2.7.1")
    -- Found PY_em: /usr/lib/python2.7/dist-packages/em.pyc
    -- Found gtest: gtests will be built
    -- catkin 0.5.51
    -- BUILD_SHARED_LIBS is on
    -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    -- ~~  traversing packages in topological order:
    -- ~~  - beginner_tutorials
    -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    -- +++ add_subdirectory(beginner_tutorials)
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/user/catkin_ws/build
    ####
    #### Running command: "make -j4" in "/home/user/catkin_ws/build"
    ####

Nota che catkin_make prima mostra quali paths si stanno usando per ciascuno degli 'spaces'. Gli spaces sono descritti nel REP128 e dalla documentazione sui catkin workspaces sul wiki: catkin/workspaces. La cosa importante da notare è che a causa di questi valori di default, diverse cartelle sono state create nel tuo catkin workspace. Dai un'occhiata con ls:

$ ls
  • build
    devel
    src

Il folder build è la locazione di default del build space ed è dove cmake e make sono chiamati per configurare e compilare i tuoi package. Il folder devel è la locazione di default del devel space, che è il luogo in cui vanno i tuoi eseguibili e le tue librerie prima che installi i tuoi package.

Ora che hai compilato il tuo ROS package, cominciamo a discutere riguardo i ROS Nodes.

Wiki: it/ROS/Tutorials/BuildingPackages (last edited 2013-10-20 19:47:45 by Il_Voza)