Membuat ROS Package¶
ROS package adalah sebuah directory dimana source dari software itu berada. Selain itu, library, dataset, message, service, dan action files, third-party modules juga berada di dalam directory tersebut. Lebih detail mengenai ROS package bisa di baca lebih lengkap disini.
Berikut contoh membuat ROS package
#cd ke catkin workspace, kemudian src
cd ros_catkin_ws/src
#add required libraries as arguments for catkin_create_pkg
catkin_create_pkg rospy roscpp std_msgs
Dengan command catkin_create_pkg, CMakeLists.txt dan package.xml akan terbuat otomatis dan dependencies yang di berikan pada command tersebut secara otomatis akan ada di dalam kedua file tersebut.
CMakeLists.txt¶
Berikut adalah contoh CMakeLists.txt pada package roscpp_simple_service_client.
0 cmake_minimum_required(VERSION 2.8.3)
1 project(roscpp_simple_service_client)
2
3 ## Compile as C++11, supported in ROS Kinetic and newer
4 add_compile_options(-std=c++11)
5
6 find_package(catkin REQUIRED COMPONENTS
7 ros_custom_msgs
8 roscpp
9 )
10
11 catkin_package(
12 )
13
14 include_directories(
15 # include
16 ${catkin_INCLUDE_DIRS}
17 )
18
19 #Executable
20 add_executable(simple_server
21 ros/src/simple_server.cpp
22 )
23 add_dependencies(simple_server
24 ${catkin_EXPORTED_TARGETS}
25 )
26 target_link_libraries(simple_server
27 ${catkin_LIBRARIES}
28 )
29
30 add_executable(simple_client
31 ros/src/simple_client.cpp
32 )
33 add_dependencies(simple_client
34 ${catkin_EXPORTED_TARGETS}
35 )
36 target_link_libraries(simple_client
37 ${catkin_LIBRARIES}
38 )
package.xml¶
Semua dependencies yang dibutuhkan dari package tersebut harus di definisikan dalam file ini.
Berikut adalah contoh package.xml pada package roscpp_simple_service_client.
0 <?xml version="1.0"?>
1 <package format="2">
2 <name>roscpp_simple_service_client</name>
3 <version>0.0.0</version>
4 <description>The roscpp_simple_service_client package</description>
5
6 <author email="mwasil@outlook.co.id">Mohammad Wasil</author>
7 <maintainer email="mwasil@outlook.co.id">Mohammad Wasil</maintainer>
8
9 <license>GPL-3.0</license>
10
11 <buildtool_depend>catkin</buildtool_depend>
12 <build_depend>ros_custom_msgs</build_depend>
13 <build_depend>roscpp</build_depend>
14
15 <build_export_depend>ros_custom_msgs</build_export_depend>
16 <build_export_depend>roscpp</build_export_depend>
17
18 <exec_depend>ros_custom_msgs</exec_depend>
19 <exec_depend>roscpp</exec_depend>
20
21 </package>