ws/src/$ catkin_create_pkg [pkg name] [의존성패키지]
$ls
CMakeLists.txt
package.xml
src
include
건드려야 하는 파일은 package.xml과 CMakeLists.txt
의존하는 패키지로는 roscpp std_msg 등을 달 수 있다.
의존성 패키지는 이처럼 패키지 생성시에 지정할 수도 있지만 나중에 package.xml에 직접 입력해도 된다.
<build_depend>roscpp</build_depend> //패키지.xml 의존성 패키지 지정 부분. 각각 하나씩 써준다.
<?xml> //문서 문법 정의. 안건드리면 됨
<package> </package> //여기부터 안의 내용이 설정 부분
<name> //패키지 이름. 패키지 이름 변경을 원하면 폴더 이름을 바꾸는게 아니라 여길 건드려줘야 함. 아마 폴더도 맞춰줘야 할..걸..?
<buildtool_depend> //이건 그냥 catkin이다.
<build_depend> //build할때 의존하는 package
<exec_depend> //실행할 때 의존하는 package
실제 코드를 찾아보니 쌩판 모르겠는 가 등장했다. 아마 build와 exec할 때 항상 depend하는 1차 의존성 패키지를 저렇게 처리하는 듯하다.
<buildtool_depend>catkin</buildtool_depend>
<depend>roscpp</depend>
<depend>std_msgs</depend>
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>rospy</exec_depend>
<test_depend>python-mock</test_depend>
ROS가 CMake라는 빌드 방식을 이용하기 때문에 빌드 설정 파일인 CMakeLists파일도 건드려준다.
src말고 패키지 폴더 안의 CM 파일을 수정할것.
⚠️CMake는 C언어와 관련이 없다. Make 방식을 확장한 Cross platform Make방식이 CMake임.
project(my_first_ros_pkg) //여기 들어가는 건 패키지명. package.xml에 있는 name과 같아야함.
find_package(catkin REQUIRED COMPONENTS roscpp std_msg)
//catkin build시에 필요한 패키지 표시. 이게 없으면 빌드시 에러가 뜬다. 즉, 빌드 전 미리 깔게 만드는것.
#find_package(Boost REQUIRED COMPONENTS system)
//ROS 패키지 말고 시스템 패키지 기술. Boost 이용시 system이라는 패키지가 필요하다.
# catkin_python_setup()
//python 이용시 설정. 파이썬 설치 프로세스인 setup.py을 부른다.
# add_message_files(//사용할 메세지를 추가하는 부분.
# FILES //패키지 폴더의 msg폴더 안에 .msg확장자 파일 중 이용할 파일 기입
# Message1.msg //이 메세지 파일이 msg에 있어야함.
# Message2.msg
# )
//이 위로는 custom msg 아래는 원래 있는 msg pkg
# generate_messages( // 의존하는 msg설정
# DEPENDENCIES //dependencies 옵션에 의하여 다음에 나열한 메세지 패키지를 이용하겠다.
# std_msgs # Or other packages containing msgs
# )
catkin_package( //catkin build option
# INCLUDE_DIRS include //패키지 내부 폴더인 include의 헤더파일을 이용하겠다는 뜻.
# LIBRARIES my_first_ros_pkg
# CATKIN_DEPENDS roscpp std_msg ////////////////////////아 짜증나 그만할래
# DEPENDS system_lib
)
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
${catkin_INCLUDE_DIRS}
)
## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/my_first_ros_pkg.cpp
# )
## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
**add_executable(${PROJECT_NAME}_node src/my_first_ros_pkg_node.cpp)**
#**뒤의 파일을 빌드해서 앞의 이름으로 실행파일을 만들라는 소리**
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
## Add cmake target dependencies of the executable
## same as for the library above
**add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})**
## Specify libraries to link a library or executable target against
**target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES}**
)
차량비전시스템 목금까지 추가등록 4명 대면
#############
## Install ##
#############
# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )
## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_my_first_ros_pkg.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)