EasyManua.ls Logo

CLEARPATH Turtlebot4 - Page 115

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...
Subscribe to the Create® 3 interface buttons
Our next step is to subscribe to the Create® 3 interface buttons topic to receive button presses.
We will need to create a rclpy.Subscription as well as a callback function for the subscription.
The callback function will be called every time we receive a message on the interface buttons
topic.
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)
# Interface buttons subscription callback
def interface_buttons_callback(self, create3_buttons_msg: InterfaceButtons):
Notice that the interface_buttons_subscriber uses the InterfaceButtons message type, and the
quality of service is qos_profile_sensor_data. These parameters must match the topic,
otherwise the subscription will fail. If you are unsure what message type or QoS a topic is using,
you can use the ROS2 CLI to find this information.
Call ros2 topic info /<topic> --verbose to get the full details.