turtlebot移动机器人(21):模拟器的定位导航

在hydro版本的ROS,对于turtlebot机器人,只支持stage模拟器,栈和包是turtlebot_gazebo。

0、准备

0.1、如果需要,安装:
$ sudo apt-get install ros-hydro-turtlebot-simulator
0.2、如果需要,更新:
$ rosdep update
0.3、如果需要安装键盘控制
$ sudo apt-get install ros-hydro-turtlebot-apps ros-hydro-turtlebot-rviz-launchers

一、仿真:gazebo模拟world,rviz可视化。

1.1、启动gazebo模拟器下的机器人,和空的world。
$ roslaunch turtlebot_gazebo turtlebot_empty_world.launch
1.2、启动键盘控制终端,这样可以通过键盘控制机器人动作。
$ roslaunch turtlebot_teleop keyboard_teleop.launch
1.3、启动可视化窗口,这样可以显示机器人所探测的世界。
$ roslaunch turtlebot_rviz_launchers view_robot.launch
1.4.1、可以在gazebo里面放置一些障碍物,例如圆柱垃圾桶和矩形桌子

1.4.2、通过rviz,可以显示点云图

二、建图导航:进一步的建图和导航功能。

1.1、启动gazebo模拟器下的机器人和虚拟world
$ roslaunch turtlebot_gazebo turtlebot_playground.launch
1.2、启动建图
$ roslaunch turtlebot_gazebo gmapping_demo.launch
1.3、通过可视化查看建图过程
$ roslaunch turtlebot_rviz_launchers view_navigation.launch
1.4、启动键盘控制终端移动,直到地图满意为止
$ roslaunch turtlebot_teleop keyboard_teleop.launch
1.5、保存地图
$ rosrun map_server map_saver -f ~/demomap
1.6、使用地图导航:关闭所有进程,重复以上所有步骤,除了建图这一步。
$ roslaunch turtlebot_gazebo amcl_demo.launch map_file:=~/demomap.yaml

  • 1、启动机器人

物理环境就是把真是机器人bring-up,这里在3d版模拟器gazebo中启动机器人turtlebot:
$ roslaunch turtlebot_gazebo turtlebot_world.launch
先启动这个gazeb就相当于把硬件启动了,传感器也都启动了,激光器/scan和里程计/odom都有数据了。
如下图这是个简单的宾馆场景:

问题一、出现Error [SDF.cc:788] Missing element description for [pointCloudCutoffMax]
解释:没找到答案。好像不会影响使用。
问题二、出现modeldatabase:unable to get model name
解释一:这是gazebo2.2太老,需要更新:
$ sudo sh -c ‘echo “deb http://packages.osrfoundation.org/gazebo/ubuntu trusty main” > /etc/apt/sources.list.d/gazebo-latest.list’
$ wget http://packages.osrfoundation.org/gazebo.key -O – | sudo apt-key add –
$ wget http://gazebosim.org/models/dumpster/model.tar.gz
解释二:这是因为它到http://gazebosim.org/models去采集组建但某种原因出现了问题,所以不如直接全部下载,几个小时。
$ cd ~/.gazebo
$ wget -r -R “index.html*” http://models.gazebosim.org/
把下载得到的都复制到~/.gazebo/models文件夹。
问题三、启动gazebo出错不能启动
解释:这通常是非nvida显卡引起的,没有办法,多启动几次总会好。

  • 2、控制机器人移动

如果通过键盘
$ roslaunch turtlebot_teleop keyboard_teleop.launch –screen
如果通过罗技手柄
$ roslaunch turtlebot_teleop logitech.launch –screen

3、查看机器人

$ roslaunch turtlebot_rviz_launchers view_robot.launch
很好,机器人看起来不错。

4、创建地图

$ roslaunch turtlebot_gazebo gmapping_demo.launch
启动gmapping,就可以利用采集所得到的传感器数据,进行地图绘制,/map也就有数据了。
这个过程是静寂的。
说明一、这个terminal停留在Registering First Scan不动,这是因为机器人没有移动的缘故。
此时可以尝试调试工具:
$ rosrun rqt_graph rqt_graph
WARNING: topic [/base_scan] does not appear to be published yet

5、显示地图

Gazebo模拟了现实世界,RViz可视化的感知周围事物。所以运行rviz,显示相应的制图信息。
$ roslaunch turtlebot_rviz_launchers view_navigation.launch –screen
此时可以尝试调试工具:
$ rostopic echo /base_scan
$ rostopic echo /odom
$ rostopic echo /map | grep frame_id
$ roswtf
$ Loaded plugin tf.tfwtf No package or stack in context
根据激光扫描器安装与否,有时会把scan重定向到base_scan,这样:
$ rosrun gmapping slam_gmapping scan:=base_scan

6、移动扫描

此时控制turtle平面走动,并转圈扫描,不断丰富地图,如下图:

  • 7、保存地图

如果满意,把地图保存用于后续的导航:
$ rosrun map_server map_saver -f dehaoZ_map

8、建图结束

地图构建完成后,关闭以上所有进程。看机器人如何自主导航。

启动硬件模拟器

$ roslaunch turtlebot_gazebo turtlebot_world.launch

键盘或手柄的teleop控制可选

$ roslaunch turtlebot_teleop keyboard_teleop.launch –screen

启动导航

