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
. These steps are similar to the
, but focus
on interacting with the TurtleBot 4. For source code, click
.
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.
Содержание TurtleBot 4 Lite
Страница 50: ...Running the Light Ring test...
Страница 61: ...Adding Displays in Rviz2...
Страница 63: ...Camera image displayed in Rviz2...
Страница 82: ...TurtleBot 4 Lite with a NED2 arm...
Страница 147: ...Color camera diagnostics...