Home | Tutorials | Wiki | Issues
Ask Your Question

Ordered List of Models in World

asked 2018-01-22 07:23:53 -0500

Baumboon gravatar image

updated 2018-01-22 08:19:36 -0500

Hello Guys,

i use gazebo 7.0 with Ros kinetic.

First of all i want a ordered List of the models how i add them to the list.

Here is what my code looks like:

class Block:
    def __init__(self, name, relative_entity_name):
        self._name = name
        self._relative_entity_name = relative_entity_name

class Tutorial:

    _blockListDict = {
        'a': Block('cardboard_box', 'link'),
        'b': Block('cabinet', 'link'),
        'c': Block('bookshelf_0', 'link'),
        'e': Block('jersey_barrier', 'link'),
        'd': Block('Dumpster_0', 'link'),

My problem actual is that my order when i print information for the objects is:

cardboard, bookshelf_0 , cabinet, jersey barrier, Dumpster_0

What i am expected was cardboard, cabinet, bookshelf_0 , Dumpster_0, Jersey_barrier.

Any ideas what i am doing wrong?

Thats how i iterate the list:

 def update_gazebo_models(self):
        i = 0
            model_coordinates = rospy.ServiceProxy('/gazebo/get_model_state', GetModelState)
        vlist = []

            for block in self._blockListDict.itervalues():
                blockName = str(block._name)
                 resp_coordinates = model_coordinates(blockName, block._relative_entity_name)
             value = resp_coordinates.pose.position.x + resp_coordinates.pose.position.y
             i = i +1
        return vlist
        except rospy.ServiceException as e:
            rospy.loginfo("Get Model State service call failed:  {0}".format(e))
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-01-22 08:56:14 -0500

Raskkii gravatar image

So this is not a Gazebo specific problem as it could happen to any dictionary in Python.

The reason for your problem is that in Python dictionaries are not ordered.

I suggest you read more on the provided link and try a different datatype for storing your block objects.


edit flag offensive delete link more


Thank u, i messed up that i did´t use a orderedList Thank u!

Baumboon gravatar imageBaumboon ( 2018-01-22 09:20:48 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-01-22 07:23:53 -0500

Seen: 59 times

Last updated: Jan 22