Skip to main content

✏️ Code Style & Standards

Consistent code style ensures that the LIMO Pro + MyCobot + YOLO project remains readable, maintainable, and safe.
This guide defines standards, documentation rules, testing requirements, and best practices.


📐 Style & Formatting​

We follow PEP 8 for Python with a few ROS2-specific conventions:

  • 4-space indentation (no tabs).
  • Snake_case for variables/functions: object_detected, navigate_to_pose_msg().
  • PascalCase for class names: PickNode, ExplorationNode.
  • ALL_CAPS for constants: WAYPOINTS, PICK_TIMEOUT.
  • Imports grouped: standard libs → ROS2 → project modules.
# ✅ Example
import math
import time

import rclpy
from rclpy.node import Node

from .utils import quat_from_yaw
Avoid
  • Long functions (>50 lines) — split into smaller methods.
  • Magic numbers — use constants or parameters.
  • Hardcoded paths — pass via ROS2 parameters.

📄 Documentation Requirements​

Every node, class, and function must have docstrings explaining its purpose.

Example:

class PickNode(Node):
"""
Controls the MyCobot arm to pick an object.

Sequence:
1. Open gripper
2. Move to center
3. Move to pickup pose
4. Close gripper
5. Return to center
"""
  • Use inline comments to explain non-obvious math (e.g., yaw calculations, TF transforms).
  • In launch files, comment why a delay exists (TimerAction), not just the value.

🧪 Testing Guidelines​

  • Test individual functions (e.g., quat_from_yaw()).
  • Mock ROS2 publishers/subscribers when possible.
  • Use pytest for automated testing.

💡 Best Practices​

  • Fail safely — if a node crashes, it should not leave motors running.
  • Voice feedback for key states (pick complete, drop complete, navigation start).
  • Use ROS2 parameters instead of editing code for configuration.
  • Log at appropriate levels:
    • self.get_logger().info() → normal operation
    • self.get_logger().warn() → recoverable issue
    • self.get_logger().error() → critical failure
  • Keep launch dependencies modular — avoid one giant launch file for everything.

✅ Pre-Merge Checklist​

  • ☐ Code builds with colcon build --symlink-install
  • ☐ No PEP8 violations (flake8 clean)
  • ☐ All tests pass
  • ☐ Code reviewed by at least one other contributor
  • ☐ No debug prints left (print() → use logger)
Pro Tip

Run black . && isort . before committing to auto-format your Python code.


Next: Testing Framework