智能机器人(21):Hokuyo激光雷达hokuyo_node方式

0. 激光雷达分类

a) – 单点激光测距仪
激光位移传感器,比较常见,价格低,只能测量到目标上特定点的距离,例如建筑装修行业的手持式测距仪。

b) – 2D激光雷达
如果将测距仪安装在一个可以旋转的平台上,然后旋转扫描一周,就变成了2D激光雷达(LiDAR).
时间换空间,牺牲速度,比如Hokuyo的10Hz。
2D激光雷达使用单束的点状的激光,进行扫描,因此只能采集一个面的距离信息。

c) – 3D激光雷达
如果要测量3D的数据,可用2种方式扩充:1)采用一个线状激光器,然后旋转; 2)使用前述的2D激光雷达扫描,同时在另一个轴进行旋转。
第一种方式是改变激光器输出模式,由原先的一个点,变成一条型光。扫描仪通过测量这束线型光在待测目标物体上的反射从而一次性获得一个扫描截面的数据。从而扫描速度很快,精度比较高。缺点是由于一点激光变成了一条线段,强度将随着距离大幅衰减,因此测距范围有限。
第二种方式优点是很容易用2D激光雷达增加旋转平台进行改造,在相同的激光功率下扫描距离更远。但是串行的级联的那个额外自由度的转轴误差可能较大,同时扫描速度低。

d)- 如果需要4D、5D、6D激光雷达
按同样办法增加维度处理…
不过 超过三维的空间很难理解。

1. 两个驱动

1.1 urg_node is new package
ROS provides special driver for all kinds of Hokyuo LRF, such as URG, for example urg driver is referred to as urg_node, we can install the urg_node as follows:
$ sudo apt-get install ros-indigo-urg-*

1.2 hokuyo_node is old driver
But, it is also better possible to use the hokuyo_node and, for this you need to install hokuyo_node as follows:
$ sudo apt-get install ros-indigo-hokuyo-node

2. 老的 hokuyo_node

Here we discuss the old driver hokuyo_node
Here we discussed the older Hokuyo_node, which used for most usb, rather than rj45 ip port.
Urg_node is newer than hokuyo_node,
Hokuyo_node will remain maintained for current users and PR2s.
And urg_node is BSD while hokuyo_node is LGPL.
$ sudo apt-get install ros-indigo-hokuyo-node

Then hokuyo_node Published Topics on /scan.

3. Powered On, and Pluggedin

4. Configure Hokuyo

Make sure hokuyo_node will be able to access the Hokuyo laser scanner. Check it’s file permissions, they should be read/write/execute for all.
$ ls -l /dev/ttyACM0
— crw-rw-XX- 1 root dialout 166, 0 2009-10-27 14:18 /dev/ttyACM0

If XX be rw: the laser is configured properly, if not:
$ sudo chmod a+rw /dev/ttyACM0

5. CLI tools

The Command-Line Tools getID program can be used to get information about a hokuyo laser scanner:
$ rosrun hokuyo_node getID /dev/ttyACM0
— Device at /dev/ttyACM0 has ID H0807228

or, friendly in a script way:
$ rosrun hokuyo_node getID /dev/ttyACM0 —
— H0807228

7. Setup udev rules

The getID program can be used to get the hardware ID of a Hokuyo device given its port.
Combined with udev, this allows a consistent device name to be given to each device, even if the order in which they are plugged in varies.

7.1 50-laser.rules
Create the file /etc/udev/rules.d/50-laser.rules, then edit and add the following to it:
KERNEL==”ttyACM[0-9]*”, MODE=”0777″
or,
$ sudo echo ‘KERNEL==”ttyACM[0-9]*”, MODE=”0777″‘ >> /etc/udev/rules.d/50-laser.rules

So, restart udev to take on the new rules:
$ sudo /etc/init.d/udev restart

or,

7.2 hokuyo.rules
a)
$ lsusb
— Bus 001 Device 006: ID 15d1:0000
ID后面的部分idVendor:idProduct, 确认idVendor和idProduct

b)创建串口别名
新建 /etc/udev/rules.d/hokuyo.rules文件,内容如下:(别名为hokuyo,实际名称为:/dev/hokuyo)
KERNEL==”ttyACM[0-9]*”, ACTION==”add”, ATTRS{idVendor}==”15d1″, MODE=”0666″, GROUP=”dialout”, SYMLINK+=”hokuyo”

