ros2-action-communication
ROS2 Action 通讯技能 - ActionServer/ActionClient 实现、目标执行、反馈获取、任务取消
от MIUAV★ 30 звёзд на GitHub
Установить ros2-action-communication в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
ROS2 Action Communication Skill
ROS2 Action 异步任务执行完整指南
何时使用
当需要以下帮助时使用此技能:
- 实现长时间运行的任务
- 需要进度反馈的操作
- 任务取消和抢占
- 异步目标执行
- 任务状态跟踪
快速参考
基础架构
Goal (目标) ──> ActionServer <─── Execution
^ |
│ v
Feedback <────── Progress
^
│
Result <──────── Completion
应用场景
- 导航 (Nav2)
- 机械臂运动控制
- 无人机起飞/降落
- 摄像头标定
- 数据采集任务
C++ ActionServer
基本服务端
#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/rclcpp_action.hpp>
#include <example_interfaces/action/fibonacci.hpp>
class FibonacciServer : public rclcpp::Node {
public:
using Fibonacci = example_interfaces::action::Fibonacci;
using GoalHandle = rclcpp_action::ServerGoalHandle<Fibonacci>;
FibonacciServer() : Node("fibonacci_server") {
// 创建 ActionServer
action_server_ = rclcpp_action::create_server<Fibonacci>(
this,
"fibonacci",
std::bind(&FibonacciServer::handle_goal, this, std::placeholders::_1, std::placeholders::_2),
std::bind(&FibonacciServer::handle_cancel, this, std::placeholders::_1),
std::bind(&FibonacciServer::handle_accepted, this, std::placeholders::_1));
RCLCPP_INFO(this->get_logger(), "Action server ready");
}
private:
rclcpp_action::Server<Fibonacci>::SharedPtr action_server_;
// 处理新目标
rclcpp_action::GoalResponse handle_goal(
const rclcpp_action::GoalUUID& uuid,
std::shared_ptr<const Fibonacci::Goal> goal) {
RCLCPP_INFO(this->get_logger(), "Received goal with order: %d", goal->order);
return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
}
// 处理取消请求
rclcpp_action::CancelResponse handle_cancel(
const std::shared_ptr<GoalHandle> goal_handle) {
RCLCPP_INFO(this->get_logger(), "Received cancel request");
return rclcpp_action::CancelResponse::ACCEPT;
}
// 处理接受的目标
void handle_accepted(const std::shared_ptr<GoalHandle> goal_handle) {
// 在新线程执行
std::thread([this, goal_handle]() { execute(goal_handle); }).detach();
}
// 执行目标
void execute(const std::shared_ptr<GoalHandle> goal_handle) {
RCLCPP_INFO(this->get_logger(), "Executing goal");
auto feedback = std::make_shared<Fibonacci::Feedback>();
auto& sequence = feedback->partial_sequence;
sequence.push_back(0);
sequence.push_back(1);
auto result = std::make_shared<Fibonacci::Result>();
for (int i = 1; i < goal_handle->get_goal()->order; ++i) {
// 检查取消
if (goal_handle->is_canceling()) {
result->sequence = sequence;
goal_handle->canceled(result);
RCLCPP_INFO(this->get_logger(), "Goal canceled");
return;
}
// 更新序列
sequence.push_back(sequence[i] + sequence[i-1]);
// 发布反馈
goal_handle->publish_feedback(feedback);
RCLCPP_INFO(this->get_logger(), "Published feedback");
// 模拟耗时操作
std::this_thread::sleep_for(1s);
}
// 完成
result->sequence = sequence;
goal_handle->succeed(result);
RCLCPP_INFO(this->get_logger(), "Goal succeeded");
}
};
C++ ActionClient
基本客户端
class FibonacciClient : public rclcpp::Node {
public:
using Fibonacci = example_interfaces::action::Fibonacci;
using GoalHandle = rclcpp_action::ClientGoalHandle<Fibonacci>;
FibonacciClient() : Node("fibonacci_client") {
// 创建 ActionClient
action_client_ = rclcpp_action::create_client<Fibonacci>(
this,
"fibonacci");
// 等待服务可用
if (!action_client_->wait_for_action_server(10s)) {
RCLCPP_ERROR(this->get_logger(), "Action server not available");
return;
}
send_goal();
}
void send_goal() {
auto goal = Fibonacci::Goal();
goal.order = 10;
// 发送目标
auto send_goal_options =
rclcpp_action::Client<Fibonacci>::SendGoalOptions();
// 目标响应回调
send_goal_options.goal_response_callback = [this](
std::shared_ptr<GoalHandle> handle) {
if (!handle) {
RCLCPP_ERROR(this->get_logger(), "Goal was rejected");
} else {
RCLCPP_INFO(this->get_logger(), "Goal accepted");
goal_handle_ = handle;
}
};
// 反馈回调
send_goal_options.feedback_callback = [this](
std::shared_ptr<GoalHandle> handle,
const std::shared_ptr<Fibonacci::Feedback> feedback) {
RCLCPP_INFO(this->get_logger(), "Feedback: %ld",
feedback->partial_sequence.size());
};
// 结果回调
send_goal_options.result_callback = [this](
const rclcpp_action::ClientGoalHandle<Fibonacci>::WrappedRe
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл ros2-action-communication?
ROS2 Action 通讯技能 - ActionServer/ActionClient 实现、目标执行、反馈获取、任务取消
Как установить скилл ros2-action-communication?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ros2-action-communication запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…