|Note: This tutorial assumes that you have completed the previous tutorials: ROS tutorials.|
|It is appreciated that problems/questions regarding this tutorial are asked on answers.ros.org. Don't forget to include in your question the link to this page, versions of your OS & ROS, and also add appropriate tags.|
Simulating One Robot in StageDescription: This tutorial shows you how to use the Stage simulator to simulate a single, Erratic-like robot, roaming an environment that looks a lot like the Willow Garage building.
Tutorial Level: BEGINNER
If necessary (e.g., if you're running from your own source tree), build the stage package:
For the keyboard teleoperation part of this tutorial, you also need to get the teleop_base package, which has not, at the time of writing, been released. Check it out from SVN:
svn co https://code.ros.org/svn/wg-ros-pkg/branches/trunk_cturtle/sandbox/teleop_base teleop_base
Then make sure that the resulting working copy is in your ROS_PACKAGE_PATH, and build it:
If necessary, bring up an instance of roscore:
Run stageros with an existing world file
The stage package ships with some example world files, including one that puts an Erratic-like robot in a Willow Garage-like environment. To run it:
rosrun stage stageros `rospack find stage`/world/willow-erratic.world
You should see a Stage window pop up that looks something like this:
Browsing the stage window should show up 2 little squares, a red square which is a red box and a blue square which is the erratic robot.
Click on the stage window and press R to see the perspective view.
Drive the robot around
You have a simulated robot; let's make it move. An easy way to do this is keyboard-based teleoperation. If necessary, build the teleop_base package:
Now run teleop_base_keyboard:
rosrun teleop_base teleop_base_keyboard base_controller/command:=cmd_vel
You should see console output that gives you the key-to-control mapping, something like this:
Reading from keyboard --------------------------- Moving around: u i o j k l m , . q/z : increase/decrease max speeds by 10% w/x : increase/decrease only linear speed by 10% e/c : increase/decrease only angular speed by 10% anything else : stop ---------------------------
Hold down any of those keys to drive the robot. E.g., to drive forward, hold down the i key. When you do this, you should see the robot move in the Stage window. Note that you need focus in the window where you ran teleop_base_keyboard (e.g., you may need to click in that window).
Visualize sensor data
The simulation isn't just for driving; it's also producing sensor data, some of which can be easily visualized. Let's start with laser data. If necessary, build rviz:
roscd stage rosrun rviz rviz -d `rospack find stage`/rviz/stage.vcg
You should see an rviz window pop up. Now drive the robot around some more. You should see a kind of "map" start to accumulate in rviz, looking something like this:
Note that you're just accumulating Stage's perfect laser scans with perfect odometry. Real robots and real lasers exhibit noise that Stage isn't simulating (Stage can simulate noisy odometry; see the Stage manual for details). Mapping with noisy sensors requires a SLAM system; check the gmapping tutorials for more on that topic.
By the way, the "map" that you've built will disappear over time, because rviz can only buffer a finite number of laser scans.