前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >蓝桥ROS机器人之第一个功能包helloros

蓝桥ROS机器人之第一个功能包helloros

作者头像
zhangrelay
发布2022-05-01 10:21:25
4540
发布2022-05-01 10:21:25
举报

helloros

代码语言:javascript
复制
cmake_minimum_required(VERSION 2.8.3)
project(helloros)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

## 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
  roscpp
)

## 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 exec_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 exec_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
#   std_msgs  # Or other packages containing 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 exec_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 your 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 helloros
#  CATKIN_DEPENDS roscpp
#  DEPENDS system_lib
)

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

## 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}/helloros.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/helloros_node.cpp)
add_executable(${PROJECT_NAME}_node src/helloros.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}
# )
target_link_libraries(${PROJECT_NAME}_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 ${PROJECT_NAME} ${PROJECT_NAME}_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_helloros.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)
代码语言:javascript
复制
#include <ros/ros.h>

int main ( int argc , char ** argv ) {
// Initialize the ROS system . 
	ros::init( argc , argv , "hello_ros" ); 
// Establish this program as a ROS node . 
	ros::NodeHandle nh;
// Send some output as a log message . 
	ROS_INFO_STREAM( "Hello nihao, ROS!" );
}

代码语言:javascript
复制
shiyanlou:src/ $ catkin_create_pkg -h                                 [9:38:58]
usage: catkin_create_pkg [-h] [--meta] [-s [SYS_DEPS [SYS_DEPS ...]]]
                         [-b [BOOST_COMPS [BOOST_COMPS ...]]] [-V PKG_VERSION]
                         [-D DESCRIPTION] [-l LICENSE] [-a AUTHOR]
                         [-m MAINTAINER] [--rosdistro ROSDISTRO]
                         name [dependencies [dependencies ...]]

Creates a new catkin package

positional arguments:
  name                  The name for the package
  dependencies          Catkin package Dependencies

optional arguments:
  -h, --help            show this help message and exit
  --meta                Creates meta-package files
  -s [SYS_DEPS [SYS_DEPS ...]], --sys-deps [SYS_DEPS [SYS_DEPS ...]]
                        System Dependencies
  -b [BOOST_COMPS [BOOST_COMPS ...]], --boost-comps [BOOST_COMPS [BOOST_COMPS ...]]
                        Boost Components
  -V PKG_VERSION, --pkg_version PKG_VERSION
                        Initial Package version
  -D DESCRIPTION, --description DESCRIPTION
                        Description
  -l LICENSE, --license LICENSE
                        Name for License, (e.g. BSD, MIT, GPLv3...)
  -a AUTHOR, --author AUTHOR
                        A single author, may be used multiple times
  -m MAINTAINER, --maintainer MAINTAINER
                        A single maintainer, may be used multiple times
  --rosdistro ROSDISTRO
                        The ROS distro (default: environment variable
                        ROS_DISTRO if defined)
shiyanlou:src/ $ catkin_create_pkg helloros roscpp                    [9:39:09]
Created file helloros/package.xml
Created file helloros/CMakeLists.txt
Created folder helloros/include/helloros
Created folder helloros/src
Successfully created files in /home/shiyanlou/Code/helloros/src/helloros. Please adjust the values in package.xml.
shiyanlou:src/ $ cd helloros/src                                      [9:40:06]
shiyanlou:src/ $ ls                                                   [9:41:00]
shiyanlou:src/ $ gedit helloros.cpp                                   [9:41:05]

(gedit:1618): GVFS-RemoteVolumeMonitor-WARNING **: remote volume monitor with dbus name org.gtk.vfs.UDisks2VolumeMonitor is not supported

