Introduction to ros project compilation

1. To build a ROS project, you must first understand its organizational structure, understand the functions and functions of each file, be
fundamentally familiar with the organizational form of the ROS project, understand the functions and functions of each file, and then develop and program correctly.

insert image description here

Detailed organization

insert image description here

Now make a simple example
2. Sample code:

#include “ros/ros.h”
int main(){
ROS_WARN(“wrong”);
}

#1、新建test_c_ws工程,
mkdir -p test_c_ws/src
cd test_c_ws/src

# 在它下面新建test1功能包
# 直接使用catkin_create_pkg指令(可以自动创建package.xml和CMakeLists.txt文件)
# 格式为:catkin_create_pkg 包名 ros库1 ros库2…
catkin_create_pkg test1 roscpp
cd test1/src/

# 在test1/src目录下新建一个wrong.cpp,敲下上述示例代码。
#include “ros/ros.h”
int main(){
ROS_WARN(“wrong”);
}

2. Modify the package.xml and CMakeLists.txt files in the test1 directory
without modifying package.xml, mainly to modify CMakeLists.txt
to find the following part and remove the comments before include

insert image description here
and add below

add_executable(wrong src/wrong.cpp)
target_link_libraries(wrong ${catkin_LIBRARIES})


3. Project compilation and program operation
1. Compile the project
In the test_c_ws project directory, compile the project
sudo chmod 777 src -R to give the file read and write and execute permissions with one key
catkin_make compile

2. Configure the workspace and refresh the environment
source devel/setup.bash
can also be directly added to the end of the ~/.bashrc file

3. Run the program (start as a node node separately)
rosrun test1 wrong

Normally compiled node will generate node files under devel/lib/corresponding package/ of the corresponding project directory, which
can be run directly
with ./wrong


Original link: https://blog.csdn.net/m0_52118763/article/details/120876198

Guess you like

Origin blog.csdn.net/lian740930980/article/details/126830040