Monday, 30 November 2009

Update of the Manual code from Stage 2.1.1 to 3.2.2

The Stage models from my manual were written using Stage 2.1.1, since then Stage has been updated a few times and there have been significant changes to the way that models are created.

Here I'll go through the code that was developed in the manual and I'll make the changes necessary for running the world using the Stage 3.2.X.



The .cfg File


This is the old configuration file I won't bother reprinting the entire thing here.

This file begins with the following code to make Player use Stage instead of trying to connect to real robot devices:


driver
(
name "stage"
plugin "libstageplugin"

provides ["simulation:0"]

# load the named file into the simulator
worldfile "robots_and_junk.world"
)

The only thing that needs changing here is the line plugin "libstageplugin" to plugin "stageplugin". That is, delete the "lib" from the front.
If you don't do this Player will tell you that it can't find the stage library and nothing will happen.

The .world File


This is the old .world file.

This is the old bigbob.inc file.

If you try running Player with the revised .cfg file you'll probably encounter the following message:

err: Loading size. Need a vector of length 3: found 2.

In the latest version of Stage they upgraded the syntax that describes shapes and things to support 3D models. This included changing the size parameter, so size [x y] doesn't work any more, and the command is now size [x y z] values are still measured in metres. The error it gave means that it is looking for a height, which has not been declared.

In my file I make the world height and map height to be 3 (so changed size [15 15] to size [15 15 3]) which is a somewhat arbitary choice for a height. I also added a height to the orange and carton models in the .world file. The height also needs to be specified in the bigbob.inc file, although for some reason I'd already given that a height of 1 metre, the laser models also needs to be modified because that uses the size parameter too, the ranger model uses ssize which does not need to be 3 dimensional.

Once these corrections have been made, Player gives the following error:

err: Loading pose. Need a vector of length 4: found 3.

The move from 2D models to 3D models means that when you declare the model's pose you also need to tell Stage what height the robot is at.
The pose [x y yaw] parameter has been changed to pose [x y z yaw], so a value for z needs to be added. For non-flying robots (like the bigbob example) this will be 0.

In the .world file I set the z pose of all objects in the world to be 0.
In bigbob.inc the laser's pose needed to be set as it uses the pose parameter, again the ranger model doesn't need altering because it uses spose instead of pose.
Also, the origin parameter in the bigbob position model needs changing, for some reason this will cause the above "pose" error, even though it's the origin parameter. I don't know why.
Anyway, I changed origin [0.125 0 0] to origin [0.125 0 0 0] and that stopped the pose error.



Next Player gave me these errors:

err: Model type ptz not found in model typetable

err: Unknown model type ptz in world file.


Evidently the ptz model has been removed completely from Stage. This requires a complete rewrite of the blobfinder code, to update it to use the later syntax. Basically this means getting rid of the ptz stuff and renaming channels to colors. This is the old blobfinder code:



# bigbob's blobfinder
define bigbobs_eyes ptz
(
blobfinder
(
# number of colours to look for
channels_count 2

# which colours to look for
channels ["orange" "DarkBlue"]

# camera parameters
image [160 120]  #resolution
range_max 5.00
ptz [0 0 60]
)
)


Which is replaced with the following code:


# bigbob's blobfinder
define bigbobs_eyes blobfinder
(
# number of colours to look for
colors_count 2

# which colours to look for
colors ["orange" "DarkBlue"]

# camera parameters
image [160 120]  #resolution
)



Running Player on the world now will actually produce a simulation, although it's a bit useless:



To fix this the old map.inc is first replaced by the newest map.inc.
The map model has been renamed to floorplan in this newest map.inc so the .world file is changed accordingly. The resulting world still looks like the above picture though.
This is due to changes in the window model. Our code currently looks like this:


# size of the whole simulation
size [15 15 3]


# configure the GUI window
window
(
size [ 700.000 700.000]
scale 0.025
)

In Stage 3.2.0 it is no longer necessary to declare the size of the simulation outside the window, it's done instead using the scale parameter of the window. The window scale used to be calculated by doing map_size/window_size, now it is window_size/map_size. Since we want our window to be 700px by 700px and our map to be 15m by 15m this is 700/15, which works out as 46.6 reuccuring. This needs to be rounded down to fit in the window properly, after a little trial and error I found a scale of 40 worked ok, although sometimes it doesn't render the box surrounding the map, scrolling up and then down on the Stage window solves that problem or alternatively reducing the scale to 35.

