ROS2 Interface Development Documentation•Chapter 6: LED Control

Chapter 6: LED Control

Updated: October 14, 2026

1 Interface Overview

The LED control interface is used to control the LED light effects on the robot, supporting various colors and LED effect modes (blinking, constant on, breathing, water flow, etc.). Developers switch LED modes by publishing the LedControl message, and the command takes effect immediately.

2 Message Fields and Mode Enum

Communication Interface:

Topic NameMessage TypeDirectionDescription
/hardware/led_controlLedControl.msgClient → Lighting Control ServiceSend lighting control request

The complete message definition can be found in the GitHub Message Directory.

Supported LED Modes:

Mode ConstantDescriptionEffect
0RestoreRestore built-in lighting
BLINK_REDRed blinkingLED red fast blinking
BLINK_GREENGreen blinkingLED green fast blinking
BLINK_BLUEBlue blinkingLED blue fast blinking
BLINK_WHITEWhite blinkingLED white fast blinking
CONSTANT_ON_WHITEWhite constant onLED white continuously lit
CONSTANT_ON_GREENGreen constant onLED green continuously lit
BREATHE_WHITEWhite breathingLED white breathing effect
WATER_WHITEWhite water flowLED white water flow effect
BREATHE_REDRed breathingLED red breathing effect
BLINK_ORANGEOrange blinkingLED orange fast blinking
CONSTANT_ON_ORANGEOrange constant onLED orange continuously lit

3 Example: LED Mode Cycling

File Name: led_control_example.py

This example automatically switches the LED mode every 1 second, cycling through all available lighting effects.

Run Command:

Bash
python3 src/interface_example/scripts/led_control_example.py

Custom LED Control:

Python
import rclpy
from rclpy.node import Node
from interface_protocol.msg import LedControl

class LedControlExample(Node):
    def __init__(self):
        super().__init__("led_control_example")
        self.pub = self.create_publisher(LedControl, "/hardware/led_control", 10)
        # Switch LED mode every 1 second
        self.modes = [LedControl.BLINK_RED, LedControl.BREATHE_WHITE,
                      LedControl.CONSTANT_ON_GREEN, LedControl.WATER_WHITE]
        self.idx = 0
        self.create_timer(1.0, self._tick)

    def _tick(self):
        msg = LedControl()
        msg.color = self.modes[self.idx]
        self.pub.publish(msg)
        self.get_logger().info(f"LED mode: {self.modes[self.idx]}")
        self.idx = (self.idx + 1) % len(self.modes)

rclpy.init()
rclpy.spin(LedControlExample())

4 Notes

  • LED control commands take effect immediately
  • It is recommended to control the publishing frequency to avoid overly frequent switching
  • Some mode combinations may not be supported by the hardware
  • If a built-in system error or warning occurs, the ROS2 lighting design interface will become invalid

📎 Source files in the open-source repository for this chapter (click file name to jump to GitHub): LedControl.msg · led_control_example.py