目前用在ROS Kinetic上的stage版本为4.1 官方教程http://rtv.github.io/Stage/modules.html
用户可以用stage或者gazebo来创建地图和机器人,传感器模型来进行仿真,并与自己的SLAM模型进行通讯达到虚拟仿真的目的。
单独安装和卸载stage命令(stage包含在ROS完整版安装包中无需单独安装):
sudo apt-get remove ros-kinetic-stage
sudo apt-get install ros-kinetic-stage
当然因为stage是一个二维模拟器,相比来说运行资源要求不高,仿真速度快。
ROS上关于stage的教程http://wiki.ros.org/stage/Tutorials/IntroductiontoStageControllers因为已经相对过时,并不适用于当前的版本。
下面开始介绍stage地图文件的基本组成:
首先在自己的~/catkin_ws/src下创建ROS文件包,catkin_create_pkg stage_controllers,暂时不添加依赖包
在~/catkin_ws/src/stage_controllers/下创建world文件夹以及2个文件map.inc test.world,具体内容如下:
map.inc
define floorplan model
(
# sombre, sensible, artistic
color "gray30"
# most maps will need a bounding box
boundary 1
gui_nose 1
gui_grid 0
gui_outline 0
gui_move 0
gripper_return 1
fiducial_return 1
ranger_return 1
)
这里创建名为floorplan的模型 定义其中定义boundary 1表示地图的周围形成封闭边界;gui_nose表示是否显示模型的正方向;gui_grid是否显示网格;gui_move是否允许拖拽移动地图,下面表示是否允许传感器探测到,比如ranger_return表示完全能够看到,并设置intensity为1,如果为负值表示无法被探测。
test.world
include "map.inc"
resolution 0.02
interval_sim 20 # simulation timestep in milliseconds
# configure the GUI window
window
(
size [ 800.000 800.000 ] # in pixels
scale 25 # pixels per meter
center [ 0.0 0.0 ]
rotate [ 0.0 0.0 ]
show_data 1# 1=on 0=off
)
# load an environment bitmap
floorplan
(
name "roomba-stage"
bitmap "bitmaps/roomba-stage.png"
size [ 20.0 15.0 1.0 ]
pose [ 0.0 0.0 0.0 0.0]
)
define laser ranger
(
# generic model properties
color "blue"
size [ 0.156 0.155 0.19 ]
sensor
(
range [0.0 8.0]
fov 360.0
samples 360
)
)
#define laser2 ranger
#(
# generic model properties
# color "blue"
# size [ 0.156 0.155 0.19 ]
#sensor
#(
# range [0.0 8.0]
## fov 360.0
# samples 360
# )
#)
define robot position
(
size [ 0.33 0.33 0.2 ]
#pose [ 0.0 0.0 0.0 0.0 ]
localization "odom"
localization_origin [ 0.0 0.0 0.0 0.0 ]
# odometry error model parameters,
# only used if localization is set to "odom"
odom_error [ 0.0 0.0 0.0 0.0 ]
color "gray50"
origin [ 0.0 0.0 0.0 0.0 ]
#positonal things
drive "diff"
gui_nose 1
laser(
pose [ 0.0 0.0 0.5 0.0 ]
ctrl "lasernoise"
alwayson 1
)
#laser2(
#pose [ 0.0 0.0 0.5 0.0 ]
#ctrl "lasernoise"
#alwayson 1
#)
#ctrl "wander" #uncomment this when $stage test.world
)
robot
(
name "roomba"
pose [-8.0 6.0 0.0 0.0]
#color "green"
)
这里引用了map.inc文件,在同一个路径下
window下定义了窗口的一些信息,大小比例等;
创建了floorplan的实例,名为roomba-stage
这里只是简单定义了一个机器人和一个激光传感器,同样是先创建模型再创建实例。这样便于快速的创建N个重复的模型。
size(0.33 0.33 1)表示模型实际大小。
show_data 1#表示雷达数据可见
主要在机器人模型中创建了一个lasers()。
odom_error [x y z theta]
parameters for the odometry error model used when specifying localization "odom". Each value is the maximum proportion of error in intergrating x, y, and theta velocities to compute odometric position estimate. For each axis, if the the value specified here is E, the actual proportion is chosen at startup at random in the range -E/2 to +E/2. Note that due to rounding errors, setting these values to zero does NOT give you perfect localization - for that you need to choose localization "gps".
注意这里,如果假设模型位置误差为0,则应该选择gps,而不是odom
localization "gps"
编辑完成后就可以在此world文件夹中打开terminal
方法1:启动stage地图和模型
rosrun stage_ros stageros test.world
查看创建的地图。
键盘上R 可以切换视角 P 暂停
可以看到雷达扫描的区域,并且仿真速度很快。
当然也可以打开rviz来查看点云数据!
可以安装键盘控制
sudo apt-get install ros-kinetic-teleop-twist-keyboard
并启动
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
用键盘就可以控制图中的机器人移动
可以将点云数据通过gmapping来建图,通过rviz查看地图
rosrun gmapping slam_gmapping scan:=base_scan
方法2:添加第2个ranger,并且用ctrl "wander" 来进行自主控制,缺点是无法与ros进行通讯
stage test.world
注释: Ctrl “lasernoise”用来给laser添加噪声,比例是,方差0.05
可查看路径下是否有对应文件:/opt/ros/kinetic/lib/Stage-4.1/lasernoise.so以及wander.so