参考文献:ROS2 Foundation - An introduction to core concepts
ROS2极简总结-核心概念(一)_zhangrelay的专栏-CSDN博客
#request
int8 a
int8 b
---
#response
int8 sum
7 行动
使用场景如下:
行动是采用服务和主题的组合实现
行动接口有
目标:要实现什么行动以及如何实现。
反馈:完成行动的进展
抢占:抢占正在执行的行动
结果:行动的结果
行动客户端与服务器端
# Define a goal of washing all dishes
bool heavy_duty # Spend extra time cleaning
---
# Define the result that will be published after the action execution ends.
uint32 total_dishes_cleaned
---
# Define a feedback message that will be published during action execution.
float32 percent_complete
uint32 number_dishes_cleaned
Actions 行动 | Services 服务 |
---|---|
Intended for longer running tasks 适用于运行时间较长的任务 | For tasks that terminated quickly 适用于快速终止的任务 |
Preemptable 可抢占 | Not preemptable 不可抢占 |
Consists of goal, result and feedback 由目标、结果和反馈组成 | Consists of request and response 由请求和响应组成 |
Provides steady feedback 提供稳定的反馈 | Provides a single response 提供单一响应 |
8 参数
同一个算法如何适用不同类型但有原理类似的机器人呢???
调整参数即可,当然如果可以专用算法可以发挥最大效能,但是通用算法验证只需参数的匹配。
常用2种方式
def __init__(self):
super().__init__('test_params_rclpy')
self.declare_parameter('my_str')
self.declare_parameter('my_int')
param_str = self.get_parameter('my_str')
param_int = self.get_parameter('my_int')
self.get_logger().info("str: %s, int: %s" % (str(param_str.value), str(param_int.value)))
在命令行中设置 ros2 参数:
ros2 run ros2_tutorials test_params_rclpy --ros-args -p my_str:="Hello world" -p my_int:=5
用于 ROS2 参数的 YAML
功能包结构
将 YAML 配置加载到节点
def __init__(self):
super().__init__('your_amazing_node')
self.declare_parameters(
namespace='',
parameters=[
('bool_value', None),
('float_number', None),
('str_text', None)
])
命令行模式:
ros2 run pkg_name node_name --ros-args --params-file .~/locate_pkg/config/params.yaml
启动文件模式:
def generate_launch_description():
ld = LaunchDescription()
config = os.path.join(
get_package_share_directory('ros2_tutorials'),
'config',
'params.yaml'
)
node=Node(
package = 'ros2_tutorials',
name = 'Node_A',
executable = 'test_yaml_params',
parameters = [config]
)
ld.add_action(node)
return ld
Python功能包模式,配置”setup.py“
...
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share', package_name, 'launch'), glob('launch/.launch.py')),
(os.path.join('share', package_name, 'config'), glob('config/.yaml'))
],
...
更多细节参考ROS2参数官方文档。
为啥需要启动文件(Launch)
使用场景,启动文件用于:
启动文件位置:
使用 colcon build 然后 source workspace
就可以在CLI(命令行接口)中使用:
ros2 launch package_name launch_file_name
-End-