我在使用 Ubuntu Core 和 ROS 时遇到了一些问题。我正在使用 Snapcraft。我能够完成“创建您的第一个 snap”教程 (https://snapcraft.io/docs/build-snaps/your-first-snap),一切都很好。
然后我按照 ROS 教程(https://github.com/snapcore/snapcraft/blob/master/docs/ros-snap.md)。我没有使用 talker 和 listener,而只使用一个“hello world”节点向屏幕输出消息。我可以顺利构建和安装,但在运行时我得到以下输出:
$USER@localhost:~$ ros-example.launch-project
... logging to /home/$USER/snap/ros-example/x1/ros/log/a413e04a-efb3-11e6-bf45-3d232f894a41/roslaunch-localhost.localdomain-7392.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Traceback (most recent call last):
File "/snap/ros-example/x1/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/__init__.py", line 307, in main
p.start()
File "/snap/ros-example/x1/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/parent.py", line 268, in start
self._start_infrastructure()
File "/snap/ros-example/x1/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/parent.py", line 217, in _start_infrastructure
self._load_config()
File "/snap/ros-example/x1/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/parent.py", line 132, in _load_config
roslaunch_strs=self.roslaunch_strs, verbose=self.verbose)
File "/snap/ros-example/x1/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/config.py", line 471, in load_config_default
config.assign_machines()
File "/snap/ros-example/x1/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/config.py", line 222, in assign_machines
if [m for m in machine_unify_dict.values() if not is_machine_local(m)]:
File "/snap/ros-example/x1/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/core.py", line 97, in is_machine_local
local_addresses = ['localhost'] + rosgraph.network.get_local_addresses()
File "/snap/ros-example/x1/opt/ros/kinetic/lib/python2.7/dist-packages/rosgraph/network.py", line 218, in get_local_addresses
for iface in netifaces.interfaces():
OSError: [Errno 13] Permission denied
我已经在 cmake 列表中添加了 .cpp、.hpp 和 .launch 文件的安装规则,并且运行命令roslaunch
可以运行节点。但在核心环境中以 snap 方式运行不起作用。任何建议都将不胜感激。
这是我的 cmake 列表:
cmake_minimum_required(VERSION 2.8.3)
project(hello_world)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
catkin_package()
include_directories(${catkin_INCLUDE_DIRS})
add_executable(write_prompt src/write_prompt.cpp)
target_link_libraries(write_prompt ${catkin_LIBRARIES})
install(TARGETS write_prompt
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN "*.hpp"
PATTERN ".svn" EXCLUDE
)
install(FILES
launch/run_code.launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
还有我的 snapcraft.yaml:
name: ros-example
version: 1.0
summary: ROS Example
description: Runs a modified Hello World node
confinement: strict
apps:
launch-project:
command: roslaunch hello_world run_code.launch
parts:
ros-project:
plugin: catkin
source: .
catkin-packages:
- hello_world
rosdistro: kinetic
答案1
您已经很接近了!您的快照没有请求访问网络,默认情况下快照不会获得网络访问权限。您可以通过设置plugs
相关应用程序的属性来做到这一点。尝试让您的apps
部分看起来像这样:
apps:
launch-project:
command: roslaunch hello_world run_code.launch
plugs: [network, network-bind]
安装完成后,运行snap interfaces
,您将看到network
和network-bind
插头都连接到核心插槽。要了解更多信息,请查看snapd 接口 wiki。
作为额外的练习,一旦它工作正常,请尝试断开接口:
sudo snap disconnect ros-example:network
sudo snap disconnect ros-example:network-bind
然后再次运行你的应用。你应该看到它再次失败并出现相同的错误。
最后要注意的是,当你开发/测试某些东西时,请记住你可以安装以--devmode
跳过限制:sudo snap install --devmode <my snap>
。