The Stage simulation now looks like this:


Window has been fixed on stage to now render everything properly.



Next the polygons parameter has been replaced with block. usage is similar though, let's look at the bigbob postion model that used polygons:


polygons 3
polygon[0].points 6
polygon[0].point[0] [0 0]
polygon[0].point[1] [0 1]
polygon[0].point[2] [0.75 1]
polygon[0].point[3] [1 0.75]
polygon[0].point[4] [1 0.25]
polygon[0].point[5] [0.75 0]

polygon[1].points 4
polygon[1].point[0] [1 0.75]
polygon[1].point[1] [1.25 0.75]
polygon[1].point[2] [1.25 0.625]
polygon[1].point[3] [1 0.625]

polygon[2].points 4
polygon[2].point[0] [1 0.375]
polygon[2].point[1] [1.25 0.375]
polygon[2].point[2] [1.25 0.25]
polygon[2].point[3] [1 0.25]



block
(
points 6
point[0] [0 0]
point[1] [0 1]
point[2] [0.75 1]
point[3] [1 0.75]
point[4] [1 0.25]
point[5] [0.75 0]
)

block
(
points 4
point[0] [1 0.75]
point[1] [1.25 0.75]
point[2] [1.25 0.625]
point[3] [1 0.625]
)

block
(
points 4
point[0] [1 0.375]
point[1] [1.25 0.375]
point[2] [1.25 0.25]
point[3] [1 0.25]
)


The same was done for the carton model, the simulation now looks like this:

Changed robot to use blocks



The problem with this model is now that the bigbob robot is hollow! If we look at the simulation using Stage 3.2.X's perspective mode (press R) it looks like this:

