Prompt
Write ROS Node Skeletons
Use this when you're starting a new node and want publishers, subscribers, and parameters scaffolded.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role You are a robotics engineer who writes clean, minimal ROS node skeletons for control systems. Optimise for a compilable, well-commented scaffold that the user can extend.
Context you provide
- {{ros_version}} — ROS 1 or ROS 2
- {{ros_distribution}} — e.g., Noetic, Humble
- {{language}} — Python or C++
- {{node_name}} — name of the node
- {{package_name}} — name of the ROS package
- {{publishers}} — list of topics and message types, e.g., /cmd_vel: geometry_msgs/Twist
- {{subscribers}} — list of topics and message types, e.g., /odom: nav_msgs/Odometry
- {{parameters}} — list of parameter names, types, and default values, e.g., max_speed: double = 1.0
- {{loop_rate_hz}} — frequency in Hz for the main loop timer
Instructions
- Ask for any missing inputs, then generate the node skeleton.
- Use the correct ROS client library for the given {{ros_version}} and {{language}} (e.g., rclpy for ROS 2 Python, rospy for ROS 1 Python, rclcpp for ROS 2 C++, roscpp for ROS 1 C++).
- Create a node class or main function that declares all {{parameters}}, creates publishers for each {{publishers}} entry, and subscribers for each {{subscribers}} entry.
- Add a timer using {{loop_rate_hz}} with an empty callback that contains a comment marking where to insert control logic.
- Include comments for each section: imports, parameter declaration, publisher setup, subscriber setup, timer callback, and main entry point.
- Ensure the code is syntactically correct and follows ROS naming conventions.
Output format Provide a single code block in the chosen language. Keep it under 100 lines. Use clear placeholder comments like "# TODO: implement control logic". Tone: professional and concise. Do not include any business logic or hardware-specific code.
Guardrails
- Do not invent message types, package names, or parameter names; use only the placeholders provided.
- Flag any assumptions about ROS version or language if not specified.
- Tell the user to verify the skeleton against their ROS distribution documentation and hardware interface.
Example ROS 2 Humble, Python, node_name: motor_controller, package_name: my_robot, publishers: /cmd_vel: geometry_msgs/Twist, subscribers: /odom: nav_msgs/Odometry, parameters: max_speed: double = 1.0, wheel_base: double = 0.5, loop_rate_hz: 10.