Properties

Properties are named attributes of a stage. They can be used to configure the stages behaviour and control further substages. Lets take a closer look at how to work with properties.

Basic Operations with Properties

Lets define a property and assign a description, as well as a value to it.

# Create a property
p = core.Property()

# Set a descriptive string to describe the properties function
p.setDescription("Foo Property")

Notice that a property always has two values: the current value and the default value. Before we use the property, we might want to check if the current value defined.

# Check if the property is defined
assert p.defined()

Now we are ready to safely retrieve the values of the proprty!

# Retrieve the stored value
print(p.value())

# Retrieve the default value
print(p.defaultValue())

# Retrieve the description
print(p.description())

The Property Map

Usually a stage comprises multiple properties. A stage contains a single PropertyMap that acts as a container for all properties associated to that stage.

Lets first create a PropertyMap in isolation and initialize some properties using a dict. As you can see, properties can be of arbitrary type.

# Create a property map
pm = core.PropertyMap()
props = {"prop1": "test", "prop2": 21, "prop3": PoseStamped(), "prop4": 5.4}
pm.update(props)

Properties can also be initialized using a more pythonic way.

# Add a property to the property map using the pythonic way
pm["prop5"] = 2

There are two ways to retrieve properties back from the property map. We might only be interested in in the value of the property:

# Return the value of a property
print(pm["prop5"])

Or we can obtain a reference to the whole property object.

# Return the underlying property object
p2 = pm.property("prop5")

The PropertyMap class additionally provides an iterator that can be used in loops.

# Iterate through all the values in the property map
print("\n")
for i in pm:
    print(i, "\t\t", pm[i])
print("\n")

Remember that wer initialized our PropertyMap by using a dict. In fact, you can also use an existing PropertMap to copy over some properties.

# A new property map can also be configured using an existing one
# You can also only use a subset of the properties that should be configured.
pm2 = core.PropertyMap()
pm.exposeTo(pm2, ["prop2", "prop4"])

Accessing Properties of a Stage

You can obtain a reference to the the PropertyMap of a stage like so

# Create a stage
stage = stages.CurrentState("Current State")
# Access the property map of the stage
props = stage.properties

As mentioned, each stage contains a PropertyMap. Stages communicate to each other via their interfaces. If you want to forward properties through these interfaces, you can use the reference of a stages’ property object.

# Add a Cartesian pose generator
generator = stages.GeneratePose("cartesian pose")
pose = Pose(position=Point(z=0.2))
generator.pose = PoseStamped(header=Header(frame_id="panda_link8"), pose=pose)
props = computeIK.properties
# derive target_pose from child's solution
props.configureInitFrom(core.Stage.PropertyInitializerSource.INTERFACE, ["target_pose"])

Take a look at the How-To-Guides for a full example of this.