PIBOT上位机开发(ROS1/ROS2)

@[TOC]

1. 概述

采用树莓派/RK3288/RK3399/X86工控机/TK1/TX1/TX2作为上位ROS主控,基于ROS开发适配导航建图算法


2. 软件框架

软件框架图

3. Ubuntu的刷入、ROS(ROS2)的安装

具体请参考树莓派(raspberrypi 3b/4b)安装ROS

tf卡启动的nanopi(RK3399) 则同树莓派一样操作


4. ssh远程连接

windows中推荐安装xshell远程连接

树莓派/nanopi rk3399默认开启了热点ssidpassword均为pibot_ap,可以通过连接该热点连接树莓派/nanopi rk3399,树莓派/nanopi rk3399的IP为192.168.12.1

ap默认配置打开,如果需要重新配置,只需要执行cd ~/pibot_ros/third_party/create_ap && ./config_ap.sh && sudo make install && cd ~/pibot_ros && ./pibot_ap.sh start

如需要关闭ap模式,改为连接wifi,只需要执行cd ~/pibot_ros && ./pibot_ap.sh stop后重启
如需要打开ap模式, 开启则执行cd ~/pibot_ros && ./pibot_ap.sh start后重启

4.1 安装xshell

网盘中下载xshell并安装

通过Xshell连接树莓派/RK3288/RK3399

输入IP和用户名密码

  • 树莓派3B/3B+pibot
  • firefly RK3288、RK3399firefly
  • nanopi 3399pi
pibot_xshell.gif

5. 用户主机

需要一个PC安装ROS环境,用来显示查看地图或者玩转模拟器等,PIBOT提供了一个一键安装ROS的脚本pibot_install_ros,可以直接在Ubuntu下安装ROS
用户主机环境Ubuntu或者Windows7/10+Vmvare+Ubuntu虚拟机Ros kinetic环境, 安装ROS参见Windows下安装Ubuntu虚拟机及ROS相关章节


6. 多机通讯

用户主机树莓派/RK3288/RK3399/TK1/TX1/TX2/X86主机怎么建立ROS通讯的,PIBOT提供了一键配置脚本pibot_init_env

  • 设备端


    pibot_init_env_dev.gif
  • 主机端


    pibot_init_env_host.gif

7. ROS驱动开发

7.1 概述

下位机及通过串口与树莓派/RK3288/RK3399/TK1/TX1/TX2/X86主机通讯,PIBOT提供了一个简单的协议,通讯协议具体请参见协议文档

7.2 驱动开发及PID参数动态调整

PID参数已在出厂时候配置,如需了解细节请参考PIBOT的driver的实现及动态PID调节

7.3 目录结构简介

建议拷贝提供的压缩文件至目标设备(树莓派/RK3288/RK3399/X86工控机/TK1/TX1/TX2)上解压或者直接git clone,不然会遇到一些问题,具体问题见Q&A

PIBOTROS workspace目录如下图

  • arbotix_ros 模拟器
  • pibot 工具集
    pibot
  • pibot_bringup pibot驱动包
    pibot_bringup
  • pibot_description pibot urdf文件
    pibot_description
  • pibot_navigation 建图导航相关配置项
    pibot_navigation
  • pibot_simulator pibot导航模拟器
    pibot_simulator
  • rplidar_ros rplidar激光雷达驱动包
  • ydlidar-1.2.1 eai激光雷达驱动包

7.4 编译与测试

编译

cd ~/pibot_ros
git fetch # 拉取最新的代码
git pull
 # ros2 需要切换到ros分支,如 git checkout -b galactic-devel origin/galactic-devel
cd ~/pibot_ros/ros_ws
catkin_make   # ros2 为 pbmake

测试

初始化配置

重新拔插USB口或者重启树莓派/RK3288/RK3399

ls /dev/pibot -l

开始测试

打开终端输入pibot_,再输入2次tab提示支持的命令

pibot_cmd.gif

也可以输入"alias | grep pibot_"查看所有命令的别名,对应其ros的全命令,如下图

pibot@pibot~$ alias | grep pibot_
alias pibot_base='ros2 launch pibot_bringup robot_launch.py'
alias pibot_base_with_imu='ros2 launch pibot_bringup robot_launch.py'
alias pibot_bringup='ros2 launch pibot_bringup bringup_launch.py'
alias pibot_bringup_with_imu='ros2 launch pibot_bringup bringup_with_imu_launch.py'
alias pibot_cartographer='ros2 launch pibot_navigation cartographer.launch.py'
alias pibot_cartographer_with_odom='ros2 launch pibot_navigation cartographer.launch.py'
alias pibot_configure='ros2 run rqt_reconfigure rqt_reconfigure'
alias pibot_control='ros2 launch pibot_bringup keyboard_teleop_launch.py'
alias pibot_gmapping='ros2 launch pibot_navigation mapping.launch.py'
alias pibot_gmapping_with_imu='ros2 launch pibot_navigation mapping.launch.py'
alias pibot_holonomic_joystick='ros2 launch pibot_bringup joystick_launch.py joy_config:=joystick-holonomic'
alias pibot_joystick='ros2 launch pibot_bringup joystick_launch.py joy_config:=joystick'
alias pibot_lidar='ros2 launch pibot_lidar rplidar_launch.py'
alias pibot_mapping='ros2 launch pibot_navigation mapping.launch.py'
alias pibot_naviagtion='ros2 launch pibot_navigation navigation2.launch.py'
alias pibot_naviagtion_with_imu='ros2 launch pibot_navigation navigation2.launch.py'
alias pibot_save_map='ros2 launch pibot_navigation save_map.launch.py'
alias pibot_simulator='ros2 launch pibot_simulator nav_launch.py'
alias pibot_tf_tree='ros2 run rqt_tf_tree rqt_tf_tree'
alias pibot_view='rviz2 -d ${PIBOT_HOME}/ros_ws/src/pibot_navigation/rviz/nav2_default_view.rviz'
alias pibot_view_cartographer='rviz2 -d ${PIBOT_HOME}/ros_ws/src/pibot_navigation/rviz/nav2_default_view.rviz'