c)
增加当前用户对串口的默认访问权限:
$ sudo usermod -a -G dialout 用户名

d)
使UDEV配置生效:(使串口的默认访问权限生效,需要重启机器)
$ sudo service udev reload
$ sudo service udev restart

总之, 上述*.rules文件,位于/etc/udev/rules.d/。

Give an example here, which with urg_node:
On the PR2 we use the following udev rule:
SUBSYSTEMS==”usb”, KERNEL==”ttyACM[0-9]*”, ACTION==”add”, ATTRS{idVendor}==”15d1″, ATTRS{idProduct}==”0000″, MODE=”666″, PROGRAM=”/opt/ros/indigo/lib/urg_node/getID /dev/%k q”, SYMLINK+=”sensors/hokuyo_%c”, GROUP=”dialout”
This udev rule sets up a device name that is based on the Hokuyo’s hardware ID.

Then:
The PR2 then has a symlink to that name that gets changed if the Hokuyo is replaced:
$ ls -l /etc/ros/sensors/base_hokuyo
— lrwxrwxrwx 1 root root 28 2010-01-12 15:53 /etc/ros/sensors/base_hokuyo -> /dev/sensors/hokuyo_H0902620
$ ls -l /dev/sensors/hokuyo_H0902620
— lrwxrwxrwx 1 root root 10 2010-04-12 12:34 /dev/sensors/hokuyo_H0902620 -> ../ttyACM1

10. 动态配置参数

Make sure that we have the correct configurations loaded on the parameter server.

10.1 命令行
If your Hokuyo is not at the default /dev/ttyACM0, you have to indicate where it is below:
$ rosparam set hokuyo_node/port /dev/ttyACM0

Below option will speed up the startup of the driver, but, will lead to less acurate timestamps:
$ rosparam set hokuyo_node/calibrate_time false <— ignore 10.2 CLI Start by getting the dependencies and compiling dynamic_reconfigure. $ rosdep install dynamic_reconfigure $ rosmake dynamic_reconfigure Reconfigure the hokuyo_node parameters , by calling dynamic_reconfigure $ rosrun dynamic_reconfigure dynparam set /

For example, if the node is named hokuyo_node and the parameter is min_ang:
$ rosrun dynamic_reconfigure dynparam set /hokuyo_node min_ang -1.0

10.3 launch file

Here using dynparam from a launch file.
You can use dynparam with the set_from_parameter command to set parameters of an already running node from a launch file.

For example to set the hokuyo scanning range

10.4 源代码

Using dynamic_reconfigure from code:

Python code:
import dynamic_reconfigure.client
rospy.init_node(‘myconfig_py’, anonymous=True)
client = dynamic_reconfigure.client.Client()
params = { ‘my_string_parameter’ : ‘value’, ‘my_int_parameter’ : 5 }
config = client.update_configuration(params)

C++ code:
system(“rosrun dynamic_reconfigure dynparam set_from_parameters camera_synchronizer_node narrow_stereo_trig_mode 3”);

10.5 图形接口 GUI

First getting the dependencies and compiling dynamic_reconfigure.
$ rosdep install dynamic_reconfigure
$ rosmake dynamic_reconfigure

run the reconfigure_gui:
$ rosrun rqt_reconfigure rqt_reconfigure

now editable parameters be available:

11. 测试雷达数据
Running hokuyo_node
$ rosrun hokuyo_node hokuyo_node
— [ INFO] 1256687975.743438000: Connected to device with ID: H0807344

Viewing data
$ rosrun rviz rviz -d `rospack find hokuyo_node`/hokuyo_test.vcg

============================
Now, Hokuyo LiDAR LRF test tutorial:
==========================================

13. 初级方法

不通过在机器人模型urdf里面添加雷达模型joint/link,而是经由一个通过静态tf变换实现

13.1 准备一个加载driver的启动文件 – hokuyo_laser.launch

在turtlebot_navigation包之下建立启动文件 – hokuyo_laser.launch :
$ roscd turtlebot_navigation
$ mkdir -p laser/driver
复制这个启动文件:
$ sudo cp ~/turtlebot_ws/src/hokuyo_node/hokuyo_test.launch laser/driver/hokuyo_laser.launch
修改hokuyo_laser.launch
$ vi turtlebot_navigation hokuyo_laser.launch
* 检查框架frame_id是否指定为laser* 查看port是否指定正确端口,使用别名
检查端口:,设置好别名,或直接端口/dev/ttyACM0
* 增加TF变幻:

