1 初始化

# 初始化节点
rclpy.init()

# 启动节点
rclpy.spin()

# 启动一个节点
rclpy.spin_once()

# 启动节点直至工作完成
rclpy.spin_until_future_complete()

# 获取执行程序
rclpy.get_global_executor()

# 关闭节点
rclpy.shutdown()

2 Node

# 导包
from rclpy.node import Node

# 添加等待
add_waitable

# 统计节点发布者数量
count_publishers(topic_name)

# 统计节点订阅者数量
count_subscribers(topic_name)

# 销毁节点
destroy_node()

3 Topic

3.1 Publisher

# 创建发布者
Node.create_publisher(
    msg_type,                      # 数据类型
    topic,                             # 发布名
    qos_profile,                    #
)

# 设置为活动状态
assert_liveliness()

# 销毁
destroy()

# 获取该发布者的订阅者数量
get_subscription_count()

# 发布数据
publish(msg)

3.2 Subscription

# 创建订阅者
Node.create_subscription(
    msg_type,                        # 数据类型
    topic,                            # 订阅名
    callback(),                    # 回调函数
    qos_profile
)

4 Services

4.1 Client

# 创建客户端
Node.create_client(
    srv_type,                    #
    srv_name,                    #
    qos_profile                #
)

# 发出请求
call(request)

# 异步请求
call_async(request)

# 删除请求
remove_pending_request()

# 检查服务是否准备就绪
service_is_ready()

# 等待服务启动
wait_for_service()

4.2 Service

# 创建服务端
Node.create-service(
    srv_type,
    srv_name,
    qos_profile
)
send_response()

5 Actions

5.1 Action Client

# 导包
from rclpy.action import ActionClient

ActionClient(
    action_type,
    action_name,
)

# 添加等待
add_to_wait_set(wait_set)

# 销毁
destroy()

# 实体编号
get_num_entities()

# 是否就绪
is_ready(wait_set)

# 发送
send_goal(goal)

# 异步发送
send_goal_async()

# 检查服务端是否准备就绪
server_is_ready()

# 等待服务端就绪
wait_for_server()

5.2 Action Server

ActionServer(
    action_type,
    action_name,
    callback,
)
# 添加等待
add_to_wait_set(wait_set)

# 销毁
destroy()

# 实体编号
get_num_entities()

# 是否就绪
is_ready(wait_set)

# 发送
send_goal(goal)

# 异步发送
send_goal_async()

# 检查服务端是否准备就绪
server_is_ready()

# 等待服务端就绪
wait_for_server()

6 Timer

# 导包
from rclpy.timer import Rate,Timer

Rate(timer,*,context)

Timer(
    callback,
    callback_group,
    timer_period_ns,
    clock,
    *,
    context=None
)
cancel()
destroy()
is_canceled()
is_ready()
reset()
time_since_last_call()
time_until_next_call()

7 Context

init()

ok()

# 添加要在关机时调用的回调
on_shutdown()

shutdown()

try_shutdown()

results matching ""

    No results matching ""