CLEARPATH Turtlebot4 User Manual page 98

Table of Contents

Advertisement

Creating your first node (C++)
This tutorial will go through the steps of creating a ROS2 package and writing a ROS2 node in
C++. For a Python example, click here. These steps are similar to the
ROS2
Tutorial, but focus
on interacting with the TurtleBot 4. For source code, click here.
Note
You can follow this tutorial on either the Raspberry Pi of your TurtleBot 4, or your PC.
Create a workspace
If you do not already have a workspace, open a terminal and create one in the directory of your
choice:
mkdir
~/turtlebot4_ws/src
-p
Create a package and node
You will need to create a ROS2 package to hold your files. For this tutorial, we will create a
package called
turtlebot4_cpp_tutorials
with a node called turtlebot4_first_cpp_node.
source
/opt/ros/galactic/setup.bash
cd
~/turtlebot4_ws/src
ros2 pkg create
--build-type
ament_cmake
--node-name
turtlebot4_first_cpp_node
turtlebot4_cpp_tutorials
This will create a
turtlebot4_cpp_tutorials
folder and populate it with a basic "Hello World" node,
as well as the CMakeLists.txt and package.xml files required for a ROS2 C++ package.
Write your node
The next step is to start coding. For this tutorial, our goal will be to use the Create® 3 interface
button 1 to change the colour of the Create® 3 lightring. Open up the "Hello World"
.cpp
file
located at
~/turtlebot4_ws/src/turtlebot4_cpp_tutorials/src/turtlebot4_first_cpp_node.cpp
in your
favourite text editor.

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?

Questions and answers

This manual is also suitable for:

Turtlebot 4 lite

Table of Contents