修改为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.

完整代码:

13.2 准备一个建图的配置文件 – hokuyo_gmapping.launch.xml

在turtlebot_navigation包之下建立配置文件 – hokuyo_gmapping.launch.xml:
$ roscd turtlebot_navigation
$ touch launch/includes/gmapping/hokuyo_gmapping.launch.xml
$ vi launch/includes/gmapping/hokuyo_gmapping.launch.xml

13.3 准备建图的启动文件 hokuyo_gmapping_demo.launch,在其中加载hokuyo_laser.launch驱动

在turtlebot_navigation包建立hokuyo_gmapping_demo.launch文件用于启动gmapping :
$ roscd turtlebot_navigation
$ touch launch/hokuyo_gmapping_demo.launch
这个touch命令不常用,一般在使用make时,用来修改时间戳,或新建一个不存在的文件。如果创建一个新文件有很多种方法,vi cat echo, 而touch命令不仅可以创建新文件,而且可以修改文件的时间属性。

$ vi launch/hokuyo_gmapping_demo.launch

NOTE: 设置laser_type为hokuyo_laser.launch.

13.4 测试激光雷达的gmapping建图

启动turtlebot
$ roslaunch turtlebot_bringup minimal.launch
启动gmapping,用于构建地图
$ roslaunch turtlebot_navigation hokuyo_gmapping_demo.launch
启动键盘操作Turtlebot
$ roslaunch turtlebot_teleop keyboard_teleop.launch
启动rviz,实时查看建图情况
$ roslaunch turtlebot_rviz_launchers view_navigation.launch
保存地图
$ rosrun map_server map_saver -f /tmp/hokuyo_gmapping

13.5 利用地图进行AMCL

15. 中级方法

使用机器人模型urdf, 直接在其中添加laser

15.1 add LiDAR to the robot model

Edit ./urdf/turtlebot_library.urdf.xacro and add the following right above the tag
$ vi ./urdf/turtlebot_library.urdf.xacro

Above files will have your kinect’s virutal laser scan publishing on the same topic that other tutorials want to use, but here we would rather the laser data would come from the hokuyo laser.
This can be prevented by changing the topic that the Kinect laser publishes on with the following.

15.3 edit 3dsensor to change kinect date on /scan_topic rather than /scan.

$ vi turtlebot_bringup/launch/3dsensor.launch
edit 3dsensor.launch and look for the line that looks like this:

Remove it and replace it with:

15.5 edit minimal.launch to add laser node

Then edit minimal.launch, for we now need to add the hokuyo node to it.
At the bottom of the file right before , add the following:

This should bring up the hokuyo node when you launch it.

15.7 Test config

Bringup new config:
$ roslaunch turtlebot_bringup minimal.launch
— process[laser_driver-9]: started with pid [8288]

In another terminal, you can bring up the kinect sensor by running:
$ roslaunch turtlebot_bringup 3dsensor.launch

Check your results with rviz.
Now run rviz. You should now have a block that appears on your turtlebot.
Add two LaserScan visuilizations.
Subscribe one of them to the /kinect_scan topic and set it’s Color to “2; 255; 255”
Subscribe the other topic to /scan. Leave it’s Color “255; 255; 255”

17. 高级方法

建立激光雷达的dae模型,然后加入机器人模型。

We should make the changes in Turtlebot URDF, Two things:
one is description about Hokuyo that is in meshes folder,
and the other is the defining join with its location and its relation with parent frame (joint).

17.1 Make the hokuyo.dae file
We copy the hokuyo.dae file from the driver into /opt/ros/indigo/share/turtlebot_description/meshes folder.
It need administrative and write privileges to do it .
These meshes file contain all the properties that are needed to define hokuyo_node.
$ sudo cp …../hokuyo.dae /opt/ros/indigo/share/turtlebot_description/meshes

17.2 Create a new Hokuyo URDF file – hokuyo.urdf.xacro
Create and edit the Hokuyo URDF file – hokuyo.urdf.xacro
First go the folder /opt/ros/indigo/share/turtlebot_description/urdf/sensors ,
then , create and edit a new file named hokuyo.urdf.xacro

