بنقرة واحدة
ros2-service-action
ROS2 Service and Action implementation with Clean Architecture (Python & C++)
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
ROS2 Service and Action implementation with Clean Architecture (Python & C++)
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Author a new asset for this .claude/ template — a rule, skill, slash command, or sub-agent — following the project's conventions and wiring it into the CLAUDE.md / README.md indexes. Trigger when the user wants to add or extend a command, skill, agent, or rule (make the template itself extensible).
Bootstrap a complete ROS 2 colcon workspace from scratch — directory layout, .gitignore, top-level README, this .claude/ config, an interfaces package and a first Clean Architecture package, and a bringup package. Trigger when the user asks to create a new workspace / start a new ROS 2 project from zero.
Scaffold a Behavior Tree leaf node — plain BehaviorTree.CPP (SyncActionNode / StatefulActionNode / ConditionNode) or a BehaviorTree.ROS2 wrapper (RosActionNode / RosServiceNode / RosTopicPubNode / RosTopicSubNode) — with ports, factory/plugin registration, and XML v4 usage. Trigger when the user asks to write a behavior-tree node (not Nav 2-specific).
Scaffold a ros2_control hardware component (SystemInterface / ActuatorInterface / SensorInterface) and its bringup — the plugin (on_init/on_configure/on_activate, RT-safe read()/write()), URDF <ros2_control> wiring, controllers.yaml + launch, pluginlib export. Trigger when the user asks to integrate hardware or bring up a robot under ros2_control.
Scaffold or extend a ros2_control controller or broadcaster (ControllerInterface / ChainableControllerInterface) — base-class choice, command/state interface configuration, lifecycle, real-time-safe update(), generate_parameter_library, pluginlib export, tests. Trigger when the user asks to write a ros2_control controller or broadcaster.
Bridge a VDA 5050 v3.0.0 fleet-control interface (MQTT/JSON) onto Nav 2 under Clean Architecture — domain entities, MQTT/Nav 2 adapters behind ports, order→NavigateThroughPoses mapping, state aggregation, action handlers. Trigger when the user asks to build or extend a VDA 5050 connector / fleet bridge.
| name | ROS2 Service & Action |
| description | ROS2 Service and Action implementation with Clean Architecture (Python & C++) |
This skill provides a guide for implementing ROS2 Services and Actions adhering to Clean Architecture principles.
# srv/SetRobotMode.srv
# Request
string mode # "idle", "active", "emergency"
bool force_change # Force mode change
---
# Response
bool success
string message
string previous_mode
See previous Python example.
// infrastructure/ros2/services/robot_mode_service.hpp
#pragma once
#include <rclcpp/rclcpp.hpp>
#include "robot_interfaces/srv/set_robot_mode.hpp"
#include "domain/use_cases/set_robot_mode.hpp"
namespace infrastructure::ros2::services {
class RobotModeServiceNode : public rclcpp::Node {
public:
explicit RobotModeServiceNode(
std::shared_ptr<domain::use_cases::SetRobotModeUseCase> use_case,
const rclcpp::NodeOptions& options = rclcpp::NodeOptions());
private:
void handle_set_mode(
const std::shared_ptr<robot_interfaces::srv::SetRobotMode::Request> request,
std::shared_ptr<robot_interfaces::srv::SetRobotMode::Response> response);
std::shared_ptr<domain::use_cases::SetRobotModeUseCase> use_case_;
rclcpp::Service<robot_interfaces::srv::SetRobotMode>::SharedPtr service_;
};
} // namespace
// infrastructure/ros2/services/robot_mode_service.cpp
#include "infrastructure/ros2/services/robot_mode_service.hpp"
namespace infrastructure::ros2::services {
RobotModeServiceNode::RobotModeServiceNode(
std::shared_ptr<domain::use_cases::SetRobotModeUseCase> use_case,
const rclcpp::NodeOptions& options)
: Node("robot_mode_service", options), use_case_(use_case) {
using namespace std::placeholders;
service_ = this->create_service<robot_interfaces::srv::SetRobotMode>(
"/robot/set_mode",
std::bind(&RobotModeServiceNode::handle_set_mode, this, _1, _2)
);
}
void RobotModeServiceNode::handle_set_mode(
const std::shared_ptr<robot_interfaces::srv::SetRobotMode::Request> request,
std::shared_ptr<robot_interfaces::srv::SetRobotMode::Response> response) {
// Conversion from message to domain object would go here
// ...
// Execute use case
// auto result = use_case_->execute(...);
// Map result to response
// response->success = result.success;
}
} // namespace
// infrastructure/ros2/clients/robot_mode_client.hpp
#pragma once
#include <rclcpp/rclcpp.hpp>
#include "robot_interfaces/srv/set_robot_mode.hpp"
namespace infrastructure::ros2::clients {
class RobotModeClient {
public:
explicit RobotModeClient(rclcpp::Node::SharedPtr node);
std::future<std::shared_ptr<robot_interfaces::srv::SetRobotMode::Response>>
set_mode_async(const std::string& mode, bool force = false);
private:
rclcpp::Node::SharedPtr node_;
rclcpp::Client<robot_interfaces::srv::SetRobotMode>::SharedPtr client_;
};
} // namespace
# action/NavigateToPoint.action
# Goal
geometry_msgs/Point target_point
float32 max_velocity
bool avoid_obstacles
---
# Result
bool success
string message
float32 total_distance
float32 total_time
---
# Feedback
geometry_msgs/Point current_position
float32 distance_remaining
float32 estimated_time
string status
// infrastructure/ros2/actions/navigation_action_server.hpp
#pragma once
#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/rclcpp_action.hpp>
#include "robot_interfaces/action/navigate_to_point.hpp"
#include "domain/use_cases/navigate_to_point.hpp"
namespace infrastructure::ros2::actions {
class NavigationActionServer : public rclcpp::Node {
public:
using NavigateToPoint = robot_interfaces::action::NavigateToPoint;
using GoalHandle = rclcpp_action::ServerGoalHandle<NavigateToPoint>;
explicit NavigationActionServer(
std::shared_ptr<domain::use_cases::NavigateToPointUseCase> use_case,
const rclcpp::NodeOptions& options = rclcpp::NodeOptions());
private:
rclcpp_action::GoalResponse handle_goal(
const rclcpp_action::GoalUUID& uuid,
std::shared_ptr<const NavigateToPoint::Goal> goal);
rclcpp_action::CancelResponse handle_cancel(
const std::shared_ptr<GoalHandle> goal_handle);
void handle_accepted(const std::shared_ptr<GoalHandle> goal_handle);
void execute(const std::shared_ptr<GoalHandle> goal_handle);
std::shared_ptr<domain::use_cases::NavigateToPointUseCase> use_case_;
rclcpp_action::Server<NavigateToPoint>::SharedPtr action_server_;
};
} // namespace
// infrastructure/ros2/clients/navigation_client.hpp
#pragma once
#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/rclcpp_action.hpp>
#include "robot_interfaces/action/navigate_to_point.hpp"
namespace infrastructure::ros2::clients {
class NavigationClient {
public:
using NavigateToPoint = robot_interfaces::action::NavigateToPoint;
using GoalHandle = rclcpp_action::ClientGoalHandle<NavigateToPoint>;
explicit NavigationClient(rclcpp::Node::SharedPtr node);
std::shared_future<std::shared_ptr<GoalHandle>> navigate_to(
double x, double y, double z,
std::function<void(const NavigateToPoint::Feedback&)> feedback_cb);
private:
rclcpp::Node::SharedPtr node_;
rclcpp_action::Client<NavigateToPoint>::SharedPtr client_;
};
} // namespace