Welcome to ROSMASTER X3 repository
5.ROS function package
5.ROS function package
The function package is a folder used to store each node program. This section explains how to create a function package in the src directory of the workspace ros_ws created in the previous section.
5.1 Create function package
The function package is stored in the src folder under the workspace folder. Enter the following command to create it. Take creating the learn_topic function package as an example. Terminal input,
cd ~/ros_ws/srccatkin_create_pkg learn_topic std_msgs rospy roscpp geometry_msgs turtlesim
Explain what the command line consists of:
- catkin_create_pkg:create command
- learn_topic:the name of the function package
- roscpp、rospy、geometry_msgs turtlesim:This is a dependent library of the function package. It can also be added to the CMakeLists.txt file in the function package directory when needed later.
5.2 Function package folder description
There are the following files under the created function package:

- include: stores header files that need to be compiled
- src: stores the source code files for compiling node programs
- CMakeLists.txt: files required for compilation, including declaring which libraries need to be connected, which dependencies are required, which programs are generated, etc.
- package.xml: declares some dependencies required for compilation and some information about the function package, including the function package version, the author of the function package creation, etc.
Later, we will learn how to write a node program. There will be a C++ version and a Python version. Generally, the C++ version of the program source code is stored in src.The source code of the Python version is stored in the scripts folder. This folder is created by yourself under the function package path. You can enter the following command to create it,
xxxxxxxxxxcd ~/ros_ws/src/learn_topicmkdir scripts
Including the launch files and customized message files that will be mentioned later, the corresponding launch files and msg folders need to be created in the directory of the function package for storage.