0%

运行一个示例

安装依赖

1
sudo apt-get install ros-galactic-turtle-tf2-py ros-galactic-tf2-tools ros-galactic-tf-transformations
1
pip3 install transforms3d

运行示例

在不同的命令窗口中运行下面的命令

启动小乌龟窗口

1
ros2 launch turtle_tf2_py turtle_tf2_demo.launch.py

启动键盘控制节点

1
ros2 run turtlesim turtle_teleop_key

观察坐标转换的结果

1
ros2 run tf2_ros tf2_echo turtle2 turtle1

示例分析

本示例中启动了两只小乌龟Turtle1Turtle2TF发布器会将Turtle1相对于world坐标系的位置关系和Turtle2相对于world坐标系的位置关系发布出来。为了实现Turtle2跟随Turtle1的效果,程序中获取了Turtle1相对于Turtle2的位置关系并且将其折算成速度控制量。

阅读全文 »

launch 文件

launch文件可以同时配置和启动多个ros节点。ROS2中的launch文件可以用Pythonxmlyaml来写。

ROS2中的Python launch文件更为灵活,功能也更加强大。可以用它执行一些其他的任务(比如新建目录,配置环境变量)。所以官方推荐的是使用python来写。而launch文件一般会放在功能包中的launch文件夹下面。如果想感受一下各种方式写launch文件的效果,可以点开下面的链接体会一下。

https://docs.ros.org/en/galactic/How-To-Guides/Launch-file-different-formats.html

launch文件一般通过下面的命令启动:

1
ros2 launch <package_name> <launch_file_name>

值的注意的是,当package编译时加了--symlink-install选项,在包内修改了launch文件,不用编译也是生效的。

阅读全文 »

ROS2最新的5年长期支持版ROS 2 Humble Hawksbill 发布了。它是第一个运行在Ubuntu 22.04 (Jammy Jellyfish)上的版本。

介绍文章:

https://discourse.ros.org/t/ros-2-humble-hawksbill-released/25729

ROS2 Humble Hawksbill 版本新特性:

https://docs.ros.org/en/humble/Releases/Release-Humble-Hawksbill.html#new-features-in-this-ros-2-release

ROS2 Humble Hawksbill官方手册:

https://docs.ros.org/en/humble/index.html

阅读全文 »

使用ros2 lifecycle --h命令可以看到lifecycle相关的命令有哪些。

获取LifecycleNode节点的状态

1
ros2 lifecycle get /lifecycle_node_demo_node

其中/lifecycle_node_demo_node为节点名称

阅读全文 »

map的数据类型

map话题的类型是nav_msgs::msg::OccupancyGrid。使用下面的命令可以查询该类型的数据结构。

1
ros2 interface show nav_msgs/msg/OccupancyGrid

nav_msgs::msg::OccupancyGrid的数据结构:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This represents a 2-D grid map
std_msgs/Header header
builtin_interfaces/Time stamp
int32 sec
uint32 nanosec
string frame_id

# MetaData for the map
MapMetaData info
builtin_interfaces/Time map_load_time
int32 sec
uint32 nanosec
float32 resolution
uint32 width
uint32 height
geometry_msgs/Pose origin
Point position
float64 x
float64 y
float64 z
Quaternion orientation
float64 x 0
float64 y 0
float64 z 0
float64 w 1

# The map data, in row-major order, starting with (0,0).
# Cell (1, 0) will be listed second, representing the next cell in the x direction.
# Cell (0, 1) will be at the index equal to info.width, followed by (1, 1).
# The values inside are application dependent, but frequently,
# 0 represents unoccupied, 1 represents definitely occupied, and
# -1 represents unknown.
int8[] data

其中data数据成员用于存储地图中的每个栅格值。nav_msgs::msg::OccupancyGrid存储的栅格值范围在[0~100]。0表示栅格未被占用,100表示栅格被占用了,而0到100之间表示被占用的程度。-1表示未知区域。

