Summary: After making a node, the standard workflow is:

🔹 Standard Workflow for a New Node (ament_python)

1. Create workspace + package

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_python my_package

This gives you package.xml, setup.py, and a Python module folder (my_package/).


2. Write your node

Inside ~/ros2_ws/src/my_package/my_package/ create my_node.py:

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from std_msgs.msg import String

class MinimalNode(Node):
    def __init__(self):
        super().__init__('minimal_node')
        self.publisher_ = self.create_publisher(String, 'chatter', 10)
        self.timer = self.create_timer(1.0, self.timer_callback)

    def timer_callback(self):
        msg = String()
        msg.data = "Hello ROS2!"
        self.publisher_.publish(msg)
        self.get_logger().info(f'Publishing: "{msg.data}"')

def main():
    rclpy.init()
    node = MinimalNode()
    rclpy.spin(node)
    rclpy.shutdown()

if __name__ == '__main__':
    main()

Make it executable:

chmod +x ~/ros2_ws/src/my_package/my_package/my_node.py


3. Edit setup.py

Tell ROS how to run your node:

entry_points={
    'console_scripts': [
        'talker = my_package.my_node:main',
    ],
},

This means:

ros2 run my_package talker

will run the main() function from my_node.py.