美文网首页ROS自主导航机器人
ROS机器人底盘(43)-使用docker创建pibot ros

ROS机器人底盘(43)-使用docker创建pibot ros

作者: PIBOT导航机器人 | 来源:发表于2022-03-12 11:59 被阅读0次

    1. docker安装

    docker 安装可以参考官方链接按照提示一步一步操作可
    对于ubuntu

    # 删除旧版本 sudo apt-get remove docker docker-engine docker.io containerd runc
    sudo apt-get update
    sudo apt-get install ca-certificates curl gnupg lsb-release
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli containerd.io
    

    2. 添加权限

    添加docker权限,给当前用户,使docker命令免sudo执行

    sudo groupadd docker 
    sudo gpasswd -a ${USER} docker 
    sudo service docker restart 
    

    执行完成后只需要退出登出当前用户再重新登入即可,或者直接重启
    执行docker ps 无异常即可

    3. PIBOT ROS环境镜像

    3.1 pibot env

    • pull image
     docker pull registry.cn-hangzhou.aliyuncs.com/pibot/pibot:melodic
    
    • confirm
    ❯ docker images
    REPOSITORY                                      TAG       IMAGE ID       CREATED          SIZE
    registry.cn-hangzhou.aliyuncs.com/pibot/pibot   melodic   a08b09485640   3 days ago       3.09GB
    

    3.2 编译

    3.2.1 启动容器

    • 启动上面的docker镜像
    • 同时把pibot_ros目录映射的容器里
    • 同时可以选择把串口设备映射到容器

    如下面命令

    docker run --rm -it -v "${HOME}/pibot_ros:/root/pibot_ros" \
                        --name pibot \
                        --device /dev/rplidar:/dev/rplidar \
                        --device /dev/pibot:/dev/pibot \
                        registry.cn-hangzhou.aliyuncs.com/pibot/pibot:melodic /bin/bash
    

    3.2.2 编译环境

    在上面的终端或这个执行docker exec -it pibot bash启动新的终端进入容器

    cd ~/pibot_ros
    # 配置pibot相关参数类型
    ./pibot_init_env.sh -m apollo -b stm32f1 -l rplidar -c none -a localhost
    source ~/.bashrc
    # 编译
    cd ~/pibot_ros/ros_ws/ && catkin_make
    

    3.2.3 测试

    • 执行docker exec -it pibot bash启动新的终端进入容器输入pibot_gmapping打开gmapping slam
    • 执行docker exec -it pibot bash启动新的终端进入容器输入pibot_control打开控制终端即可控制pibot小车

    3.2.4 可视化

    配置的这个docker容器是无法启动图形界面的,如pibot_view启动rviz是无法启动的

    root@45f1d3a89920:~# rosrun rviz rviz
    QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
    qt.qpa.screen: QXcbConnection: Could not connect to display 
    Could not connect to any X display
    

    我们可以配置多级通讯的方法,在宿主机启动rviz

    容器中我们通过命令查看可以看到

    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
            ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
            RX packets 79  bytes 13851 (13.8 KB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    root@45f1d3a89920:~/pibot_ros# ./pibot_view_env.sh 
    PIBOT_ENV_INITIALIZED:   1
    SYS_DIST:                bionic
    ROS_DIST:                melodic
    ROS_MASTER_URI:          http://172.17.0.2:11311
    ROS_IP:                  172.17.0.2
    ROS_HOSTNAME:            172.17.0.2
    PIBOT_MODEL:             apollo
    PIBOT_LIDAR:             rplidar
    PIBOT_BOARD:             stm32f1
    PIBOT_3DSENSOR:          none
    *****************************************************************
    

    宿主机中的ifconfig可以看到docker的网卡ip是172.17.0.1

    ❯ ifconfig
    docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
            inet6 fe80::42:c9ff:feca:591a  prefixlen 64  scopeid 0x20<link>
            ether 02:42:c9:ca:59:1a  txqueuelen 0  (Ethernet)
            RX packets 65597  bytes 4695797 (4.6 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 136671  bytes 205180802 (205.1 MB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    enp2s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            ether 44:8a:5b:59:f3:9d  txqueuelen 1000  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 3414  bytes 382515 (382.5 KB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 3414  bytes 382515 (382.5 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    

    我们只需要在宿主机设置ROS_MASTER_URI指向容器中的地址172.17.0.2,我们可以使用pibot提供的脚本pibot_init_env.sh配置,配置后可以查看当前配置如下

     ~/pibot_ros  v2.0.0 *2 ?1  ./pibot_view_env.sh                                 ✔    11:56:02 
    PIBOT_ENV_INITIALIZED:   1
    SYS_DIST:                bionic
    ROS_DIST:                melodic
    ROS_MASTER_URI:          http://172.17.0.2:11311
    ROS_IP:                  172.17.0.1
    ROS_HOSTNAME:            172.17.0.1
    PIBOT_MODEL:             apollo
    PIBOT_LIDAR:             rplidar
    PIBOT_BOARD:             stm32f1
    PIBOT_3DSENSOR:          none
    

    这样我们在主机端输入pibot_view就可以启动rviz

    相关文章

      网友评论

        本文标题:ROS机器人底盘(43)-使用docker创建pibot ros

        本文链接:https://www.haomeiwen.com/subject/xsmhrrtx.html