This is an old revision of the document!


Fluents

Fluents are proxy objects which are synchronized between different threads. They can be used to store values in a dynamic parallel system and to react to changes of these values.

In PyCRAM fluents are created by calling the constructor of the Fluent class which can be imported from pycram.fluent. The constructor has to given a value which should be saved in the fluent and optionally a name, if no name is provided a random string will be generated instead.

from pycram.fluent import Fluent 

f = Fluent(5)

This creates a fluent which stores the integer 5.

To get to value stored in a fluent the method 'get_value' is used. To assign a new value to a fluent to method 'set_value' is used.

f.get_value() # Would return 5
f.set_value("a") # Sets the value of this fluent to "a" 

It is also possible to wait for the value of a fluent to change. This can be done by using the 'wait_for' function of a fluent.

f.wait_for()

This blocks the thread until the value of the fluent is changed. It is also possible to combine fluents to create a conditions that should be checked every time the fluent is updated. This chaining of fluents is called a fluent network.

(f / 2 == 0).wait_for()

Every time the value of f is changed the condition will be checked and because operator on fluents generate new fluents to wait_for method is also available.