ros程序一些注意事项
Posted 可峰科技
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ros程序一些注意事项相关的知识,希望对你有一定的参考价值。
编译ros程序按照统一的标准有利于自己的调试与发布
现在贴出来astra相机的一些配置,以供后续开发参考
1-CmakeList.txt
cmake_minimum_required(VERSION 3.5.1)
project(astra_camera)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "$CMAKE_C_FLAGS -fPIC -O3")
set(CMAKE_CXX_FLAGS_DEBUG "$CMAKE_CXX_FLAGS_DEBUG -fPIC -g")
set(CMAKE_CXX_FLAGS "$CMAKE_CXX_FLAGS -fPIC -O3")
set(CMAKE_CXX_FLAGS_DEBUG "$CMAKE_CXX_FLAGS_DEBUG -fPIC -g")
set(CMAKE_BUILD_TYPE "Release")
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif ()
find_package(catkin REQUIRED
cv_bridge
dynamic_reconfigure
image_geometry
image_transport
message_generation
roscpp
sensor_msgs
std_srvs
tf2
tf2_ros
message_filters
camera_info_manager
)
find_package(OpenCV REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Boost REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_search_module(LIBUVC REQUIRED libuvc)
if (NOT LIBUVC_FOUND)
message(FATAL_ERROR "libuvc is not found")
endif ()
pkg_search_module(GLOG REQUIRED libglog)
if (NOT GLOG_FOUND)
message(FATAL_ERROR "glog is not found")
endif()
execute_process(COMMAND uname -m OUTPUT_VARIABLE MACHINES)
execute_process(COMMAND getconf LONG_BIT OUTPUT_VARIABLE MACHINES_BIT)
message(STATUS "ORRBEC Machine : $MACHINES")
message(STATUS "ORRBEC Machine Bits : $MACHINES_BIT")
if (($MACHINES MATCHES "x86_64") AND ($MACHINES_BIT MATCHES "64"))
set(HOST_PLATFORM "x64")
elseif ($MACHINES MATCHES "arm")
set(HOST_PLATFORM "arm")
elseif (($MACHINES MATCHES "aarch64") AND ($MACHINES_BIT MATCHES "64"))
set(HOST_PLATFORM "arm64")
elseif (($MACHINES MATCHES "aarch64") AND ($MACHINES_BIT MATCHES "32"))
set(HOST_PLATFORM "arm")
endif ()
message(STATUS "ORRBEC : $HOST_PLATFORM")
message(STATUS "libuvc $libuvc_VERSION_MAJOR.$libuvc_VERSION_MINOR.$libuvc_VERSION_PATCH")
generate_dynamic_reconfigure_options(cfg/Astra.cfg)
add_message_files(
FILES
DeviceInfo.msg
Extrinsics.msg
Metadata.msg
)
add_service_files(
FILES
GetBool.srv
GetCameraInfo.srv
GetCameraParams.srv
GetDeviceInfo.srv
GetInt32.srv
GetString.srv
SetInt32.srv
SetString.srv
)
generate_messages(
DEPENDENCIES
std_msgs sensor_msgs
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES $PROJECT_NAME
CATKIN_DEPENDS
cv_bridge
dynamic_reconfigure
image_geometry
image_transport
message_runtime
roscpp
sensor_msgs
tf2
tf2_ros
std_srvs
message_filters
camera_info_manager
)
add_definitions(-Dlibuvc_VERSION_MAJOR=$libuvc_VERSION_MAJOR)
add_definitions(-Dlibuvc_VERSION_MINOR=$libuvc_VERSION_MINOR)
add_definitions(-Dlibuvc_VERSION_PATCH=$libuvc_VERSION_PATCH)
set(ORBBEC_OPENNI2_REDIST
"$CMAKE_CURRENT_SOURCE_DIR/include/openni2_redist/$HOST_PLATFORM")
link_directories($ORBBEC_OPENNI2_REDIST
$catkin_LINK_DIRS
$OpenCV_LIBS)
add_library($PROJECT_NAME
src/point_cloud_proc/point_cloud_xyz.cpp
src/point_cloud_proc/point_cloud_xyzrgb.cpp
src/d2c_filter.cpp
src/device_listener.cpp
src/ob_camera_info.cpp
src/ob_frame_listener.cpp
src/ob_timer_filter.cpp
src/ob_camera_node_factory.cpp
src/ob_camera_node.cpp
src/ros_service.cpp
src/utils.cpp
src/uvc_camera_driver.cpp
)
target_include_directories($PROJECT_NAME PUBLIC
$<BUILD_INTERFACE:$CMAKE_CURRENT_BINARY_DIR/include>
$<BUILD_INTERFACE:$CMAKE_CURRENT_SOURCE_DIR/include>
$<INSTALL_INTERFACE:include>
$catkin_INCLUDE_DIRS
$Boost_INCLUDE_DIRS
$libuvc_INCLUDE_DIRS
$OpenCV_INCLUDED_DIRS
)
target_link_libraries($PROJECT_NAME
-lOpenNI2
-L$ORBBEC_OPENNI2_REDIST
$catkin_LIBRARIES
$CMAKE_THREAD_LIBS_INIT
$OpenCV_LIBS
$GLOG_LIBRARIES
$LIBUVC_LIBRARIES
)
add_dependencies($PROJECT_NAME
$PROJECT_NAME_gencfg
$PROJECT_NAME_generate_messages_cpp)
add_dependencies($PROJECT_NAME $catkin_EXPORTED_TARGETS)
add_executable($PROJECT_NAME_node
src/main.cpp
)
target_include_directories($PROJECT_NAME_node PUBLIC
$<BUILD_INTERFACE:$CMAKE_CURRENT_BINARY_DIR/include>
$<BUILD_INTERFACE:$CMAKE_CURRENT_SOURCE_DIR/include>
$<INSTALL_INTERFACE:include>
$catkin_INCLUDE_DIRS
$Boost_INCLUDE_DIRS
$LIBUVC_INCLUDE_DIRS
$OpenCV_INCLUDED_DIRS
)
target_link_libraries($PROJECT_NAME_node
-lOpenNI2
-L$ORBBEC_OPENNI2_REDIST
$PROJECT_NAME
$catkin_LIBRARIES
$CMAKE_THREAD_LIBS_INIT
$OpenCV_LIBS
$LIBUVC_LIBRARIES
$GLOG_LIBRARIES
)
add_executable(list_devices_node
src/list_devices_node.cpp
)
target_include_directories(list_devices_node PUBLIC
$<BUILD_INTERFACE:$CMAKE_CURRENT_BINARY_DIR/include>
$<BUILD_INTERFACE:$CMAKE_CURRENT_SOURCE_DIR/include>
$<INSTALL_INTERFACE:include>
$catkin_INCLUDE_DIRS
$Boost_INCLUDE_DIRS
$LIBUVC_INCLUDE_DIRS
$OpenCV_INCLUDED_DIRS
)
target_link_libraries(list_devices_node
-lOpenNI2
-L$ORBBEC_OPENNI2_REDIST
$PROJECT_NAME
$catkin_LIBRARIES
$CMAKE_THREAD_LIBS_INIT
$OpenCV_LIBS
$GLOG_LIBRARIES
$LIBUVC_LIBRARIES
)
install(TARGETS $PROJECT_NAME
$PROJECT_NAME_node
list_devices_node
ARCHIVE DESTINATION $CATKIN_PACKAGE_LIB_DESTINATION
LIBRARY DESTINATION $CATKIN_PACKAGE_LIB_DESTINATION
RUNTIME DESTINATION $CATKIN_PACKAGE_BIN_DESTINATION
)
install(FILES $ORBBEC_OPENNI2_REDIST/libOpenNI2.so
DESTINATION $CATKIN_PACKAGE_LIB_DESTINATION/
)
install(DIRECTORY $ORBBEC_OPENNI2_REDIST/OpenNI2
DESTINATION $CATKIN_PACKAGE_LIB_DESTINATION/
)
install(DIRECTORY include
DESTINATION $CATKIN_PACKAGE_INCLUDE_DESTINATION/
)
install(FILES 56-orbbec-usb.rules
DESTINATION $CATKIN_PACKAGE_LIB_DESTINATION/$PROJECT_NAME
)
install(DIRECTORY scripts
DESTINATION $CATKIN_PACKAGE_LIB_DESTINATION/$PROJECT_NAME
)
install(FILES 56-orbbec-usb.rules
DESTINATION $CATKIN_PACKAGE_SHARE_DESTINATION
)
install(DIRECTORY scripts
DESTINATION $CATKIN_PACKAGE_SHARE_DESTINATION
)
install(DIRECTORY launch
DESTINATION $CATKIN_PACKAGE_SHARE_DESTINATION
)
install(DIRECTORY params
DESTINATION $CATKIN_PACKAGE_SHARE_DESTINATION
)
2-package.xml
<?xml version="1.0"?>
<package format="2">
<name>astra_camera</name>
<version>1.1.4</version>
<description>Drivers for Orbbec Astra Devices. </description>
<license>Apache License 2.0</license>
<maintainer email="mocun@orbbec.com">Mo Cun</maintainer>
<buildtool_depend>catkin</buildtool_depend>
<depend>cv_bridge</depend>
<depend>dynamic_reconfigure</depend>
<depend>git</depend>
<depend>image_geometry</depend>
<depend>image_transport</depend>
<depend>libudev-dev</depend>
<depend>libusb-1.0-dev</depend>
<depend>message_generation</depend>
<depend>message_runtime</depend>
<depend>rgbd_launch</depend>
<depend>roscpp</depend>
<depend>sensor_msgs</depend>
<depend>std_srvs</depend>
<depend>tf2_ros</depend>
<depend>tf2</depend>
<depend>message_filters</depend>
<depend>camera_info_manager</depend>
</package>
3-cfg文件
#!/usr/bin/env python
PACKAGE = 'astra_camera'
from dynamic_reconfigure.parameter_generator_catkin import *
gen = ParameterGenerator()
# TODO Only offer modes supported by known hardware
output_mode_enum = gen.enum([
gen.const("1024_768_5", int_t, 1, "1024x768@5"),
gen.const("1024_768_10", int_t, 2, "1024x768@10"),
gen.const("1024_768_15", int_t, 3, "1024x768@15"),
gen.const("1024_768_30", int_t, 4, "1024x768@30"),
gen.const("1024_768_60", int_t, 5, "1024x768@60"),
gen.const("1280_1024_5", int_t, 6, "1280x1024@5"),
gen.const("1280_1024_10", int_t, 7, "1280x1024@10"),
gen.const("1280_1024_15", int_t, 8, "1280x1024@15"),
gen.const("1280_1024_30", int_t, 9, "1280x1024@30"),
gen.const("1280_1024_60", int_t, 10, "1280x1024@60"),
gen.const("1280_720_5", int_t, 11, "1280x720@5"),
gen.const("1280_720_10", int_t, 12, "1280x720@10"),
gen.const("1280_720_15", int_t, 13, "1280x720@15"),
gen.const("1280_720_30", int_t, 14, "1280x720@30"),
gen.const("1280_720_60", int_t, 15, "1280x720@60"),
gen.const("1280_800_5", int_t, 16, "1280x800@5"),
gen.const("1280_800_10", int_t, 17, "1280x800@10"),
gen.const("1280_800_15", int_t, 18, "1280x800@15"),
gen.const("1280_800_30", int_t, 19, "1280x800@30"),
gen.const("1280_800_60", int_t, 20, "1280x800@60"),
gen.const("160_120_5", int_t, 21, "160x120@5"),
gen.const("160_120_10", int_t, 22, "160x120@10"),
gen.const("160_120_15", int_t, 23, "160x120@15"),
gen.const("160_120_30", int_t, 24, "160x120@30"),
gen.const("160_120_60", int_t, 25, "160x120@60"),
gen.const("240_180_5", int_t, 26, "240x180@5"),
gen.const("240_180_10", int_t, 27, "240x180@10"),
gen.const("240_180_15", int_t, 28, "240x180@15"),
gen.const("240_180_30", int_t, 29, "240x180@30"),
gen.const("240_180_60", int_t, 30, "240x180@60"),
gen.const("320_180_5", int_t, 31, "320x180@5"),
gen.const("320_180_10", int_t, 32, "320x180@10"),
gen.const("320_180_15", int_t, 33, "320x180@15"),
gen.const("320_180_30", int_t, 34, "320x180@30"),
gen.const("320_180_60", int_t, 35, "320x180@60"),
gen.const("320_200_5", int_t, 36, "320x200@5"),
gen.const("320_200_10", int_t, 37, "320x200@10"),
gen.const("320_200_15", int_t, 38, "320x200@15"),
gen.const("320_200_30", int_t, 39, "320x200@30"),
gen.const("320_200_60", int_t, 40, "320x200@60"),
gen.const("320_240_5", int_t, 41, "320x240@5"),
gen.const("320_240_10", int_t, 42, "320x240@10"),
gen.const("320_240_15", int_t, 43, "320x240@15"),
gen.const("320_240_30", int_t, 44, "320x240@30"),
gen.const("320_240_60", int_t, 45, "320x240@60"),
gen.const("480_360_5", int_t, 46, "480x360@5"),
gen.const("480_360_10", int_t, 47, "480x360@10"),
gen.const("480_360_15", int_t, 48, "480x360@15"),
gen.const("480_360_30", int_t, 49, "480x360@30"),
gen.const("480_360_60", int_t, 50, "480x360@60"),
gen.const("512_384_5", int_t, 51, "512x384@5"),
gen.const("512_384_10", int_t, 52, "512x384@10"),
gen.const("512_384_15", int_t, 53, "512x384@15"),
gen.const("512_384_30", int_t, 54, "512x384@30"),
gen.const("512_384_60", int_t, 55, "512x384@60"),
gen.const("640_360_5", int_t, 56, "640x360@5"),
gen.const("640_360_10", int_t, 57, "640x360@10"),
gen.const("640_360_15", int_t, 58, "640x360@15"),
gen.const("640_360_30", int_t, 59, "640x360@30"),
gen.const("640_360_60", int_t, 60, "640x360@60"),
gen.const("640_400_5", int_t, 61, "640x400@5"),
gen.const("640_400_10", int_t, 62, "640x400@10"),
gen.const("640_400_15", int_t, 63, "640x400@15"),
gen.const("640_400_30", int_t, 64, "640x400@30"),
gen.const("640_400_60", int_t, 65, "640x400@60"),
gen.const("640_480_5", int_t, 66, "640x480@5"),
gen.const("640_480_10", int_t, 67, "640x480@10"),
gen.const("640_480_15", int_t, 68, "640x480@15"),
gen.const("640_480_30", int_t, 69, "640x480@30"),
gen.const("640_480_60"以上是关于ros程序一些注意事项的主要内容,如果未能解决你的问题,请参考以下文章
第四天:SLAM智能小车DIY乐趣-小车控制ROS驱动包开发
完整的Ubuntu20.04+ROS+PX4+Anaconda+PyTorch+GPU+CUDA+CUDNN+XTdrone配置智能无人机开发环境搭建过程