IMU可视化化工具:
sudo apt install ros-galactic-imu-tools注意ROS2版本

other

查看ROS2版本:printenv ROS_DISTRO

ROS2-部署VScode:http://t.csdnimg.cn/XhFS2

生命周期管理器


vscode 报错”rclcpp/rclcpp.hpp”:

在vscode中的c_cpp_properties.json中添加对应的ros路径,例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/ros/humble/**" ## 添加在这里

],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}

ROS2 基本

创建工作空间&功能包

1
2
3
4
5
6
7
8
mkdir workspace #名字可以随意 
cd workspace #进入文件夹
mkdir src
colcon build
cd src
ros2 pkg create <package-name> --build-type {cmake,ament_cmake,ament_python} --dependencies <依赖名字>

colcon install

launch文件编写

格式:xml、yaml和python

Python写法

基础用法(启动节点):

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
# 导入库
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
"""launch内容描述函数,由ros2 launch 扫描调用"""

example-node = Node(
package='package-name', #节点所在的功能包
namespace='package-namespace', #命名空间。如果存在同名节点,这一选项会有用
executable='execute-name/script-name.py', #表示要运行的可执行文件名或脚本名字.py
parameters=[{'parameter-name': parameter-value}], #参数
arguments=['-xxx', xxx, '-xxx', xxx ], #启动参数
output='screen', #用于将话题信息打印到屏幕
name='node-name' #表示启动后的节点名,可以没有
remappings=[ #重映射
('/xxx/xxx-new', '/xxx/xxx-old'),
]
)

# 创建LaunchDescription对象launch_description,用于描述launch文件
launch_description = LaunchDescription(
[parameters_basic1, parameters_basic2])
# 返回让ROS2根据launch描述执行节点
return launch_description

使用ament_cmake ,需要添加cmake命令

1
2
install(DIRECTORY launch
DESTINATION share/${PROJECT_NAME})

详细用法:

  1. 调用shell命令

  2. 获取路径

  3. 连接路径

  4. 改变参数

  5. 启动另一个launch文件

  6. 在另一个launch文件中使用参数

参考博客:
https://www.robotsfan.com/posts/7a5950c4.html

ROS2 相关写法

问题

(1)ROS2 Vscode编译找不到自定义的头文件

解决:

  1. 写入相对路径:#include "..//include/功能包名/**.hpp"

  2. 在CMakeLists.txt中添加路径:

    1
    2
    3
    INCLUDE_DIRECTORIES(
    ${CMAKE_CURRENT_SOURCE_DIR}/include/功能包名/
    )