ROS机器人开发实践(1)——ROS基础

小乌龟Demo

我们的学习就从一个生动有趣的Demo开始启程吧。
运行ROS的第一步是要在终端输入roscore,这是使用ROS的前提条件。
我们要分别打开三个窗口,逐一运行下面三行指令。

$ roscore
$ rosrun turtlesim turtlesim_node
$ rosrun turtlesim turtle_teleop_key

在这里插入图片描述(看着第二个窗口里弹跳出来的警告,我只想说,ROS里的小乌龟很有可能是个双子座话痨,他太能说了)

发布者(Publisher)与订阅者(Subscriber)

发布者(Publisher)与订阅者(Subscriber)是ROS里面最基础的通信方式。
我们打开一个新的终端。输入如下命令

$ rqt_graph

在这里插入图片描述通过上面这一幅图,我们可以知道我们创建了两个节点,根据箭头的方向,/teleop_turtle为发布者用于发布键盘的指令,/turtlesim 为订阅者用于接受指令,箭头上方的内容是话题。

创建工作空间以及编译

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace
Creating symlink "/home/warmtree/catkin_ws/src/CMakeLists.txt" pointing to "/opt/ros/melodic/share/catkin/cmake/toplevel.cmake"
$ cd ~/catkin_ws/
$ catkin_make

编译之后,我们发现devel里面自动生成脚本文件。
在这里插入图片描述之后我们进行环境变量设置以及查看是否设置成功。

$ source devel/setup.bash
$ echo $ROS_PACKAGE_PATH
/home/warmtree/catkin_ws/src:/opt/ros/melodic/share

结果能打印出来包含当前工作空间的路径证明环境变量设置成功。
在这里面,我们遇到了一个Linux系统常见的一个命令echo。TA的基本用法就是命令后面加上输出文本。

(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ echo 1234
1234
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ echo test message
test message
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ echo "www.ec-nantes.fr"
www.ec-nantes.fr
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ echo -n "www.ec-nantes.fr"
www.ec-nantes.fr(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ 

更多输出彩色字体的用法详见链接echo用法

创建功能包

(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~/catkin_ws$ cd src
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~/catkin_ws/src$ catkin_create_pkg learning_communication std_msgs rospy roscpp
Created file learning_communication/CMakeLists.txt
Created file learning_communication/package.xml
Created folder learning_communication/include/learning_communication
Created folder learning_communication/src
Successfully created files in /home/warmtree/catkin_ws/src/learning_communication. Please adjust the values in package.xml.
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~/catkin_ws/src$ cd ~/catkin_make
bash: cd: /home/warmtree/catkin_make: 没有那个文件或目录
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~/catkin_ws/src$ cd ~/catkin_ws
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~/catkin_ws$ catkin_make
Base path: /home/warmtree/catkin_ws
Source space: /home/warmtree/catkin_ws/src
Build space: /home/warmtree/catkin_ws/build
Devel space: /home/warmtree/catkin_ws/devel
Install space: /home/warmtree/catkin_ws/install
####
#### Running command: "cmake /home/warmtree/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/warmtree/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/warmtree/catkin_ws/install -G Unix Makefiles" in "/home/warmtree/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/warmtree/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/warmtree/catkin_ws/devel;/opt/ros/melodic
-- This workspace overlays: /home/warmtree/catkin_ws/devel;/opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.15", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/warmtree/catkin_ws/build/test_results
-- 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/python2 (found version "2.7.15") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.19
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - learning_communication
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'learning_communication'
-- ==> add_subdirectory(learning_communication)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/warmtree/catkin_ws/build
####
#### Running command: "make -j4 -l4" in "/home/warmtree/catkin_ws/build"
####
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~/catkin_ws$ source devel/setup.bash

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肥鼠路易

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值