1. 在工作空间的src目录下新建工作包
catkin_create_pkg py_test std_msgs rospy
2. 在工作包目录下新建scripts文件夹
mkdir scripts
3. 在scripts文件下新建python文件 test.py
def hello():
print("hello world")
if __name__ == '__main__':
hello()
4. 配置CMakeList.txt
catkin_install_python(PROGRAMS
scripts/*.py
scripts/*.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
5. 运行脚本
格式 rosrun pkg_name ***.py
rosrun py_test test.py