The Godmap

Giskard's Godmap is its most important internal data structure. All of Giskard's data can be found in the Godmap, which is essentially a huge dict and used to share data among plugins. In that sense it is similar to the blackboard of a behavior tree. The problem it is solving is that when you program a constraint, you need to write symbolic expressions. The symbols used in the expressions need to be substituted with real data, when the quadratic program is created. This is where the Godmap comes in. It is able to traverse its internal data given a path. Lets explain with some code:

from giskardpy.god_map import GodMap
 
class MUH(object):
    d = {'a':1, 0:2, 'f': lambda x,y:x*y}
    l = [42]
 
    def f(self):
        return 'hi'
 
god_map = GodMap()
muh = MUH()
god_map.set_data(['whatever'], muh)
print(god_map.get_data(['whatever']))
# >> <__main__.MUH object at 0x7f9a546d84c0>
print(god_map.get_data(['whatever', 'd']))
# >> {'a': 1, 0: 2, 'f': <function MUH.<lambda> at 0x7f9a4cb36040>}
print(god_map.get_data(['whatever', 'd', 'a']))
# >> 1
print(god_map.get_data(['whatever', 'd', 0]))
# >> 2
print(god_map.get_data(['whatever', 'd', 'f']))
# >> <function MUH.<lambda> at 0x7f9a4cb36040>
print(god_map.get_data(['whatever', 'd', 'f', (2,3)]))
# >> 6
print(god_map.get_data(['whatever', 'f', tuple()]))
# >> hi
print(god_map.get_data(['whatever', 'l']))
# >> [42]
print(god_map.get_data(['whatever', 'l', 0]))
# >> 42
 
god_map.set_data(['whatever', 'l', 0], 23)
print(god_map.get_data(['whatever', 'l', 0]))
# >> 23
 
l = god_map.get_data(['whatever', 'l'])
l[0] = 1337
print(god_map.get_data(['whatever', 'l', 0]))
# >> 1337
 
s = god_map.to_symbol(['whatever', 'l', 0])
print(s)
# >> whatever_l_0
print(god_map.get_values([str(s)]))
# >> [1337]
 
with god_map:
    l = god_map.unsafe_get_data(['whatever', 'l'])
    l.append(42)
    god_map.unsafe_set_data(['whatever', 'l'], l)

As you can see, the Godmap can traverse most data structures and is able to generate symbols for a path. When the quadratic program is created, the god_map.get_values() function is used to get the current values for each symbol.

Since Giskard uses multi threading, the Godmap needs to be thread safe. The standard get_data and set_data functions lock the godmap while the operation is happening. If you want to lock the Godmap for a longer period, you can use a with statement in combination with unsafe versions of the get and set data functions.

Some paths which are used often are hardcoded in identifier.py. Most importantly, the whole config yaml is saved as a dict under identifier.rosparam. Therefore, every new entry added to the config file is immediately available without any extra work.