【ROS】 ros学习日记(1)

发布时间:2026/10/16 12:54:08
【ROS】 ros学习日记(1) ros学习日记1ros安装测试ros小乌龟启动启动小乌龟并测试小乌龟不动错误排查HelloWorld1.创建工作空间并初始化2.进入 src 创建 ros 包并添加依赖3.使用C编写程序ros的安装、测试和helloworld学习的为赵虚左老师的教程 1.老师的文档 2.老师的视频ros安装直接诶使用鱼香肉丝的ros一键安装命令如下wgethttp://fishros.com/install-Ofishros.fishros测试ros小乌龟启动启动小乌龟并测试首先启动三个命令行(ctrl alt T)1.命令行1键入: bashroscor2.命令行2键入以下命令(此时会弹出图形化界面) bash rosrun turtlesim turtlesim_node可以输入tur后按Tab自动补全3.命令行3键入以下命令(在3中可以通过上下左右控制2中乌龟的运动)rosrun turtlesim turtle_teleop_key最终结果如下所示:小乌龟不动错误排查1.光标是否停留在rosrun turtlesim turtle_teleop_key界面2.输入法是否为英文HelloWorld先创建一个工作空间→再创建一个功能包→编辑源文件 →编辑配置文件→编译并执行1.创建工作空间并初始化mkdir-p自定义空间名称/srccd自定义空间名称 catkin_make比如mkdir-pdemo001_ws/srccddemo001_ws catkin_make上述命令首先会创建一个工作空间以及一个 src 子目录然后再进入工作空间调用 catkin_make命令编译。2.进入 src 创建 ros 包并添加依赖cdsrc catkin_create_pkg 自定义ROS包名 roscpp rospy std_msgs比如cdsrc catkin_create_pkg helloworld roscpp rospy std_msg上述命令会在工作空间下生成一个功能包该功能包依赖于 roscpp、rospy 与 std_msgs其中roscpp是使用C实现的库而rospy则是使用python实现的库std_msgs是标准消息库创建ROS功能包时一般都会依赖这三个库实现。运行效果如下canvolcano:~$mkdir-pdemo001_ws/src canvolcano:~$cddemo001_ws/ canvolcano:~/demo001_ws$ catkin_make Base path: /home/can/demo001_ws Source space: /home/can/demo001_ws/src Build space: /home/can/demo001_ws/build Devel space: /home/can/demo001_ws/devel Install space: /home/can/demo001_ws/install Creating symlink/home/can/demo001_ws/src/CMakeLists.txtpointing to/opt/ros/noetic/share/catkin/cmake/toplevel.cmake######## Running command: cmake /home/can/demo001_ws/src -DCATKIN_DEVEL_PREFIX/home/can/demo001_ws/devel -DCMAKE_INSTALL_PREFIX/home/can/demo001_ws/install -G Unix Makefiles in /home/can/demo001_ws/build####-- The C compiler identification is GNU9.4.0 -- The CXX compiler identification is GNU9.4.0 -- Checkforworking C compiler: /usr/bin/cc -- Checkforworking 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-- Checkforworking CXX compiler: /usr/bin/c -- Checkforworking 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/can/demo001_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Found PythonInterp: /usr/bin/python3(found suitable version3.8.10, minimum required is3)-- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Found PY_em: /usr/lib/python3/dist-packages/em.py -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing()-- Using CATKIN_TEST_RESULTS_DIR: /home/can/demo001_ws/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under/usr/src/googletest:gtests will be built -- Found gmock sources under/usr/src/googletest:gmock will be built -- Found PythonInterp: /usr/bin/python3(found version3.8.10)-- Found Threads: TRUE -- Using Python nosetests: /usr/bin/nosetests3 -- catkin0.8.12 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on -- Configuringdone-- Generatingdone-- Build files have been written to: /home/can/demo001_ws/build######## Running command: make -j12 -l12 in /home/can/demo001_ws/build####canvolcano:~/demo001_ws$cdsrc canvolcano:~/demo001_ws/src$ catkin_create_pkg helloworld roscpp rospy std_msg Createdfilehelloworld/package.xml Createdfilehelloworld/CMakeLists.txt Created folder helloworld/include/helloworld Created folder helloworld/src Successfully created filesin/home/can/demo001_ws/src/helloworld. Please adjust the valuesinpackage.xml. canvolcano:~/demo001_ws/src$3.使用C编写程序1.进入 ros 包的 src 目录编辑源文件cd自定义的包我这里是helloworld所以cdhelloworldcdsrc新建一个cpp文档touchhelloworld_c.cpp然后在文档中输入以下代码#includeros/ros.hintmain(intargc,char*argv[]){//执行 ros 节点初始化ros::init(argc,argv,hello);//创建 ros 节点句柄(非必须)ros::NodeHandle n;//控制台输出 hello worldROS_INFO(hello world!);return0;}2.编辑 ros 包下的 Cmakelist.txt文件把下面两块的注释去掉并修改一个是在136行一个是149-151行136行的如下add_executable(步骤3的源文件名 src/步骤3的源文件名.cpp)改为add_executable(haha src/helloworld_c.cpp)另一个如下target_link_libraries(步骤3的源文件名${catkin_LIBRARIES})改为target_link_libraries(haha${catkin_LIBRARIES})3.进入工作空间目录并编译cd自定义空间名称 catkin_make4.执行新的终端先启动命令行1roscore再启动命令行2又一个新的终端cd工作空间source./devel/setup.bash rosrun 包名 C节点ps.节点就是第二步的时候我们修改的那两行的括号里第一个参量这是一种映射关系haha和src/helloworld_c.cpp的映射关系。最终结果如下

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询