$ sudo vi /opt/ros/indigo/share/turtlebot_description/urdf/sensors/hokuyo.urdf.xacro

The code focuses on two things:
the one is description about Hokuyo that is in meshes folder. hokuyo.dae,
the other is the defining join with its location and its relation with parent frame (joint).
link is laser_joint and joint is hokuyo_joint.

For finding the location of hokuyo sensor, you may need to calculate the location that will be in meters and the representation is in x,y,z .

Turtlebot assumes 0 0 0 at it base center, like blow.

Above Collision do provide the opportunity to take a decision before going to collide.
In above code we have defined collisions for more explanation look into Adding Collisions.
It is necessary to set the parameters to avoid collisions.

Above code, first thing we did is specifying the joint name that is Hokuyo (but can be changed to any other thing), the type we select as fixed then we defined where the Hokuyo is attached with respect to origin,
Next thing the joints are defined by parent and child, You can also specify some fixed frame like map or base_footprint or make it link to default parent

17.3 Add LiDAR to robot
Add Hokuyo URDF description – hokuyo.urdf.xacro to Turtlebot URDF description – turtlebot_library.urdf.xacro

In order to be Hokuyo a part of URDF description, we need to add Hokuyo LRF description to the Turtlebot URDF so that it can be visualized in rivz and other simulators.
So, edit /opt/ros/indigo/share/turtlebot_description/urdf/turtlebot_library.urdf.xacro file and add some lines:

$ sudo vi /opt/ros/indigo/share/turtlebot_description/urdf/turtlebot_library.urdf.xacro
add:

Above will call the hokuyo description created in urdf.

17.4 minimal.launch

In order to launch the description , it is just required to launch mininal.launch and it will work.
NOTE:
In order to see a hokuyo sensor in rviz we need to add its definition in gazebo, but not covered here,
but can be borrowed from Building Visual Robot:
http://wiki.ros.org/urdf/Tutorials/Building%20a%20Visual%20Robot%20Model%20with%20URDF%20from%20Scratch

17.5 Create Launch File for Hokuyo Node driver

Its is better to create a Hokuyo Launch file in order to launch the Hokuyo node.
It will also allow Hokuyo node dynamic re-configuration of Hokuyo node.

$ vi hokuyo.launch

正常做法是把这个驱动图的launch文件在minimal.launch中包含, 但是单独运行也没问题。

17.6 Use SLAM With Hokuyo LIDAR Sensor

利用hokuyo laser创建地图.
In order to use Hokuyo for SLAM as described in tutorial Building SLAM, following below:

地图:
a)
$ roslaunch turtlebot_bringup minimal.launch
b) run the Hokuyo node
$ roslaunch turtlebot_test_launch hokuyo.launch

c) Launch the gmapping for map building
$ roslaunch turtlebot_navigation gmapping_demo.launch

d) View the map at workstation using rviz
$ roslaunch turtlebot_rviz_launchers view_navigation.launch
e)
$ roslaunch turtlebot_teleop keyboard_teleop.launch
f) 地图构建完成之后保存 :
$ rosrun map_server map_saver -f /tmp/my_map

导航:
a)
$ roslaunch turtlebot_navigation amcl_demo.launch map_file:=/tmp/my_map.ymal
b)
$ roslaunch turtlebot_rviz_launchers view_navigation.launch
c) 2D Pose Estimate
d) 2D Nav Goal

Available for UTM-30LX,UBG-04LX-F01, URG-04LX, URG-04LX-UG01, UTM-04G…
REF:
http://www.iroboapp.org/index.php?title=Adding_Hokuyo_Laser_Range_Finder_to_Turtlebot
http://www.voidcn.com/blog/jie_sky_2015/article/p-5698136.html
http://wiki.ros.org/turtlebot/Tutorials/hydro/Adding%20a%20Hokuyo%20laser%20to%20your%20Turtlebot
http://www.ncnynl.com/archives/201611/1097.html
http://amanbreakingthings.blogspot.hk/2014/11/adding-hokuyo-lidar-to-turtlebot-in-ros.html
http://www.iheartrobotics.com/2012/03/in-stock-even-more-turtlebot.html
http://blog.sina.com.cn/s/blog_c5a00db10102wg07.html

0 回复

发表评论

Want to join the discussion?
Feel free to contribute!

发表评论