Gazebo | Ignition | Community
Ask Your Question
0

Ordered List of Models in World

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

Baumboon gravatar image

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

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):
        try:
        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
             vlist.append(round(value,2))
             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
2

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

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.

https://stackoverflow.com/questions/1...

edit flag offensive delete link more

Comments

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

Baumboon gravatar imageBaumboon ( 2018-01-22 09:20:48 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 872 times

Last updated: Jan 22 '18