๐ Adding New Nodes & Packages
This guide explains how to create new ROS2 nodes and packages for the LIMO Pro + MyCobot + YOLO ecosystem, follow architectural best practices, integrate them into the workflow, and test them safely.
๐ฆ Creating a New Packageโ
We use ROS2 Python packages for most nodes in this project.
cd ~/krish_ws/src
ros2 pkg create --build-type ament_python my_new_node
Structure:
my_new_node/
โโโ package.xml
โโโ setup.py
โโโ resource/my_new_node
โโโ my_new_node/__init__.py
โโโ my_new_node/my_new_node.py
โโโ launch/
๐งฉ Node Architecture Guidelinesโ
Keep it Modular
Each node should have one core responsibility (e.g., detection, navigation, arm control) and communicate via ROS2 topics/services/actions.
Required structure inside a node:
1. Initializationโ
- Node name
- Parameters
- Publishers/Subscribers/Action clients
- Logging start message
2. Core Logicโ
- Main loop or callbacks
- State handling (if applicable)
3. Shutdown Handlingโ
- Stop motors, close connections, save state
Example skeleton:
import rclpy
from rclpy.node import Node
class MyNewNode(Node):
def __init__(self):
super().__init__('my_new_node')
self.get_logger().info("Node initialized.")
def main_loop(self):
pass # Core logic here
def main(args=None):
rclpy.init(args=args)
node = MyNewNode()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
๐ Integration Proceduresโ
To integrate a new node:
1. Add to Launch Fileโ
Use launch_ros.actions.Node in full_system.launch.py with proper TimerAction so it starts after dependencies are ready.
2. Respect Existing Topicsโ
- If publishing
/target_pose, ensure format matchesPoseStampedfromobject_detector.py. - Avoid name collisions with existing topics.
3. Parameterize IPs and Pathsโ
- For hardware nodes (like MyCobot), accept IP from
--ros-args -p m5_ip:=.... - Never hardcode file paths โ use ROS2 params.
4. Logging & Voice Feedbackโ
- Use
self.get_logger().info()for state changes. - For user feedback, follow the
say()function pattern inpick_node.pyandmission_manager.py.
๐งช Testing New Nodesโ
- Simulation First
- Hardware Deployment
- Use RViz2 and fake data to test without risking hardware.
- If it's a detection node, feed it saved images.
- If it's a navigation node, test in Gazebo before the real robot.
- Ensure the workspace is clear of obstacles.
- Launch only your new node + dependencies:
ros2 run my_new_node my_new_node - Watch logs in real-time:
ros2 topic echo /your_topic
โ Pre-Merge Checklist for New Nodesโ
- โ Package builds with
colcon build --symlink-install - โ Code follows Code Style Guidelines
- โ Node starts without errors or warnings
- โ Integration tested with
full_system.launch.py - โ Does not break Mission Manager or YOLO detection logic
๐ Read Next: Launch & Config File Creation
Next: Launch Configuration Files