在qtcreator上进行ros机器人操作系统编程,并且配置CMakeLists.txt包含opencv2和aruco增强现实库

玩ros也有一段时间了,总是在vim环境下写代码,当遇到调试大的代码时,我还是喜欢用ide开发环境,方便好用。
因为在ubuntu开发环境下,所以我选择了用qt的开发环境,好用,也方便(以前用过qt),首先我们安装好qtcreator的开发环境,这个不说了。可以直接安装去官网下载安装包。当安装好qt后,我们进入一个ros功能包,我的是:
 roscd opencv_text 
进入我的功能包后,打开CMakeLists.txt文件,开始添加我们要添加的库的头文件和path。我把我的配置贴出来:`这里写代码片` 
cmake_minimum_required(VERSION 2.8.3)
project(opencv_text)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  rospy
  sensor_msgs
  std_msgs
  tf
)
set(ARUCO_PATH /usr/local)
SET(CMAKE_MODULE_PATH ${ARUCO_PATH}/lib/cmake )
SET(ARUCO_INCLUDE_DIRS ${ARUCO_PATH}/include/aruco )

find_package(OpenCV REQUIRED)
find_package(aruco REQUIRED )

INCLUDE(FindPkgConfig)

set(ROS_BUILD_TYPE Debug)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   sensor_msgs#   std_msgs
# )

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################

## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a run_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES opencv_text
#  CATKIN_DEPENDS cv_bridge image_transport roscpp rospy sensor_msgs std_msgs tf
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
)

## Declare a C++ library
# add_library(opencv_text
#   src/${PROJECT_NAME}/opencv_text.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(opencv_text ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
# add_executable(opencv_text_node src/opencv_text_node.cpp)

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(opencv_text_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
# target_link_libraries(opencv_text_node
#   ${catkin_LIBRARIES}
# )

#############
## 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
# install(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables and/or libraries for installation
# install(TARGETS opencv_text opencv_text_node
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_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_opencv_text.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)

include_directories(${ARUCO_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})

add_executable(aruco_marker src/aruco_marker.cpp)
target_link_libraries(aruco_marker ${catkin_LIBRARIES} ${OpenCV_LIBRARIES}  ${aruco_LIBS})

我们添加的主要是这几行:

set(ARUCO_PATH /usr/local)  #这句主要是设置一个变量
SET(CMAKE_MODULE_PATH ${ARUCO_PATH}/lib/cmake )#这句主要是设置CMAKE_MODULE_PATH的path,我们要按照自己的实际路径配置,我的在/usr/local/lib/cmake一般来说都在这里。
SET(ARUCO_INCLUDE_DIRS ${ARUCO_PATH}/include/aruco )#这个设置aruco的库的头文件,根据自己的实际位置包含

find_package(OpenCV REQUIRED)  #这两句都是调用预定义在CMAKE_MODULE_PATH下的Find<name>.cmake模块
find_package(aruco REQUIRED )

INCLUDE(FindPkgConfig)

set(ROS_BUILD_TYPE Debug)  #调试作用

include_directories(${ARUCO_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})#这句是包含三个库的文件

以上是主要添加的CMAKE配置文件的信息,如果大家添加.cPP文件,如下:

add_executable(aruco_marker src/aruco_marker.cpp)
target_link_libraries(aruco_marker ${catkin_LIBRARIES} ${OpenCV_LIBRARIES}  ${aruco_LIBS})

其中aruco_marker是我要生成的可执行文件,aruco_marker.cpp就是我们包里src/下的C渣渣文件,等这些搞定后我们就打开qtcreator,
这里写图片描述
然后点开open project,添加我们的cmakelists.txt文件,
这里写图片描述
点击打开,然后构建路径,定位到catkin_ws/build这个文件,最后点击下一步,
这里写图片描述
这里写图片描述
记得在在参数那里加上:-DCMAKE_BUILD_TYPE=Debug
否则你进行不了调试。最后就
ok
这里写图片描述
最后就可以开心的写代码了,尽量嗨!!!

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值