$ roslaunch turtlebot_gazebo amcl_demo.launch map_file:=/home/dehaoz/dehaoZ_map.yaml
这个过程也是静寂的。

可视化查看它的导航过程

$ roslaunch turtlebot_rviz_launchers view_navigation.launch

随便点击,作为目标地。规划路径及行走过程如下图:

amcl的terminal里也会提示到达目的地:

9、琐碎的事情

问题一、
rviz出错:Map “No transform from [map] to [base_link]”
解释:
You will need a transform from the /map frame to /base_link. However, there only needs to be a path between /map and /base_link, not a direct transform. Usually, the transform setup looks something like /map->/odom->/base_link.
These transforms are usually provided by a localization node such as amcl or a SLAM node such as gmapping.

问题二、
rviz出错:global status error Fixed Frame [map] does not exist
解释一、
I may not be considering this correctly, but it may be as simple as changing your “fixed frame” under “.Global Options” to “/”, “/world”, or some
fixed frame that you do have a transform for. “/base_link”!!!!
解释二、
1-这个fix frame可以解决I don’t even know how to change it. I tried your solution, it fixes “Global Status” but there still is RobotModel error:
Screenshot rosrun tf static_transform_publisher 0.0 0.0 0.0 0.0 0.0 0.0 map my_frame 100
2-You don’t have a localization as e.g. amcl running. Thus, the transformation map->base_link (or whatever you have for your robots link) does not
exist.
解释三、
You need to publish a map frame. If I’m correct, your problem is that AMCL is looking for the /map frame when it loads your static map from the map_server. In order to resolve this problem, you must either set the frame_id of your map_server to /odom or publish the /map frame as a parent
frame to /odom.

问题三、
amcl出现Extrapolation Error looking up robot pose: Lookup would require extrapolation into the past. Requested time 560.090000000 but the earliest
data is at time 620.530000000, when looking up transform from frame [base_footprint] to frame [map]
解释一、
The error is telling you that your asking for a transform from a time before which you have tf data。Most tf datasources report data in monotonic
increasing order which means that no matter long you wait you will not receive older data.。You will either need to initialize the transform listener
earlier and allow the buffer to fill up, or pass a few of these errors on startup. It’s a common race condition whether the data or tf data arrives
first.。try increasing ros::Duration(0.2) upto maximum of 10 seconds。就是说要增加延时,或者采用阻塞模式:
try{
ros::Time now = ros::Time::now();
listener.waitForTransform(“/turtle2”, “/turtle1”,now, ros::Duration(3.0));
listener.lookupTransform(“/turtle2”, “/turtle1”, now, transform);
//Note: Using ros::Time::now() is for demo, usually would be timestamp of data wishing to be transformed.
这里面waitForTransform()将会阻塞一直到坐标转换可用为止或者超时为止。
诊断二、
warn:could not get robot pose
(1)先看看大致结构。
$ rosrun rqt_graph rqt_graph
(2)再看看tf信息
$ rosrun tf tf_monitor
(3)可能会有
published by unknown_publisher
(4)看看amcl
$ rostopic info amcl_pose
(5)可以尝试
$ rosrun tf tf_echo odom map
(6)尝试减小地图尺寸
reducing size of local cost map to original size of 6×6 @ 0.5 resolution, the extrapolatoin error went away.
(7)注意CPU负载
$ gnome-system-monitor
To make sure the CPU didn’t stall, I essentially lowered the local/global maps and move_base controller update frequency to a point where the
navigation wouldn’t work well at all. For me, the map updating/publishing rates were down to 3Hz and 2Hz, respectively. The move_base frequency was
also down to 3-4Hz. On top of this, I was running rviz on the same laptop on an integrated graphics card.
1-The local planar detected an obstacle. As it moves around it, the obstacle was dragged across the local map, enclosing the robot an completely
unmovable space.
2-This lead to the robot getting lost, a lot. I would see it moving to the goal designated, but when it gets there, it would spin to get the correct
orientation. While this happens, the laser scan would slowly move out of place of the global map.Here is a couple general rule of thumb if you want
to run the navstack:Don’t run the map/controller frequency lower than the ros nav stack guide.I upgraded to a laptop with an i7-4th gen (~2.2Ghz),
and an nvidia graphics card. I run the map publish rates and controller publish rates to twice the ros tutorial’s values. It can run at higher
velocities and smoother motions!Naturally, those errors went away after the upgrade and the CPU stopped stalling/running so slow.
解释三、
是真实导航但可能使用了模拟位置:
The problem is your fake_localization. It publishes map->odom, which is now done by the real localization from the MultiMapper, So you have to remove
this fake_localization.
Somewhere in your launch file there is a node named “fake_lokalization” (I guess it is just a static_transform_publisher). Just remove this one when
adding the mapper to your system.
Looking at your RVIZ-screenshot it seems a bit like the robot is not moving the way it thinks it does. (The map patches are overlayed incorrectly.)
Some ideas only:
Check if the odometry published by Gazebo is correct. (Visualize TF in RVIZ)
Look at the Operators costmap in RVIZ (type “map”, topic “/Operator/local_costmap”)
Try to run tutorial 1 with your setup first and see if it works correctly. Then add Mapper and Navigator step by step.

0 回复

发表评论

Want to join the discussion?
Feel free to contribute!

发表评论