Ubuntu 20中在LXD容器内安装ROS
生活随笔
收集整理的這篇文章主要介紹了
Ubuntu 20中在LXD容器内安装ROS
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
快速構(gòu)建并銷毀一個(gè)完整的ROS套件。
關(guān)于容器的更多細(xì)節(jié)可以參考linuxcontainer.org
配置容器
基礎(chǔ)lxd創(chuàng)建工作
安裝lxd
~$ sudo snap install lxd安裝后用
~$ sudo lxc info查看信息如下:
If this is your first time running LXD on this machine, you should also run: lxd init To start your first instance, try: lxc launch ubuntu:18.04 …… …… ……初始化lxd
根據(jù)提示運(yùn)行
按照默認(rèn)一路回車
Would you like to use LXD clustering? (yes/no) [default=no]: Do you want to configure a new storage pool? (yes/no) [default=yes]: Name of the new storage pool [default=default]: Name of the storage backend to use (btrfs, dir, lvm, zfs, ceph) [default=zfs]: Create a new ZFS pool? (yes/no) [default=yes]: Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]: Size in GB of the new loop device (1GB minimum) [default=30GB]: Would you like to connect to a MAAS server? (yes/no) [default=no]: Would you like to create a new local network bridge? (yes/no) [default=yes]: What should the new bridge be called? [default=lxdbr0]: What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: Would you like the LXD server to be available over the network? (yes/no) [default=no]: Would you like stale cached images to be updated automatically? (yes/no) [default=yes] Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:查看lxc的profile
~$ sudo lxc profile list +---------+---------------------+---------+ | NAME | DESCRIPTION | USED BY | +---------+---------------------+---------+ | default | Default LXD profile | 0 | +---------+---------------------+---------+創(chuàng)建ROS lxc配置
創(chuàng)建lxc的ros profile
~$ sudo lxc profile create rosp Profile ros created修改lxc的ros profile
~$ sudo lxc profile edit ros修改文件至如下:
### This is a YAML representation of the profile. ### Any line starting with a '# will be ignored. ### ### A profile consists of a set of configuration items followed by a set of ### devices. ### ### An example would look like: ### name: onenic ### config: ### raw.lxc: lxc.aa_profile=unconfined ### devices: ### eth0: ### nictype: bridged ### parent: lxdbr0 ### type: nic ### ### Note that the name is shown but cannot be changedconfig: ### X Window顯示environment.DISPLAY: :0 ### 從宿主機(jī)映射userid至容器raw.idmap: both 1001 1000 ### 增加ros repositoriesuser.user-data: |#cloud-configruncmd:- "apt-key adv --fetch-keys https://raw.githubusercontent.com/ros/rosdistro/master/ros.key"- "apt-add-repository http://packages.ros.org/ros2/ubuntu"- "apt-add-repository http://packages.ros.org/ros/ubuntu" description: ROSX0:path: /tmp/.X11-unix/X0source: /tmp/.X11-unix/X0type: disk ### 網(wǎng)絡(luò)設(shè)置為橋接eth0:name: eth0nictype: bridgedparent: lxdbr0type: nicroot:path: /pool: defaulttype: disk name: ros used_by: []說明:
取可連接外網(wǎng)的網(wǎng)卡名
確認(rèn)ros profile創(chuàng)建成功
~$ sudo lxc profile list +---------+---------------------+---------+ | NAME | DESCRIPTION | USED BY | +---------+---------------------+---------+ | default | Default LXD profile | 0 | +---------+---------------------+---------+ | ros | ROS | 0 | +---------+---------------------+---------+啟動(dòng)容器
使用lxc launch創(chuàng)建相關(guān)的ros容器
我們這里使用ubuntu 20.04的鏡像
用lxc exec來啟動(dòng)容器內(nèi)的bash shell
~$ sudo lxc exec rosgalactic -- bash root@rosgalactic:~#在默認(rèn)情況下,shell是以root賬戶啟動(dòng)的
用exit命令可以退出該shell。
指定用戶啟動(dòng)
我們可以用–login來指定啟動(dòng)的賬戶
安裝ROS
ubuntu@rosgalactic:~$ sudo apt install ros-galactic-desktop關(guān)于ROS本身安裝中的問題請(qǐng)參照ROS2學(xué)習(xí)(一).Ubuntu 20.04安裝ROS2 Galactic 。
啟動(dòng)確認(rèn)
ubuntu@rosgalactic:~$ rqt添加快速啟動(dòng)參數(shù)
~$ sudo lxc alias add ubuntu 'exec @ARGS@ --user 1000 --group 1000 --env HOME=/home/ubuntu -- /bin/bash --login' ~$ sudo lxc alias list +--------+-----------------------------------------------------------------------------------+ | ALIAS | TARGET | +--------+-----------------------------------------------------------------------------------+ | ubuntu | exec @ARGS@ --user 1000 --group 1000 --env HOME=/home/ubuntu -- /bin/bash --login | +--------+-----------------------------------------------------------------------------------+ ~$ sudo lxc ubuntu rosgalactic ubuntu@rosgalactic:~$ source /opt/ros/galactic/setup.bash ubuntu@rosgalactic:~$ ros2 run demo_nodes_cpp talker至此,大功告成!
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的Ubuntu 20中在LXD容器内安装ROS的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ROS2学习(七).ROS概念 - RO
- 下一篇: ROS2学习(八).ROS概念 - RO