(gedit:1618): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
shiyanlou:src/ $ ls                                                   [9:48:07]
helloros.cpp
shiyanlou:src/ $ cd ..                                                [9:48:11]
shiyanlou:helloros/ $ l                                               [9:48:14]
\u603b\u7528\u91cf 28K
drwxrwxr-x 4 shiyanlou shiyanlou 4.0K 3\u6708  25 09:47 .
drwxrwxr-x 3 shiyanlou shiyanlou 4.0K 3\u6708  25 09:40 ..
-rw-rw-r-- 1 shiyanlou shiyanlou 6.8K 3\u6708  25 09:47 CMakeLists.txt
drwxrwxr-x 3 shiyanlou shiyanlou 4.0K 3\u6708  25 09:40 include
-rw-rw-r-- 1 shiyanlou shiyanlou 2.6K 3\u6708  25 09:40 package.xml
drwxrwxr-x 2 shiyanlou shiyanlou 4.0K 3\u6708  25 09:44 src
shiyanlou:helloros/ $ cd ..                                           [9:48:16]
shiyanlou:src/ $ cd ..                                                [9:48:21]
shiyanlou:helloros/ $ catkin_make                                     [9:48:23]
Base path: /home/shiyanlou/Code/helloros
Source space: /home/shiyanlou/Code/helloros/src
Build space: /home/shiyanlou/Code/helloros/build
Devel space: /home/shiyanlou/Code/helloros/devel
Install space: /home/shiyanlou/Code/helloros/install
Creating symlink "/home/shiyanlou/Code/helloros/src/CMakeLists.txt" pointing to "/opt/ros/kinetic/share/catkin/cmake/toplevel.cmake"
####
#### Running command: "cmake /home/shiyanlou/Code/helloros/src -DCATKIN_DEVEL_PREFIX=/home/shiyanlou/Code/helloros/devel -DCMAKE_INSTALL_PREFIX=/home/shiyanlou/Code/helloros/install -G Unix Makefiles" in "/home/shiyanlou/Code/helloros/build"
####
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/shiyanlou/Code/helloros/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/kinetic
-- This workspace overlays: /opt/ros/kinetic
-- Found PythonInterp: /usr/bin/python (found version "2.7.12") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/shiyanlou/Code/helloros/build/test_results
-- Found gmock sources under '/usr/src/gmock': gmock will be built
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found gtest sources under '/usr/src/gmock': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.14
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - helloros
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'helloros'
-- ==> add_subdirectory(helloros)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/shiyanlou/Code/helloros/build
####
#### Running command: "make -j4 -l4" in "/home/shiyanlou/Code/helloros/build"
####
Scanning dependencies of target helloros_node
[ 50%] Building CXX object helloros/CMakeFiles/helloros_node.dir/src/helloros.cpp.o
/home/shiyanlou/Code/helloros/src/helloros/src/helloros.cpp: In function \u2018int main(int, char**)\u2019:
/home/shiyanlou/Code/helloros/src/helloros/src/helloros.cpp:7:2: error: \u2018NodeHandlenh\u2019 is not a member of \u2018ros\u2019
  ros::NodeHandlenh;
  ^
