Turtlebot4Firstnode(); Subscribe To The /Interface_Buttons Topic; Interface_Buttons_Subscriber; Interface_Buttons - CLEARPATH Turtlebot4 User Manual

Table of Contents

Advertisement

TurtleBot4FirstNode()

: Node("turtlebot4_first_cpp_node"), lights_on_(false)
{

// 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));
// Create a publisher for the /cmd_lightring topic
lightring_publisher_ = this->create_publisher<irobot_create_msgs::msg::LightringLeds>(

"/cmd_lightring",

rclcpp::SensorDataQoS());
}
private:

// Interface buttons subscription callback

void
interface_buttons_callback(
const irobot_create_msgs::msg::InterfaceButtons::SharedPtr create3_buttons_msg)
{
// Button 1 is pressed
if (create3_buttons_msg->button_1.is_pressed) {
RCLCPP_INFO(this->get_logger(),
button_1_function();
}
}
// Perform a function when Button 1 is pressed.
void button_1_function()
{
// Create a ROS2 message
auto lightring_msg = irobot_create_msgs::msg::LightringLeds();
// Stamp the message with the current time
lightring_msg.header.stamp = this->get_clock()->now();
// Lights are currently off
if (!lights_on_) {
// Override system lights
lightring_msg.override_system = true;
// LED 0
lightring_msg.leds[0].red = 255;
"Button 1
Pressed!");

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Turtlebot4 and is the answer not in the manual?

This manual is also suitable for:

Turtlebot 4 lite

Table of Contents