Manual
# Create a publisher for the /cmd_lightring topic
self.lightring_publisher = self.create_publisher(
LightringLeds,
'/cmd_lightring',
qos_profile_sensor_data)
# Interface buttons subscription callback
def interface_buttons_callback(self, create3_buttons_msg: InterfaceButtons):
# Button 1 is pressed
if create3_buttons_msg.button_1.is_pressed:
self.get_logger().info('Button 1 Pressed!')
self.button_1_function()
# Perform a function when Button 1 is pressed
def button_1_function(self):
# Create a ROS2 message
lightring_msg = LightringLeds()
# Stamp the message with the current time
lightring_msg.header.stamp = self.get_clock().now().to_msg()
# Lights are currently off
if not self.lights_on_:
# Override system lights
lightring_msg.override_system = True
# LED 0
lightring_msg.leds[0].red = 255
lightring_msg.leds[0].blue = 0
lightring_msg.leds[0].green = 0
# LED 1
lightring_msg.leds[1].red = 0
lightring_msg.leds[1].blue = 255
lightring_msg.leds[1].green = 0
# LED 2
lightring_msg.leds[2].red = 0
lightring_msg.leds[2].blue = 0
lightring_msg.leds[2].green = 255
# LED 3
lightring_msg.leds[3].red = 255
lightring_msg.leds[3].blue = 255
lightring_msg.leds[3].green = 0