<<TOC(4)>> === roscreate 사용하기 === 본격적으로 패키지를 만들기 전에 `roscreate-pkg` 명령행 도구의 사용법을 알아봅시다. 모든 ROS 패키지들은 [[Manifest|manifests]], [[CMakeLists|CMakeLists.txt]], mainpage.dox, Makefiles 등 비슷한 파일들이 공통으로 들어 있습니다. 직접 손으로 위의 파일들을 만드는 것은 매우 수고로울 뿐 아니라, 빌드관련 파일과 매니패스트의 작성 시 사소한 실수때문에 에러가 생길 수 있습니다. roscreate-pkg는 이 과정을 자동화 해서 새로운 패키지를 만드는 데 도움을 줍니다. 현재 폴더 안에 새로운 패키지를 만드려면 아래와 같이 입력합니다. {{{ # roscreate-pkg [package_name] }}} 만들면서 패키지의 의존성을 정해줄 수 도 있습니다. {{{ # roscreate-pkg [package_name] [depend1] [depend2] [depend3] }}} === 새로운 ROS Package 작성하기 === 이제 홈이나 프로젝트 폴더로 이동해 자습서에서 사용할 {{{beginner_tutorials}}} 패키지를 만들게 될 것입니다. 의존성이 있는 패키지로는 기본 ROS 패키지에 포함된 [[std_msgs]], [[roscpp]], [[rospy]]를 지정할 것입니다. 이제 ~/ros_workspace/sandbox 폴더로 이동합니다. {{{ $ cd ~/ros_workspace/sandbox }}} 또는 Fuerte나 그 이전의 버전을 사용하고 계신다면 간단히 아래의 방법을 사용할 수도 있습니다. {{{ $ roscd $ cd sandbox }}} 그 다음 새로운 패키지를 만들어 봅시다. {{{ $ roscreate-pkg beginner_tutorials std_msgs rospy roscpp }}} 명령이 실행되면 아래와 같은 화면이 출력될 것입니다. {{{ Creating package directory ~/fuerte_workspace/sandbox/beginner_tutorials Creating include directory ~/fuerte_workspace/sandbox/beginner_tutorials/include/beginner_tutorials Creating cpp source directory ~/ros/ros_tutorials/beginner_tutorials/src Creating python source directory ~/fuerte_workspace/sandbox/beginner_tutorials/src/beginner_tutorials Creating package file ~/fuerte_workspace/sandbox/beginner_tutorials/Makefile Creating package file ~/fuerte_workspace/sandbox/beginner_tutorials/manifest.xml Creating package file ~/fuerte_workspace/sandbox/beginner_tutorials/CMakeLists.txt Creating package file ~/fuerte_workspace/sandbox/beginner_tutorials/mainpage.dox Please edit beginner_tutorials/manifest.xml and mainpage.dox to finish creating your package }}} 우리는 `beginner_tutorials/manifest.xml`파일에 좀 더 관심을 가질 필요가 있습니다. [[Manifest|manifests]]는 ROS에서 패키지의 빌드, 실행, 문서화 과정 모두에 영향을 미치기 때문에 링크를 통해 세부사항을 알아두시면 좋습니다. 이제 ROS가 새로 만들어진 패키지도 찾아낼 수 있는지 알아보겠습니다. 저장된 경로에 변경사항이 생겼을 때 새로고침을 해 주는 ''rospack profile''을 사용해 새로운 패키지를 찾아낼 수 있게 해줍니다. {{{ $ rospack profile $ rospack find beginner_tutorials }}} {{{ YOUR_PACKAGE_PATH/beginner_tutorials }}} 만약 실패했다면, 이는 ROS가 새로 만들어진 패키지를 찾지 못했다는 것입니다. $ROS_PACKAGE_PATH와 관련이 깊은 문제이므로 자신이 설치한 방법(소스코드 또는 바이너리)의 설치 지침을 찾아 검토해 보시길 바랍니다. 만약 $ROS_PACKAGE_PATH 경로 밖의 폴더에 새 패키지를 만드셨을 경우는 새 경로를 $ROS_PACKAGE_PATH에 지정해 주시고 ros_workspace안의 setup.bash를 쉘에 다시 등록(re-source)시켜 주시기 바랍니다. 이제 패키지의 안으로 이동하겠습니다. {{{ $ roscd beginner_tutorials $ pwd }}} {{{ YOUR_PACKAGE_PATH/beginner_tutorials }}} === 1차 패키지 의존성 === 앞서 {{{roscreate-pkg}}}를 사용할 때, 몇 가지 의존 패키지들을 같이 입력했었습니다. 이들을 1차 패키지 의존성(first-order dependencies)라 하고 {{{rospack}}} 도구를 이용해 다시 확인할 수 있습니다. {{{#!wiki blue/solid (Jan 9, 2013) There is [[https://github.com/ros/rospack/issues/4|a bug]] reported and already fixed in [[rospack]] in `groovy`; it may take some time to be reflected in the packages. If you see [[http://answers.ros.org/question/51555/beginner-tutorials-segmentation-fault-with-rospack-depends1/?comment=51762#comment-51762|an issue similar to this]] with the next command, you can skip to the following command. }}} {{{ $ rospack depends1 beginner_tutorials }}} {{{ std_msgs rospy roscpp }}} 보시다시피 {{{rospack}}}가 {{{roscreate-pkg}}} 명령을 쓸 때 입력한 의존성들을 모두 보여주는 것을 확인할 수 있습니다. 이 패키지 의존성은 매니페스트 파일에 기록되어 있습니다. 한번 매니페스트 파일을 살펴보겠습니다. {{{ $ roscd beginner_tutorials $ cat manifest.xml }}} {{{ <package> ... <depend package="std_msgs"/> <depend package="rospy"/> <depend package="roscpp"/> </package> }}} === 간접 패키지 의존성 === 많은 경우에 한개의 의존성은 자기 나름대로의 의존성을 가지고 있습니다. 예를 들면, `rospy`는 두개의 의존성을 품고 있습니다. {{{#!wiki blue/solid (Jan 9, 2013) There is [[https://github.com/ros/rospack/issues/4|a bug]] reported and already fixed in [[rospack]] in `groovy`; it may take some time to be reflected in the packages. If you see [[http://answers.ros.org/question/51555/beginner-tutorials-segmentation-fault-with-rospack-depends1/?comment=51762#comment-51762|an issue similar to this]] with the next command, you can skip to the following command. }}} {{{ $ rospack depends1 rospy }}} {{{ roslib roslang }}} {{{rospack}}}은 재귀적으로 이러한 내포된 의존성까지 알아낼 수 있습니다. {{{ $ rospack depends beginner_tutorials }}} {{{ rospack roslib std_msgs rosgraph_msgs rosbuild roslang rospy cpp_common roscpp_traits rostime roscpp_serialization xmlrpcpp rosconsole roscpp }}} 참고: Fuerte에서는 목록이 많이 짧아졌습니다. {{{ std_msgs roslang rospy roscpp }}} === ROS 클라이언트 라이브러리 === 혹시 이전 예제에서 보았던 {{{rospy}}}와 {{{roscpp}}}의 의존성에 대해 궁금해 하실 분들이 계실 지 모르겠습니다. {{{rospy}}}와 {{{roscpp}}}는 [[Client Libraries || ROS 클라이언트 라이브러리]]의 일종입니다. 클라이언트 라이브러리는 ROS상에서 서로 다른 프로그래밍 언어로 통신하는 것을 가능케 합니다. 각각 {{{rospy}}}는 python, {{{roscpp}}}는 C++에 대한 클라이언트 라이브러리입니다. === 복습 === 이 자습서에서 소개한 명령어들을 적어보겠습니다. * roscreate-pkg = ros+create-pkg : 새로운 ROS 패키지를 만드는 데 필요한 파일을 자동으로 만들어 줍니다. * rospack = ros+pack(age) : ROS 패키지와 관련된 정보를 알려줍니다. * rosstack = ros+stack : ROS 스택과 관련된 정보를 알려줍니다.