yuzhenning / ROS_turtlebot2

This is a file record Ubuntu based ROS and Turtlebot2 control system
0 stars 0 forks source link

18 RPLidar A1/2 node on Turtlebot2 ROS #18

Open yuzhenning opened 4 years ago

yuzhenning commented 4 years ago

This issue is recording my research about running rplidar, generating SLAM mapping in Turtlebot2 with Jetson TX1/2 or nano. Before work, we need following environment finished firstly.(not limited)

  1. Ubuntu 16.04 Xenial Xerus (Unique operation system support bothTurtlebot2 and 3 in official )
  2. ROS - Kinetic (ros-kinetic-desktop-full) and workspace (catkin_ws)
  3. Turtlebot2 package (ros-kinetic-turtlebot. etc )
  4. RPlidar A2 laser sensor
yuzhenning commented 4 years ago

Official reference website:

ROS wiki: http://wiki.ros.org/rplidar RPLidar: https://github.com/Slamtec/rplidar_ros RPlidar HomePage: http://www.slamtec.com/en/Lidar rplidar SDK: https://github.com/Slamtec/rplidar_sdk rplidar Tutorial: https://github.com/robopeak/rplidar_ros/wiki ROS rplidar SDK Deeply analysis https://blog.csdn.net/qq_16775293/article/details/78127451 TIPS sudo 出现unable to resolve host 解决方法 Ubuntu环境, 假设这台机器名字叫abc(机器的hostname), 每次执行sudo 就出现这个警告讯息: sudo: unable to resolve host abc 虽然sudo 还是可以正常执行, 但是警告讯息每次都出来,而这只是机器在反解上的问题, 所以就直接从/etc/hosts 设定, 让abc(hostname) 可以解回127.0.0.1 的IP 即可. sudo vim /etc/hosts replace hostname as new one (tegra-ubuntu --> ubuntutx1)

yuzhenning commented 4 years ago

Reading rplidar ROS node

https://answers.ros.org/question/199561/rplidar-driver-installation-problem-on-ubuntu/ rplidar driver installation problem on Ubuntu I have attempted to get RPLIDAR to talk to Linuxmint 17 system and an Ubuntu 14.04 system. And when I run: $ roslaunch rplidar_ros view_rplidar.launch --> RVIZ software running Error, cannot bind to the specified serial port /dev/ttyUSB0. And the GUI warns: No tf data. Actual error: Fixed Frame [laser] does not exist I believe the problem is that the USB to UART driver is installed with root permissions because I get the same error when I run the rplidar example program: $ ./ultra_simple /dev/ttyUSB0 Error, cannot bind to the specified serial port /dev/ttyUSB0. But it runs correctly when I run the above command under root:

yuzhenning commented 4 years ago

RPLidar running on Turtlebot2

ref : https://www.ncnynl.com/archives/201611/1095.html

Step1:Basic 准备工作

  1. Make direction as turtlebot_ws: $ mkdir -p ~/turtlebot_ws/src $ cd ~/turtlebot_ws/src
  2. 激光雷达rplidar一代驱动 $ git clone https://github.com/ncnynl/rplidar_ros.git
  3. Turtlebot建图依赖包 $ git clone https://github.com/turtlebot/turtlebot_apps
  4. 编译 $ cd ~/turtlebot_ws $ catkin_make
  5. 添加环境变量,在~/.bashrc最后添加一行: $ source ~/turtlebot_ws/devel/setup.bash
  6. 刷新配置
    $ source ~/.bashrc
    or
    $ rospack profile
yuzhenning commented 4 years ago

Step2: Creat RPLidar serial port surf-name 创建激光雷达(Rplidar)的串口别名

  1. 确认idVendor和idProduct,ID后面的部分idVendor:idProduct
    $ lsusb
    Display: Bus 001 Device 006: ID 10c4:ea60
  2. 新建 /etc/udev/rules.d/rplidar.rules文件,内容如下:(别名为rplidar,实际名称为:/dev/rplidar) KERNEL=="ttyUSB*", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE:="0666",GROUP:="dialout", SYMLINK+="rplidar"
  3. 这里,**ttyUSB*** 为rplidar的串口地址,

经常遇到以下问题 cannot bind specified port /dev/ttyUSB0 Solution如下: Upgrade user's right to serial port 增加当前用户对串口的默认访问权限: Add your userid to the 'dialout' group. The dialout group allows access to the serial ports: $ sudo usermod -a -G dialout 用户名(nvidia) Restart and reload udev service: (使串口的默认访问权限生效,需要重启机器)

