ROS安装
使用ubuntu20.04,对应ROS1 neotic,使用清华源下载
ubuntu下载:https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/20.04/
ubuntu清华源配置:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
ROS仓库配置:https://mirrors.tuna.tsinghua.edu.cn/help/ros/
总体借鉴这篇:https://blog.csdn.net/jy15246781299/article/details/122256113
安装指令:sudo apt-get install ros-noetic-desktop-full
,·sudo apt-get install python3-rosdep
安装依赖:sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
ROS命令行工具使用
一、常用命令
- roscore :启动ros
- rosrun :
rosrun [package_name] [node_name]
调用节点 参数为功能包名和节点名称 - rosnode :
rosnode list
列出当前运行的节点 - rqt_graph :可视化当前运行的节点
- rostopic :进行话题的操作
rostopic pub
:发布话题消息rostopic type
:查看消息类型
- rosservice :进行服务的操作
rosservice call
:发布服务请求
- rosparam
- rosmsg :获取消息的详细信息
- rossrv
二、示例:海龟仿真
-
启动ROS Master:
$roscore
-
启动海龟仿真器:
$rosrun turtlesim turtlesim_node
-
启动海龟控制节点:
$rosrun turtlesim turtle_teleop_key
注意:这三个命令分别在三个终端执行。 -
运行
三、发布话题消息
发布消息 让海龟一直移动。
- 先查看消息类型
~$ rostopic type /turtle1/cmd_vel
geometry_msgs/Twist
~$ rosmsg show geometry_msgs/Twist
geometry_msgs/Vector3 linear
float64 x
float64 y
float64 z
geometry_msgs/Vector3 angular
float64 x
float64 y
float64 z
- 编写参数
~$ rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "
linear:
x: 1.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0
"
注意:参数对齐
- 运行
四、发布服务请求
发布服务请求,添加新的海龟。
- 查看请求信息
~$ rosservice info /spawn
Node: /turtlesim
URI: rosrpc://ros2go:39063
Type: turtlesim/Spawn
Args: x y theta name
- 发布请求
~$ rosservice call /spawn "
x: 5.0
y: 5.0
theta: 0.0
name: 'turtle2'
"
name: "turtle2"
- 运行
五、话题和服务的区别
- 话题 (Topic)
- 节点间的异步通信机制
- 使用 发布/订阅 模型
- 话题数据:消息(Message) 文件格式
.msg
- 服务 (Service)
- 节点间的同步通信机制
- 使用 客户端/服务器(C/S) 模型
- 数据:文件格式
.srv