Add a boolean to keep track of the light state:
class
TurtleBot4FirstNode
(Node):
lights_on_ =
False
def
__init__
(
self
):
And modify
button_1_function
to toggle the light:
# 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
# LED 4
lightring_msg.leds[
4
].red =
255
Summary of Contents for TurtleBot 4 Lite
Page 50: ...Running the Light Ring test...
Page 61: ...Adding Displays in Rviz2...
Page 63: ...Camera image displayed in Rviz2...
Page 82: ...TurtleBot 4 Lite with a NED2 arm...
Page 147: ...Color camera diagnostics...