Document Creation Date: March 27, 2023
This document records the process of creating a ROS function package, adding nodes and running
By RobotFreak
Create workspace and initialize
mkdir -p 自定义空间名称/src
cd 自定义空间名称
catkin_make
The src directory must be created in the workspace before catkin_make, otherwise catkin_make will report an error and fail to compile.
Enter src to create ros package and add dependencies
cd src
catkin_create_pkg 自定义ROS包名 roscpp rospy std_msgs
The above command will generate a function package in the workspace, which depends on roscpp, rospy and std_msgs, where roscpp is a library implemented in C++, rospy is a library implemented in python, and std_msgs is a standard message library. Create ROS function packages generally rely on these three libraries for implementation.
Add the scrpts directory in the function package and edit the python file
cd ros包
mkdir scripts
Create and edit python files in the scripts directory
Add executable permissions to python files
chmod +x 自定义文件名.py
Edit the CmakeList.txt file under the ros package
catkin_install_python(PROGRAMS scripts/自定义文件名.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
Enter the workspace directory and compile
cd 自定义空间名称
catkin_make
Enter the workspace directory and execute
First start the command line 1:
roscore
Start command line 2 again:
cd 工作空间
source ./devel/setup.bash
rosrun 包名 自定义文件名.py
problem solved
(SOLVED)Could NOT find PY_em(missing: PY_em)
In the anaconda vision environment, the following error occurs directly after catkin_make:
Refer to the following blog:
(16 messages) ROS error: -- Could NOT find PY_em (missing: PY_EM)_High Precision Computer Vision Blog-CSDN Blog
The reason is that the python in the anaconda environment is used, and this problem can be solved by using the system's python:
catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3