这些命令具体定义在~/.pibotrc文件,该文件是pibot_init_env脚本自动生成的


8. 校准

无IMU校准

参见PIBOT的控制及校准

IMU校准

参见PIBOT的IMU校准


9. ROS建图与导航

9.1 概述

ROS驱动中提供了cmd_vel的订阅及odom的发布,至此再需要一个激光雷达就可以完成建图了

9.2 建图

树莓派/RK3288/RK3399运行pibot_gmapping
用户主机运行pibot_view(ROS2中为``)

pibot_gmappingpibot_view在ROS1/2分别对应下面的命令

  • ROS1
roslaunch pibot_navigation gmapping.launch
roslaunch pibot_navigation view_nav.launch
  • ROS2
ros2 launch pibot_navigation mapping.launch.py
rviz2 -d ${PIBOT_HOME}/ros_ws/src/pibot_navigation/rviz/nav2_default_view.rviz

另外还可以运行pibot_cartographer命令执行使用google cartographer建图
ROS2中使用slam_box提供建图

两种建图方法

  • 运行pibot_control或者pibot_joystick即可通过键盘或者遥控手柄开始建图

pibot_controlpibot_joystick在ROS1/2分别对应下面的命令

  • ROS1
roslaunch pibot keyboard_teleop.launch
roslaunch pibot joystick.launch
  • ROS2
ros2 launch pibot_bringup keyboard_teleop_launch.py
ros2 launch pibot_bringup joystick_launch.py joy_config:=joystick
  • 直接选择导航的点(2D Nav Goal)开始建图

保存地图

  • 运行下列pibot_save_map命令,如需手动指定路径,可以使用ros原命令添加参数即可,如下

pibot_save_map在ROS1/2分别对应下面的命令

  • ROS1
roslaunch pibot_navigation save_map.launch
roslaunch pibot_navigation save_map.launch map_name:=xxx
roscd pibot_navigation/maps/ && rosrun map_server map_saver -f xxx
  • ROS2
ros2 launch pibot_navigation save_map.launch.py
ros2 launch pibot_navigation save_map.launch.py map:=xxx

可以看到生成2个文件


10 导航

单点导航测试

树莓派/RK3288/RK3399输入pibot_naviagtion运行`

pibot_naviagtion在ROS1/2分别对应下面的命令

  • ROS1
roslaunch pibot_navigation nav.launch
roslaunch pibot_navigation nav.launch map_name:=xxx.yaml
  • ROS2
ros2 launch pibot_navigation navigation2.launch.py
ros2 launch pibot_navigation navigation2.launch.py map:=xxx

用户主机运行pibot_view,通过RViz提供的功能既可以完成导航测试(这里需要先指定初始位置)

如果直接运行pibot_naviagtion则使用默认参数,nav.launch文件中可以设置默认使用的地图文件

多点导航

可以通过修改pibot/scripts中的navigation_demo.pypython脚本完成单点和多点的导航
具体可以参考
使用rospy启动launch与定点导航
基于rospy的多点导航的python实现

11. 模拟器

PIBOT包内置了模拟器,可以直接运行pibot_simulator启动模拟器

pibot_simulator在ROS1/2分别对应下面的命令

  • ROS1
roslaunch pibot_simulator nav.launch
- ROS2
```bash
ros2 launch pibot_simulator nav_launch.py

这样无需小车也可以模拟导航了

12. Android App

12.1相关功能

保证手机跟跟PC或者树莓派/RK3288/RK3399连接同一个网络,保证手机能够访问到roscore(export ROS_IP=XXX.XXX.XXX.XXX)具体参见ROS多机的通讯配置


修改Master URI选择roscoreURI 点击CONNECT
切换Camera ViewMap View
android_app

  • Set Pose在地图长按 相当于Rviz中的 2D Pose Estimate
  • Set Goal在地图长按 相当于Rviz中的 2D Nav Goal
  • 左下角Joystick可以发出cmd_vel topic控制小车移动

12.2 显示视频

显示视频需要硬件摄像头支持同时在PC或者树莓派/RK3288/RK3399启动roslaunch pibot usb_camera.launch
或者直接浏览器访问192.168.12.1:8080选择相应的Topic即可

192.168.12.1为设备地址, 以具体设备为准

手机APP ROS2 暂时不支持

13. IMU的相关包使用

装有IMUPIBOT系列小车,底层提供IMU的数据采集,上层提供了IMU的互补滤波以及融合里程计和IMU的扩展的卡尔曼滤波包robot_pose_ekf
启动时只需相应的with_imulaunch文件, 具体参见pibot_命令

你可能感兴趣的:(PIBOT上位机开发(ROS1/ROS2))