Manual

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 rclcpp::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 : public rclcpp::Node
{
public:
TurtleBot4FirstNode()
: Node("turtlebot4_first_cpp_node")
{
// Subscribe to the /interface_buttons topic
interface_buttons_subscriber_ =
this->create_subscription<irobot_create_msgs::msg::InterfaceButtons>(
"/interface_buttons",
rclcpp::SensorDataQoS(),
std::bind(&TurtleBot4FirstNode::interface_buttons_callback, this, std::placeholders::_1));
}
private:
// Interface buttons subscription callback
void interface_buttons_callback(
const irobot_create_msgs::msg::InterfaceButtons::SharedPtr create3_buttons_msg)
{}
// Interface Button Subscriber
rclcpp::Subscription<irobot_create_msgs::msg::InterfaceButtons>::SharedPtr
interface_buttons_subscriber_;
};
Notice that the interface_buttons_subscriber_ uses the InterfaceButtons message type, and the
quality of service is rclcpp::SensorDataQoS(). 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.