new-hardware
The new-hardware command scaffolds a complete ros2_control hardware component (System, Actuator, or Sensor interface) with accompanying URDF ros2_control tags, controller configuration, launch files, and unit tests. Use this to generate production-ready boilerplate for integrating physical hardware or simulators into a ROS2 control architecture, including proper pluginlib exports and real-time safe read/write loops.
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/harunkurtdev/ros2-claude-code-template/HEAD/.claude/commands/new-hardware.md -o ~/.claude/commands/new-hardware.mdnew-hardware.md
Scaffold a ros2_control hardware component and its bringup.
Argument handling (`$ARGUMENTS`):
1. `<package>` — existing package under `src/` (required).
2. `<ClassName>` — CamelCase hardware class (required).
3. `<kind>` — `system` (whole robot, `SystemInterface`),
`actuator` (`ActuatorInterface`), or `sensor` (read-only,
`SensorInterface`).
If anything is missing, ask before scaffolding.
Process:
1. Read the skill `ros2_control_hardware_interface` and the rules
`ros2_control_architecture.md` + `ros2_control_demos.md`; pick the
closest example in `~/nav2_ws/src/ros2_control_demos/` to mirror
(`example_1` system, `example_6` actuator, `example_5` sensor).
2. Create the plugin:
* `hardware/include/<package>/<snake_class>.hpp` — class deriving from
`hardware_interface::{System,Actuator,Sensor}Interface`, overriding
`on_init(HardwareComponentInterfaceParams)`, `on_configure`,
`on_activate`, `on_deactivate`, and `read()` / `write()`
(sensors: `read()` only, no command interfaces).
* `hardware/<snake_class>.cpp` — implementation + `PLUGINLIB_EXPORT_CLASS`
with the right `hardware_interface::*Interface` base.
* `<package>.xml` — pluginlib description, `base_class_type` matching.
3. Create the bringup + description:
* `description/ros2_control/<robot>.ros2_control.xacro` — the
`<ros2_control>` tag with `<hardware><plugin>` (== the alias) and the
joints' `<command_interface>` / `<state_interface>`.
* `bringup/config/<robot>_controllers.yaml` — `controller_manager`
with `update_rate` + `joint_state_broadcaster` + one command
controller.
* `bringup/launch/<robot>.launch.py` — robot_state_publisher +
`ros2_control_node` + spawners (broadcaster first).
* `test/test_<snake_class>.cpp` — load the URDF and check the
interfaces export.
4. Wire `CMakeLists.txt` / `package.xml`: deps `hardware_interface`,
`pluginlib`, `rclcpp_lifecycle`;
`pluginlib_export_plugin_description_file(hardware_interface <xml>)`;
install `description/` and `bringup/`.
5. Remind: `read()`/`write()` are the RT hot path — open device handles in
`on_activate`, not in the loop; no alloc/locks/blocking I/O there.
6. `pre-commit run --files <touched files>`.
7. Print: files created and
`ros2 launch <package> <robot>.launch.py` +
`ros2 control list_hardware_interfaces`.
The URDF `<plugin>` string must equal the pluginlib alias and
`PLUGINLIB_EXPORT_CLASS`; a `sensor` component must not export command
interfaces.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).
Use proactively before opening a PR that adds or changes BehaviorTree.CPP nodes or BehaviorTree.ROS2 wrappers (RosActionNode/RosServiceNode/RosTopicPub/SubNode, TreeExecutionServer). Reviews a diff against BT.CPP v4 conventions — node base-class choice, non-blocking ticks, ports/blackboard typing, factory/plugin registration, XML v4, and the ROS 2 wrapper contract. Returns a punch list with file:line anchors, not a rewrite.
Build the colcon workspace (optionally a single package) and report the outcome.
Use when a design decision touches Clean Architecture boundaries in a ROS 2 project — which layer a new behaviour belongs to, whether a port belongs in domain or application, whether a new node should be lifecycle-managed, whether to compose nodes or split packages. Returns an architectural recommendation with trade-offs, not implementation.
Author a new skill under .claude/skills/<name>/SKILL.md with valid frontmatter, following the template conventions, and index it in CLAUDE.md + README.md.
Use when a design decision touches the gz-sim ECS — where new state should live, which system phase should write it, how to avoid coupling, whether to add a component vs. a member variable, whether a new system should be split or merged with an existing one. Returns an architectural recommendation with trade-offs, not implementation.
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).
Configure and build gz-sim from source using either CMake/Ninja directly or a colcon workspace. Trigger when the user asks to build, recompile, configure, or set up the gz-sim binary tree.