用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/harunkurtdev/ros2-claude-code-template --skill ros2-transforms-tf2命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | ROS2 Transforms (TF2) |
| description | ROS2 TF2 and Transform management with Clean Architecture (Python & C++) |
This skill demonstrates how to use the ROS2 TF2 (Transform Library) while adhering to Clean Architecture principles. The Domain layer should be protected from direct TF2 dependencies by using Repository or Service patterns.
The domain layer should not depend on TF2 or geometry_msgs.
# domain/entities/pose.py
from dataclasses import dataclass
@dataclass
class Pose:
position: tuple # (x, y, z)
orientation: tuple # (x, y, z, w)
frame_id: str
timestamp: float
// domain/entities/pose.hpp
#pragma once
#include <string>
namespace domain::entities {
struct Point3D { double x, y, z; };
struct Quaternion { double x, y, z, w; };
struct Pose {
Point3D position;
Quaternion orientation;
std::string frame_id;
double timestamp;
};
} // namespace
TF2 implementation resides here.
See previous Python example.
// infrastructure/ros2/services/tf_service.hpp
#pragma once
#include <rclcpp/rclcpp.hpp>
#include <tf2_ros/buffer.h>
#include <tf2_ros/transform_listener.h>
#include <geometry_msgs/msg/transform_stamped.hpp>
#include "domain/interfaces/transform_service.hpp"
namespace infrastructure::ros2::services {
class TFService : public domain::interfaces::ITransformService {
public:
explicit TFService(rclcpp::Node::SharedPtr node);
std::optional<domain::entities::Pose> get_transform(
const std::string& target_frame,
const std::string& source_frame) override;
private:
rclcpp::Node::SharedPtr node_;
std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
std::shared_ptr<tf2_ros::TransformListener> tf_listener_;
};
} // namespace
// infrastructure/ros2/services/tf_service.cpp
#include "infrastructure/ros2/services/tf_service.hpp"
namespace infrastructure::ros2::services {
TFService::TFService(rclcpp::Node::SharedPtr node) : node_(node) {
tf_buffer_ = std::make_shared<tf2_ros::Buffer>(node_->get_clock());
tf_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf_buffer_);
}
{
{
geometry_msgs::msg::TransformStamped t = tf_buffer_->(
target_frame, source_frame, tf2::TimePointZero);
domain::entities::Pose{
{t.transform.translation.x, t.transform.translation.y, t.transform.translation.z},
{t.transform.rotation.x, t.transform.rotation.y, t.transform.rotation.z, t.transform.rotation.w},
t.header.frame_id,
rclcpp::(t.header.stamp).()
};
} ( tf2::TransformException & ex) {
(node_->(), ,
source_frame.(), target_frame.(), ex.());
std::;
}
}
}
// infrastructure/ros2/helpers/tf_publisher.hpp
#include <tf2_ros/static_transform_broadcaster.h>
class TFPublisher {
public:
TFPublisher(rclcpp::Node::SharedPtr node) : node_(node) {
static_broadcaster_ = std::make_shared<tf2_ros::StaticTransformBroadcaster>(node);
}
void publish_static(const std::string& parent, const std::string& child,
const std::array<double, 3>& trans,
const std::array<double, 4>& rot) {
geometry_msgs::msg::TransformStamped t;
t.header.stamp = node_->get_clock()->now();
t.header.frame_id = parent;
t.child_frame_id = child;
t.transform.translation.x = trans[0];
// ...
static_broadcaster_->sendTransform(t);
}
private:
rclcpp::Node::SharedPtr node_;
std::shared_ptr<tf2_ros::StaticTransformBroadcaster> static_broadcaster_;
};
tf2_ros.tf2::TransformException.Time(0)) for data synchronization when possible.