lightring_msg.leds[4].blue =
lightring_msg.leds[4].green =
# LED 5
lightring_msg.leds[5].red =
lightring_msg.leds[5].blue =
lightring_msg.leds[5].green =
# Lights are currently on
else:
# Disable system override. The system will take back control of the lightring.
lightring_msg.override_system =
# Publish the message
self.lightring_publisher.publish(lightring_msg)
# Toggle the lights on status
self.lights_on_ = not self.lights_on_
Now the Create® 3 will regain control of the lightring if we press button 1 again.
Your first Python Node
You have finished writing your first Python node! The final
from irobot_create_msgs.msg import InterfaceButtons, LightringLeds
import rclpy
from rclpy.node import Node
from rclpy.qos import qos_profile_sensor_data
class TurtleBot4FirstNode(Node):
lights_on_ =
False
def __init__(self):
super().__init__('turtlebot4_first_python_node')
# Subscribe to the /interface_buttons topic
self.interface_buttons_subscriber = self.create_subscription(
InterfaceButtons,
'/interface_buttons',
self.interface_buttons_callback,
qos_profile_sensor_data)
0
255
0
255
255
False
.py
file should look like this:
Need help?
Do you have a question about the Turtlebot4 and is the answer not in the manual?
Questions and answers