ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Help programming a simulation in stageros.

asked 2011-10-13 01:17:06 -0500

jlo gravatar image

Hi, I want to program a simulation with stage, where I'd like a robot to move forward till he detects an obstacle, and then, turn until he can continue forward. For that I know I have to subscribe to scan topic and to publish to cmd_vel to make the robot move (thanks, Martin Günther!). But I don't know how to interact with stage itself. I think I could manage to write the subscribe and publish algorithms with what I learnt from the publisher's and subscriber's tutorials, but once that is done, I'm at a loss as to how execute the simulation. I read some of this link, but I'm still really lost. Any suggestions?


edit retag flag offensive close merge delete

5 Answers

Sort by » oldest newest most voted

answered 2011-10-13 03:52:27 -0500

updated 2011-10-13 03:53:50 -0500

You will need a so-called world file which contains a description of the virtual environment and the characteristics of your simulated robot. The stage package contains a suitable demo world file. You must start Stage with the world file as argument, e.g.

rosrun stage stageros `rospack find stage`/world/

Now you can receive on the /base_scan topic and publish to the /cmd_vel topic with your own program.

If you want to create your own world file, you need a position and laser model for your robot and a suitable floor plan (usually a bitmap) that encodes the obstacles. For the exact syntax, you can read the manual or look at the existing world files.

edit flag offensive delete link more


@Röhling : Nice command for stage, I was using ./stageros from the stage executables - but this is much better ! :-)
Arkapravo gravatar image Arkapravo  ( 2011-10-29 20:07:20 -0500 )edit

Hi, I stage is not running on my machine , I am using Ubuntu 12.04 and Hydro, when I entered above command it shows this error:

[rosrun] Couldn't find executable named stageros below /opt/ros/hydro/share/stage

tonyParker gravatar image tonyParker  ( 2014-09-11 18:34:55 -0500 )edit

ROS Hydro use stage 4.1.1. for this version try

rosrun stage_ros stageros ..............

tonyParker gravatar image tonyParker  ( 2014-09-19 08:23:08 -0500 )edit

answered 2011-10-13 22:10:40 -0500

jlo gravatar image

Thanks! I managed to get inside it and now I'm trying to publish manually info into cmd_vel. I checked with rosmsg show what type it is and I get it's a vector:

alonsoj1@aut-228:~/ros_workspace$ rosmsg show geometry_msgs/Twist
geometry_msgs/Vector3 linear
  float64 x
  float64 y
  float64 z
geometry_msgs/Vector3 angular
  float64 x
  float64 y
  float64 z

I try the following ways:

alonsoj1@aut-228:~/ros_workspace$ rostopic pub /cmd_vel geometry_msgs/Twist -- 2,3,1 0,0,0
ERROR: No key named [2,3,1]
Args are: [linear.x linear.y linear.z angular.x angular.y angular.z]

Then like this:

  • 2.0 3.0 1.0 0.0 0.0 0.0
  • 2 3 1 0 0 0
  • [2 3 1] [0 0 0]

But none of them work, any ideas?


edit flag offensive delete link more


Found it in YAML manual: rostopic pub /cmd_vel geometry_msgs/Twist -r 1 '[1, 1, 0]' '[2, 0, 0]' Now... what type of coordinates are used for angle? Like here in the first case ? I can't seem to figure them out (angles, most of al
jlo gravatar image jlo  ( 2011-10-14 00:42:32 -0500 )edit
rostopic pub /cmd_vel geometry_msgs/Twist '{linear: {x: 1, y: 0, z: 0}, angular: {x: 0, y: 0, z: 1.0}}' see also
Lorenz gravatar image Lorenz  ( 2011-10-14 00:42:44 -0500 )edit
The twist message doesn't specify any coordinates. It specifies linear and angular velocities. Information about the units used in ROS can be found here: Linear velocities are specified in m/sec and angular velocities in rad/sec.
Lorenz gravatar image Lorenz  ( 2011-10-14 00:49:52 -0500 )edit

answered 2011-10-17 01:06:17 -0500

updated 2011-10-25 01:29:03 -0500

I would suggest a slight modification to Röhling's approach.

You can locate file at /opt/ros/diamondback/stacks/simulator_stage/stage/world. Modify that world file slightly, towards the end of the file add ctrl "wander" as shown;

# throw in a robot
erratic( pose [ -11.277 23.266 0 180.000 ] name "era" color "blue" ctrl "wander")
block( pose [ -13.924 25.020 0 180.000 ] color "red")

and now if you try the command

rosrun stage stageros `rospack find stage`/world/

you should see the erratic robot move around in a 'wander' mode - moving around randomly avoiding obstacles.

edit flag offensive delete link more


Do you happen to know where the code for that 'wander' mode is? Where can it be read?
jlo gravatar image jlo  ( 2011-10-17 01:38:05 -0500 )edit
@jlo : it is not a code - it is integrated into Stage - if you want the 'wander' code which has been integrated into it then download Stage (ver 3.2.2) ( and check out the file Stage-3.2.2-Source/examples/ctrl/
Arkapravo gravatar image Arkapravo  ( 2011-10-17 02:04:32 -0500 )edit

answered 2011-10-16 21:38:30 -0500

jlo gravatar image

Hi, So... if I understood correctly, I could be able to move the robot everywhere without using the angular velocity parameter, right? I have tried and I can't manage to get it right: I can move the robot left and right (as seen in the screenshot) with the following commands:

rostopic pub /cmd_vel geometry_msgs/Twist -r 1 '[10, 0, 0]' '[0, 0, 0]'

and back to the inverted direction (right):

rostopic pub /cmd_vel geometry_msgs/Twist -r 1 '[-10, 0, 0]' '[0, 0, 0]'

I tried playing with the rest of coordinates (using y or z, but they didn't produce any visible result). I also tried to use the angular velocity parameter by themselves, but I couldn't manage to make the robot move.

image description

Any suggestions would be appreciated, thanks :)!

edit flag offensive delete link more


[SOLVED] Reading teleop_base_keyboard.cpp I found out that the only coordinates that matter are X of linear and Z of angular speed. With that, I managed to move the robot. An example, to make it move in a circle: rostopic pub /cmd_vel geometry_msgs/Twist -r 10000 '[10, 0, 0]' '[0, 0, 5]'
jlo gravatar image jlo  ( 2011-10-17 00:27:16 -0500 )edit

answered 2011-10-17 01:43:02 -0500

jlo gravatar image

Any ideas towards how can I read the laser info to check if the robot has an obstacle in front of it or not? I tried with this

alonsoj1@aut-228:~$ rosmsg show sensor_msgs/LaserScan
Header header
  uint32 seq
  time stamp
  string frame_id
float32 angle_min
float32 angle_max
float32 angle_increment
float32 time_increment
float32 scan_time
float32 range_min
float32 range_max
float32[] ranges
float32[] intensities

And I think the best way would be to establish a threshold for the range of 'intensities'. How can I stream the values of that parameter in a terminal to establish that range?

edit flag offensive delete link more


Why not use the ranges array, which contains the measured distances to the obstacles?
roehling gravatar image roehling  ( 2011-10-17 01:49:44 -0500 )edit
How can I visualize the ranges array?
jlo gravatar image jlo  ( 2011-10-17 21:02:07 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2011-10-13 01:17:06 -0500

Seen: 4,030 times

Last updated: Oct 25 '11