Generate deb installable package from ROS Package

本文详细介绍了如何将ROS包打包成Debian安装文件。首先,以beginner_tutorial为例,演示如何为Python和C++文件生成deb包,并安装到Ubuntu系统中。然后,针对RoboteQ ROS包,解释了如何处理依赖并生成相应的Debian包。通过这些步骤,可以方便地分发和安装ROS包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



Generate deb installable package from ROSPackage

 

Section 1, Package beginner_tutorial into Debian File

This tutorial assumesyou have already created the ros beginner_tutorial package by following the ROSbeginner tutorial(http://wiki.ros.org/ROS/Tutorials). You can also refer to the zipped packagefiles which is beginner_tutorials.tar.gz and beginner_tutorials_cpp.tar.gz, andexperiment with it.

Install Python files using deb

In the beginner_tutorialsROS package folder, the tree structure of the folder is as following:

 

To add the pythonsource code files to the deb, you need to add following lines to theCMakeLists.txt:

FILE(GLOB openag_script_files "${CMAKE_CURRENT_SOURCE_DIR}/script/*.*") # This line #will give the variable, openag_script_files, value of each file in the scrip#t folder
FILE(GLOB openag_subdirectory_script_files "${CMAKE_CURRENT_SOURCE_DIR}/script/srv/*.*")
 
#The following code block will install python file which in the openag_script_#files to the destination folder. About the Macro, catkin_install_python, ple#ase refer: http://docs.ros.org/jade/api/catkin/html/howto/format2/installing#_python.html
catkin_install_python(PROGRAMS
  ${openag_script_files}
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
 
# The following code block will install python file which in the openag_script_files to# the destination folder
catkin_install_python(PROGRAMS
  ${openag_subdirectory_script_files}
  DESTINATION "${CATKIN_PACKAGE_BIN_DESTINATION}/srv")
 
 

 

If you don’t add thecode above to the CMakeLists.txt file, your deb file do not contain the pythonexecutable files. After install the deb, the python executable files will NOTbe installed on your machine.

Another alternative wayof install python script files in the deb file, it is writing following macros.It has the same effect as catkin_install_python:

install(PROGRAMS
  script/listener.py
  script/talker.py
  script/add_two_ints_client.py
  script/add_two_ints_server.py
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
# The installation destination of python executable file is ${CATKIN_PACKAGE_SHARE_DE#STINATION} which is /opt/ros/kinetic/lib/
#If after you install the deb, the rosrun can’t find the python executable. Then chan#ge this destination to ${CATKIN_PACKAGE_SHARE_DESTINATION} wh
### ROS 2 Package 的创建与使用指南 ROS 2 中的 package 是组织功能模块的基本单位,用于封装节点、消息定义、配置文件和可执行程序等。创建一个 ROS 2 package 需要使用 `ros2 pkg create` 命令,并指定所需的依赖项。 #### 创建 ROS 2 PackageROS 2 中,使用以下命令创建一个新的包: ```bash ros2 pkg create my_robot_package --build-type ament_cmake --dependencies rclcpp std_msgs ``` 其中: - `my_robot_package` 是新包的名称; - `--build-type` 指定构建系统类型,如 `ament_cmake` 或 `ament_python`; - `--dependencies` 用于声明编译和运行时依赖的消息包或库。 该方式替代了 ROS 1 中的 `catkin_create_pkg` 命令,并整合了现代构建工具链的支持 [^2]。 #### Package 结构 ROS 2 的 package 通常包含以下目录结构: ``` my_robot_package/ ├── CMakeLists.txt ├── package.xml ├── src/ │ └── my_node.cpp ├── include/ │ └── my_robot_package/ ├── launch/ └── msg/ ``` - `package.xml` 定义了包的元信息,包括依赖关系; - `CMakeLists.txt` 控制构建过程; - `src/` 存放 C++ 源代码; - `launch/` 包含启动文件; - `msg/` 用于自定义消息类型的定义。 #### 使用自定义消息类型 若需在 ROS 2 中定义和使用自定义消息类型,需要在 `msg/` 目录下添加 `.msg` 文件,例如 `MyCustomMessage.msg`: ```plaintext string name int32 id float64 temperature bool is_active ``` 随后,在 `package.xml` 中添加以下依赖项以启用消息生成: ```xml <depend>std_msgs</depend> <build_depend>message_generation</build_depend> <exec_depend>message_runtime</exec_depend> ``` 同时在 `CMakeLists.txt` 中添加如下内容以触发消息生成: ```cmake find_package(message_generation REQUIRED) add_message_files( FILES MyCustomMessage.msg ) generate_messages( DEPENDENCIES std_msgs ) ``` 构建完成后,该消息类型即可被 C++ 或 Python 节点使用 [^2]。 #### 构建 ROS 2 Package ROS 2 使用 `colcon` 工具进行构建,取代了 ROS 1 中的 `catkin_make`: ```bash cd ~/my_ws colcon build --packages-select my_robot_package ``` 构建成功后,source 环境变量使包可用: ```bash source install/setup.bash ``` #### 运行 ROS 2 Node ROS 2 支持通过 `ros2 run` 命令运行包中的节点: ```bash ros2 run my_robot_package my_node ``` 也可以使用 `launch` 文件一次性启动多个节点: ```python from launch import LaunchDescription from launch_ros.actions import Node def generate_launch_description(): return LaunchDescription([ Node( package='my_robot_package', executable='my_node', name='custom_node' ), ]) ``` 该机制简化了多节点协调运行的过程,并支持条件判断、参数注入等功能 [^1]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值