EasyManua.ls Logo

CLEARPATH Turtlebot4 - Page 118

Default Icon
153 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Create a lightring publisher
Now that we can receive a button press, lets create a lightring publisher.
class TurtleBot4FirstNode(Node):
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)
# Create a publisher for the /cmd_lightring topic
self.lightring_publisher = self.create_publisher(
LightringLeds,
'/cmd_lightring',
qos_profile_sensor_data)
Note
The Lightring publisher uses the LightringLeds message type.
Next, lets create a function that will populate a LightringLeds message, and publish it.
Add this code below your interface_buttons_callback function:
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()
# 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