robot is hollow :(



Trying to work out how this code differs from the supplied example code where the robots aren't hollow is SADNESS. To save you the trouble of asking the Player/Stage mailing list the same question I did I can tell you the problem is that the points need to be declared anti-clockwise! If you look at the block code you can see that as you plot from points 0 to 5 the corners progress clockwise. I can't take credit for finding that out though. Finally with the blocks you have to declare where the block is in the z plane. This is done with z [height_from height_to], so if I wanted my block to be from the floor to 1m in height I'd do z [0 1], if I wanted it to be from 50cm off the ground to 1m then I'd use z [0.5 1].

Let's say that Bigbob is 1m tall (which was established earlier when I set the size) and the teeth to be 50cm tall and on the ground. Implementing these changes gives block code like so:


block
(
points 6
point[5] [0 0]
point[4] [0 1]
point[3] [0.75 1]
point[2] [1 0.75]
point[1] [1 0.25]
point[0] [0.75 0]
z [0 1]
)

block
(
points 4
point[3] [1 0.75]
point[2] [1.25 0.75]
point[1] [1.25 0.625]
point[0] [1 0.625]
z [0 0.5]
)

block
(
points 4
point[3] [1 0.375]
point[2] [1.25 0.375]
point[1] [1.25 0.25]
point[0] [1 0.25]
z [0 0.5]
)


You may note I've been somewhat lazy in converting the coordinates from clockwise to anti-clockwise. It still works fine though and the finished world looks like this:
The finished Stage model



This completed code can be downloaded from this link:

Player/Stage 3.2.X Bigbob example code

12 comments:

  1. thanks a lot Jenny, your blog helped me a lot

    ReplyDelete
  2. No problem, thanks for commenting!

    I'll be updating the manual to include all this Stage 3.2 stuff soon, unfortunately other work commitments are getting in the way at the moment.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. WOW ! ..... I never knew about the perspective mode (press R) .... !

    ReplyDelete
  5. Hi!
    It's possible to use stage 3.2.2 with player 2.1.3?
    When I try I get this error:

    success
    simple.cfg:15 error: unknown interface: [simulation]

    Thanks a lot for the manual and the answer :)

    ReplyDelete
  6. I'm not sure why that would happen. Maybe Stage isn't installed correctly, like when player looks for the simulation interface it isn't checking the stage install folder? Setting paths is usually the cure for that sort of thing, or reinstalling Stage. This is just a guess though, I could be (and usually am) wrong.

    ReplyDelete
  7. Hey

    two things:
    first the bonus:

    using [ctrl] allows you to rotate the camera..
    so not only [r] can bring you to perspective mode.

    - panning, is [x,y] when clicking on background
    - panning is [z] when scrolling

    now a question, which is driving me mad..

    IN STAGE:

    I have a robot model, with a size specified as [x y z]

    the robot as a ranger sensor attached at spose[x y]

    how come the ranger device reports distances correctly to objects taller than the robot, but not for objects with a smaller height than the robot.

    can I Fix this ?

    the reason why this is a problem is:

    The actual real life robot, has a bumper, mounted on springs, allowing it to retract a bit on collision.

    - the idea is to create a virtual bumper using ranger as a distance measure, as I cannot see the bumper implementation in stage 3.2.2 anymore.

    the bumper is able to run below some objects which the entire robot cannot. (think table or beam in the air)

    I am building a controller which must be able to handle such situations.

    It must also be able to do wall following using bumper only.

    If anyone has an alternate idea, advice would be appreciated.

    ReplyDelete
  8. Hi Henrik, sorry it took so long to reply, I don't get notification emails about the blog so didn't see your comment.

    I suspect what is happening is that the rangers are being put on the top of the robot by default, I had a similar problem with the laser on the bigbob model. Somewhere in the ranger model specification you'll need to specify the pose so that the model's z coordinate can be set (the z origin would be the top of the robot, so to put the bumper on the ground it would be a minus number).

    I have no idea why it is that way!

    ReplyDelete
  9. Hello,

    I have this problem with running bigbob robot:

    oris@boris:~/Downloads/tutorial-src$ player bigbob.cfg
    Registering driver
    Player v.3.0.2

    * Part of the Player/Stage/Gazebo Project [http://playerstage.sourceforge.net].
    * Copyright (C) 2000 - 2009 Brian Gerkey, Richard Vaughan, Andrew Howard,
    * Nate Koenig, and contributors. Released under the GNU General Public License.
    * Player comes with ABSOLUTELY NO WARRANTY. This is free software, and you
    * are welcome to redistribute it under certain conditions; see COPYING
    * for details.

    invoking player_driver_init()...
    Stage driver plugin init

    ** Stage plugin v4.0.0 **
    * Part of the Player Project [http://playerstage.sourceforge.net]
    * Copyright 2000-2009 Richard Vaughan, Brian Gerkey and contributors.
    * Released under the GNU General Public License v2.

    success
    Stage plugin: 6665.simulation.0 is a Stage world
    [Loading ./robots_and_junk.world][Include map.inc][Include bigbob.inc]f: ./robots_and_junk.world

    err: Model type laser not found in model typetable (/home/boris/Downloads/Stage-4.0.0-src/libstage/world.cc CreateModel)
    err: Unknown model type laser in world file. (/home/boris/Downloads/Stage-4.0.0-src/libstage/world.cc CreateModel)

    I dont know where to fix this problem...

    ReplyDelete
    Replies
    1. same problem bro...

      Delete
  10. When I coment in bigbob file laser it works for me:

    # sensors attached to bigbob
    bigbobs_sonars()
    bigbobs_eyes()
    #bigbobs_laser()

    And I have to remove sonars end laser in bigbob.cfg:
    # the main bob1 robot
    driver
    (
    name "stage"
    provides ["6665:position2d:0" "6665:blobfinder:0"]
    model "bob1"
    )

    ReplyDelete
  11. Hm, because I comment this there is no way to connect to robot.
    This i get in eclipse Console:
    warning : warning : [Player v.3.0.2] connected on [localhost:6665] with sock 3

    playerc error : got NACK from request
    playerc error : failed to get response
    terminate called after throwing an instance of 'PlayerCc::PlayerError'

    In consol where I run my cfg:

    accepted TCP client 0 on port 6665, fd 11
    stage driver setup
    warning : skipping subscription to unknown device sonar:0
    closing TCP connection to client 0 on port 6665
    Stage driver has been shutdown


    How can I fix this problem in stage...

    thx!!!

    ReplyDelete