helloros/CMakeFiles/helloros_node.dir/build.make:62: recipe for target 'helloros/CMakeFiles/helloros_node.dir/src/helloros.cpp.o' failed
make[2]: *** [helloros/CMakeFiles/helloros_node.dir/src/helloros.cpp.o] Error 1
CMakeFiles/Makefile2:907: recipe for target 'helloros/CMakeFiles/helloros_node.dir/all' failed
make[1]: *** [helloros/CMakeFiles/helloros_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
shiyanlou:helloros/ $ catkin_make                                     [9:48:42]
Base path: /home/shiyanlou/Code/helloros
Source space: /home/shiyanlou/Code/helloros/src
Build space: /home/shiyanlou/Code/helloros/build
Devel space: /home/shiyanlou/Code/helloros/devel
Install space: /home/shiyanlou/Code/helloros/install
####
#### Running command: "make cmake_check_build_system" in "/home/shiyanlou/Code/helloros/build"
####
####
#### Running command: "make -j4 -l4" in "/home/shiyanlou/Code/helloros/build"
####
Scanning dependencies of target helloros_node
[ 50%] Building CXX object helloros/CMakeFiles/helloros_node.dir/src/helloros.cpp.o
[100%] Linking CXX executable /home/shiyanlou/Code/helloros/devel/lib/helloros/helloros_node
[100%] Built target helloros_node
shiyanlou:helloros/ $ source devel/setup.zsh                          [9:49:29]
shiyanlou:helloros/ $ rosrun helloros helloros_node                   [9:49:50]
terminate called after throwing an instance of 'ros::InvalidNameException'
  what():  Character [ ] is not valid as the first character in Graph Resource Name [ hello_ros ].  Valid characters are a-z, A-Z, / and in some cases ~.
[1]    2109 abort (core dumped)  rosrun helloros helloros_node
shiyanlou:helloros/ $ rosrun helloros helloros_node                   [9:50:11]
terminate called after throwing an instance of 'ros::InvalidNameException'
  what():  Character [ ] is not valid as the first character in Graph Resource Name [ hello_ros ].  Valid characters are a-z, A-Z, / and in some cases ~.
[1]    2121 abort (core dumped)  rosrun helloros helloros_node
shiyanlou:helloros/ $ catkin_make                                     [9:50:27]
Base path: /home/shiyanlou/Code/helloros
Source space: /home/shiyanlou/Code/helloros/src
Build space: /home/shiyanlou/Code/helloros/build
Devel space: /home/shiyanlou/Code/helloros/devel
Install space: /home/shiyanlou/Code/helloros/install
####
#### Running command: "make cmake_check_build_system" in "/home/shiyanlou/Code/helloros/build"
####
####
#### Running command: "make -j4 -l4" in "/home/shiyanlou/Code/helloros/build"
####
Scanning dependencies of target helloros_node
[ 50%] Building CXX object helloros/CMakeFiles/helloros_node.dir/src/helloros.cpp.o
[100%] Linking CXX executable /home/shiyanlou/Code/helloros/devel/lib/helloros/helloros_node
[100%] Built target helloros_node
shiyanlou:helloros/ $ source devel/setup.zsh                          [9:51:22]
shiyanlou:helloros/ $ rosrun helloros helloros_node                   [9:51:33]
[ INFO] [1648173097.607466664]: Hello, ROS!
shiyanlou:helloros/ $ catkin_make                                     [9:51:37]
Base path: /home/shiyanlou/Code/helloros
Source space: /home/shiyanlou/Code/helloros/src
Build space: /home/shiyanlou/Code/helloros/build
Devel space: /home/shiyanlou/Code/helloros/devel
Install space: /home/shiyanlou/Code/helloros/install
####
#### Running command: "make cmake_check_build_system" in "/home/shiyanlou/Code/helloros/build"
####
####
#### Running command: "make -j4 -l4" in "/home/shiyanlou/Code/helloros/build"
####
Scanning dependencies of target helloros_node
[ 50%] Building CXX object helloros/CMakeFiles/helloros_node.dir/src/helloros.cpp.o
[100%] Linking CXX executable /home/shiyanlou/Code/helloros/devel/lib/helloros/helloros_node
[100%] Built target helloros_node
shiyanlou:helloros/ $ rosrun helloros helloros_node                   [9:52:34]
[ INFO] [1648173164.205589203]: Hello nihao, ROS!
shiyanlou:helloros/ $                                                 [9:52:44]
代码语言:javascript
复制
shiyanlou:~/ $ history                                               [11:37:17]
    1  git clone https://gitcode.net/ZhangRelay/v-rep_pro_edu_v3_6_2_ubuntu16_04.git
    2  tar
    3  tar --help
    4  tar --usage
    5  tar -xf v-rep_pro_edu_v3_6_2_ubuntu16_04/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04.tar.xz
    6  cd V-REP_PRO_EDU_V3_6_2_Ubuntu16_04
    7  ls
    8  gedit vrep.sh
    9  vrep.sh
   10  ./vrep.sh
   11  roscore
   12  rosrun turtlesim turtlesim_node
   13  rosrun turtlesim turtle_teleop_key
   14  rosrun turtlesim turtlesim_node
   15  rospack list
   16  catkin_create_pkg 
   17  catkin_create_pkg -h
   18  catkin_create_pkg helloros
   19  catkin_create_pkg -h
   20  catkin_create_pkg helloros roscpp
   21  cd helloros/src
   22  ls
   23  gedit helloros.cpp 
   24  ls
   25  cd ..
   26  l
   27  cd ..
   28  catkin_make
   29  source devel/setup.zsh
   30  roscore
   31  rosrun helloros helloros_node
   32  catkin_make
   33  source devel/setup.zsh
   34  rosrun helloros helloros_node
   35  catkin_make
   36  rosrun helloros helloros_node
shiyanlou:~/ $                                                       [11:37:20]
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-03-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档