$ sudo service udev reload
$ sudo service udev restart
or:
$ sudo udevadm trigger

刷新配置 $ source ~/.bashrc$ rospack profile

检查串口权限: $ ls -l /dev | grep ttyUSB 设置端口权限666 $ sudo chmod 666 /dev/ttyUSB0

yuzhenning commented 4 years ago

Step3: Make RPLidar driver document. 制作雷达驱动启动文件

Overview Direction : $~/turtlebot_ws/src/turtlebot_apps/turtlebot_navigation Copy rplidar.launch to rplidar_laser.launch,and add TF position definition

# locate to turtlebot_navigation
$ roscd turtlebot_navigation

# make document laser/driver 
$ mkdir -p laser/driver

# copy rplidar.launch file (under rplidar_ros) to rplidar_laser.launch (under rplidar_navigation) 
$ sudo cp ~/turtlebot_ws/src/rplidar_ros/launch/rplidar.launch laser/driver/rplidar_laser.launch

1. locate to direction ~/turtlebot_ws/src/turtlebot_apps/turtlebot_navigation/

2. Edit launch file $ rosed turtlebot_navigation rplidar_laser.launch+

Please _check frameid figure to laser or not. <param name="frame_id" type="string" value="laser"/>

Check serial_port figure to right port ,using surname <param name="serial_port" type="string" value="/dev/rplidar"/> or direct port name: /dev/ttyUSB0

Add TF: <node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.18 0 0.0 0.0 base_link laser 100"/>

修改为args="0.0 0.0 0.18 0 0.0 0.0 为自己的实际安装位置。详情查看,static_transform_publisher部分 static_transform_publisher x y z qx qy qz qw frame_id child_frame_id period_in_ms 这里我假设底盘的中心点为0,雷达放在机器人托盘中心位置,X为0,高度为18CM,Z为0.18m TF的单位使用米的,测量单位是CM

Whole code as : 完整代码如下:

<launch>
  <node name="rplidarNode"          pkg="rplidar_ros"  type="rplidarNode" output="screen">
  <param name="serial_port"         type="string" value="/dev/ttyUSB0"/>  
  <param name="serial_baudrate"     type="int"    value="115200"/>
  <param name="frame_id"            type="string" value="laser"/>
  <param name="inverted"            type="bool"   value="false"/>
  <param name="angle_compensate"    type="bool"   value="true"/>
  </node>

  <node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.18 0 0.0 0.0 base_link laser 100"/>
</launch>
yuzhenning commented 4 years ago

Step4: Check turtlebot_navigation package

Added rplidar_gmapping_demo.launch document, for running gmapping.

$ roscd  turtlebot_navigation
$ touch  launch/rplidar_gmapping_demo.launch
$ rosed  launch/rplidar_gmapping_demo.launch

gedit rplidar_gmapping_demo.launch file, type in following codes:

<launch>

  <!-- Define laser type-->
  <arg name="laser_type" default="rplidar" />

  <!-- laser driver -->
  <include file="$(find turtlebot_navigation)/laser/driver/$(arg laser_type)_laser.launch" />

  <!-- Gmapping -->
  <arg name="custom_gmapping_launch_file" default="$(find turtlebot_navigation)/launch/includes/gmapping/$(arg laser_type)_gmapping.launch.xml"/>
  <include file="$(arg custom_gmapping_launch_file)"/>

  <!-- Move base -->
  <include file="$(find turtlebot_navigation)/launch/includes/move_base.launch.xml"/>

</launch>

Set laser_type as rplidar. Added: rplidar_gmapping.launch.xml file for running gmapping

$ roscd  turtlebot_navigation
$ touch  launch/includes/gmapping/rplidar_gmapping.launch.xml 
$ rosed  launch/includes/gmapping/rplidar_gmapping.launch.xml

Type in following code:

