Add your dependencies
For this tutorial, we will need to use the
rclcpp and irobot_create_msgs
packages. The
rclcpp
package allows us to create ROS2 nodes and gives us full access to all the base ROS2
functionality in C++. The
irobot_create_msgs
package gives us access to the custom messages
used by the Create® 3 for reading the button presses and controlling the lightring.
In your CMakeLists.txt file, add these lines under
find_package(ament_cmake
REQUIRED):
find_package(rclcpp REQUIRED)
find_package(irobot_create_msgs REQUIRED)
and add this line under
add_executable(turtlebot4_first_cpp_node
src/turtlebot4_first_cpp_node.cpp):
ament_target_dependencies(turtlebot4_first_cpp_node rclcpp irobot_create_msgs)
In package.xml, add these lines under <buildtool_depend>ament_cmake</buildtool_depend>:
<depend>rclcpp</depend>
<depend>irobot_create_msgs</depend>
Finally, in your nodes
.cpp
file you will need to include these headers:
#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include "rclcpp/rclcpp.hpp"
#include "irobot_create_msgs/msg/interface_buttons.hpp"
#include "irobot_create_msgs/msg/lightring_leds.hpp"
Need help?
Do you have a question about the Turtlebot4 and is the answer not in the manual?
Questions and answers