info成员变量中主要存储地图文件的一些参数。比如:地图大小,分辨率,原点等信息。

阅读全文 »

Costmap_2d 的插件

Costmap_2d 的插件都是继承于CostmapLayer。具体的关系如下图所示:
img

StaticLayer

StaticLayer内主要是通过接收map_server发布的地图话题来加载静态地图的。所以StaticLayer内是可以在线更改静态地图的。

ObstacleLayer

ObservationBuffer

ObservationBuffer 是一个障碍物观察数据的buffer。观测到的障碍物数据都将转成sensor_msgs::msg::PointCloud2格式,然后存储到ObservationBuffer 中。

ObservationBuffer 里存储的历史障碍物数据可以根据想保持的时间来清空。期望保持的时间主要由变量observation_keep_time_来决定。如果设置成rclcpp::Duration(0.0s)则表示每次都只存储最新的,历史障碍物数据都会被清掉。

看到这里,有同学可能会想,既然可以以时间为依据来清除障碍物,是不是也可以以其他条件来清除障碍物呢?答案肯定是可以的。这个就需要根据应用场景来选择了。比如:使用机器人的移动距离来作为判断条件。当观测数据时的机器人位置与现在机器人的位置超过多远就把该数据清掉。

阅读全文 »

有顺序的的启动节点,暂停节点,关闭节点是ROS1的一个痛点。因为在ROS1中节点启动是无序的。ROS1系统设计时并没有考虑节点启动时可能存在的互相依赖。

但在实际生产使用环境中,某些节点能正常工作是需要其他一些节点已经启动了的。

比如:需要定位功能能正常运行,前提是map_server节点已经正常加载地图文件并且已经把地图话题发布出来。

又或者你想从建图功能切到导航功能。在ROS1中,需要先将建图功能的程序杀干净。然后再启动导航程序。在ROS2中,各个节点的状态是可管理的。

在这个场景里,大可让建图程序休眠,而不用杀掉。切换功能时只需要激活相应功能的节点即可。

阅读全文 »

废话不多说,我们直接开始。

搭建测试环境

为了避免花太多时间折腾环境问题。这里使用Docker来跑测试的示例。

安装Docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

# step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

# Step 4: 更新并安装 Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce

# Step 5: 查看docker是否安装成功
docker version
阅读全文 »

查看Action 信息的常用命令
Action主要用于长时间运行的任务。它们由三部分组成:目标、反馈和结果。

查看action列表

1
ros2 action list

查看action列表和类型

1
ros2 action list -t

查看action信息

1
ros2 action info <action_name>

显示action

1
ros2 interface show <action_name>

action send goal

1
ros2 action send_goal <action_name> <action_type> <values>
阅读全文 »

下面的操作是基于galactic

代码下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#安装git和编译工具
sudo apt-get install git python3-vcstool build-essential python3-colcon-common-extensions
mkdir -p turtlebot3_ws/src
cd turtlebot3_ws/

#下载turtlebot3代码
git clone https://ghproxy.com/https://github.com/ROBOTIS-GIT/turtlebot3.git src/turtlebot3 -b galactic-devel
git clone https://ghproxy.com/https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git src/turtlebot3_msgs -b galactic-devel
git clone https://ghproxy.com/https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git src/turtlebot3_simulations -b galactic-devel

#下载navigation2
git clone https://ghproxy.com/https://github.com/ros-planning/navigation2.git src/navigation2 -b galactic
git clone https://ghproxy.com/https://github.com/ros-planning/navigation2_tutorials.git src/navigation2_tutorials -b master

#下载teb_local_planner
git clone https://ghproxy.com/https://github.com/rst-tu-dortmund/costmap_converter.git src/costmap_converter -b ros2
git clone https://ghproxy.com/https://github.com/rst-tu-dortmund/teb_local_planner.git src/teb_local_planner -b ros2-master

注意:链接中的https://ghproxy.com/ 为使用代理下载github代码。

阅读全文 »