Note: This tutorial assumes that you have completed the previous tutorials: ROS tutorials.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Simulating One Robot in Stage

Description: 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

Build stage

If necessary (e.g., if you're running from your own source tree), build the stage package:

rosmake stage

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

You may need to install the joystick drivers that teleop_base depends on:

sudo apt-get install ros-groovy-joystick-drivers

And (in fuerte and groovy, at least), patch according to http://answers.ros.org/question/40096/cannot-rosmake-teleop_base-getting-fatal-error-in-fuerte/

Then make sure that the resulting working copy is in your ROS_PACKAGE_PATH, and build it:

rosmake teleop_base

Run roscore

If necessary, bring up an instance of roscore:

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_ros stageros $(rospack find stage_ros)/world/willow-erratic.world

You should see a Stage window pop up that looks something like this:

alt text/

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.

alt text/

Click on the stage window and press R to see the perspective view.

alt text/

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:

rosmake teleop_base

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:

rosmake rviz

Now run rviz, using a configuration file in the stage package:

roscd stage
rosrun rviz rviz -d `rospack find stage_ros`/rviz/stage.rviz

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:

alt text/

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.


Wiki: stage/Tutorials/SimulatingOneRobot (last edited 2018-12-12 03:23:13 by JayEss)