<launch>
  <arg name="scan_topic"  default="scan" />
  <arg name="base_frame"  default="base_footprint"/>
  <arg name="odom_frame"  default="odom"/>

  <node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen">
    <param name="base_frame" value="$(arg base_frame)"/>
    <param name="odom_frame" value="$(arg odom_frame)"/>
    <param name="map_update_interval" value="0.01"/>
    <param name="maxUrange" value="4.0"/>
    <param name="maxRange" value="5.0"/>
    <param name="sigma" value="0.05"/>
    <param name="kernelSize" value="3"/>
    <param name="lstep" value="0.05"/>
    <param name="astep" value="0.05"/>
    <param name="iterations" value="5"/>
    <param name="lsigma" value="0.075"/>
    <param name="ogain" value="3.0"/>
    <param name="lskip" value="0"/>
    <param name="minimumScore" value="30"/>
    <param name="srr" value="0.01"/>
    <param name="srt" value="0.02"/>
    <param name="str" value="0.01"/>
    <param name="stt" value="0.02"/>
    <param name="linearUpdate" value="0.05"/>
    <param name="angularUpdate" value="0.0436"/>
    <param name="temporalUpdate" value="-1.0"/>
    <param name="resampleThreshold" value="0.5"/>
    <param name="particles" value="8"/>
  <!--
    <param name="xmin" value="-50.0"/>
    <param name="ymin" value="-50.0"/>
    <param name="xmax" value="50.0"/>
    <param name="ymax" value="50.0"/>
  make the starting size small for the benefit of the Android client's memory...
  -->
    <param name="xmin" value="-1.0"/>
    <param name="ymin" value="-1.0"/>
    <param name="xmax" value="1.0"/>
    <param name="ymax" value="1.0"/>

    <param name="delta" value="0.05"/>
    <param name="llsamplerange" value="0.01"/>
    <param name="llsamplestep" value="0.01"/>
    <param name="lasamplerange" value="0.005"/>
    <param name="lasamplestep" value="0.005"/>
    <remap from="scan" to="$(arg scan_topic)"/>
  </node>
</launch>
yuzhenning commented 4 years ago

Step5: Testing rplidar-gmapping Performance on Turtlebot

  1. Robot terminal,open roscore
    $ roscore
  2. Robot terminal,start turtlebot
    $ roslaunch turtlebot_bringup minimal.launch
  3. Robot terminal,start gmapping, for SLAM
    $ roslaunch turtlebot_navigation rplidar_gmapping_demo.launch
  4. Host PC or Robot terminal,start keyboard control Turtlebot
    $ roslaunch turtlebot_teleop keyboard_teleop.launch 
  5. Host PC or Robot terminal,start rviz,check gmapping performance
    $ roslaunch turtlebot_rviz_launchers view_navigation.launch
yuzhenning commented 4 years ago

构建地图结束保存地图 Save the map to file: /tmp/my_map $ rosrun map_server map_saver -f /tmp/my_map

yuzhenning commented 4 years ago

利用地图进行AMCL

yuzhenning commented 4 years ago

ROS_PACKAGE LIST CHECK

系统环境变量使用 vim /etc/profile 编辑ROS_PACKAGE_PATH那项 COMMAND: $ env export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH: pwd `

单独对软件包编译: catkin_make --pkg rplidar_ros

yuzhenning commented 4 years ago

Test USB driver

Check the authority of rplidar's serial-port :

ls -l /dev |grep ttyUSB

Add the authority of write: (such as /dev/ttyUSB0) sudo chmod 666 /dev/ttyUSB0 There're two ways to run rplidar ros package I. Run rplidar node and view in the rviz roslaunch rplidar_ros view_rplidar.launch You should see rplidar's scan result in the rviz. II. Run rplidar node and view using test application

roslaunch rplidar_ros rplidar.launch
rosrun rplidar_ros rplidarNodeClient

You should see rplidar's scan result in the console 因为挂载多个USB设备,需要检查雷达使用的端口号 dmesg | grep ttyUSB* You are able to find all information about node using below command: udevadm info -a -p /sys/bus/usb-serial/devices/ttyUSB0/ Display usb device under ttyUSB0

udevadm info -a -n /dev/ttyUSB0 | grep '{serial}' | head -n1 

*Check all ttyUSB named files**

find / -name "ttyUSB*"

查看系统最后的运行日志,会提示相关文件没有打开 dmesg | tail

yuzhenning commented 4 years ago

Official rplidar ros and robopeak

ref web: http://wiki.ros.org/rplidar https://www.ncnynl.com/archives/201611/1100.html 测试 TEST

  1. running rplidar and check performance in rviz
    $ roslaunch rplidar_ros view_rplidar.launch
  2. running rplidar and test
    # terminal 1
    $ roslaunch rplidar_ros rplidar.launch
    # terminal 2
    $ rosrun rplidar_ros rplidarNodeClient