pycram.language

Module Contents

Classes

Language

Parent class for language expressions. Implements the operators as well as methods to reduce the resulting language

Repeat

Executes all children a given number of times.

Monitor

Monitors a Language Expression and interrupts it when the given condition is evaluated to True.

Sequential

Executes all children sequentially, an exception while executing a child does not terminate the whole process.

TryInOrder

Executes all children sequentially, an exception while executing a child does not terminate the whole process.

Parallel

Executes all children in parallel by creating a thread per children and executing them in the respective thread. All

TryAll

Executes all children in parallel by creating a thread per children and executing them in the respective thread. All

Code

Executable code block in a plan.

class pycram.language.Language(parent: anytree.NodeMixin = None, children: typing_extensions.Iterable[anytree.NodeMixin] = None)

Bases: anytree.NodeMixin

Parent class for language expressions. Implements the operators as well as methods to reduce the resulting language tree.

Default constructor for anytree nodes. If the parent is none this is the root node.

Parameters:
  • parent – The parent node of this node

  • children – All children of this node as a tuple oder iterable

parallel_blocklist = ['PickUpAction', 'PlaceAction', 'OpenAction', 'CloseAction', 'TransportAction', 'GraspingAction']
do_not_use_giskard = ['SetGripperAction', 'MoveGripperMotion', 'DetectAction', 'DetectingMotion']
block_list: typing_extensions.List[int] = []

List of thread ids which should be blocked from execution.

resolve() Language

Dummy method for compatability to designator descriptions

Returns:

self reference

abstract perform()

This method should be overwritten in subclasses and implement the behaviour of the language expression regarding each child.

__add__(other: Language) Sequential

Language expression for sequential execution.

Parameters:

other – Another Language expression, either a designator or language expression

Returns:

A Sequential() object which is the new root node of the language tree

__sub__(other: Language) TryInOrder

Language expression for try in order.

Parameters:

other – Another Language expression, either a designator or language expression

Returns:

A TryInOrder() object which is the new root node of the language tree

__or__(other: Language) Parallel

Language expression for parallel execution.

Parameters:

other – Another Language expression, either a designator or language expression

Returns:

A Parallel() object which is the new root node of the language tree

__xor__(other: Language) TryAll

Language expression for try all execution.

Parameters:

other – Another Language expression, either a designator or language expression

Returns:

A TryAll() object which is the new root node of the language tree

__rshift__(other: Language)

Operator for Monitors, this always makes the Monitor the parent of the other expression.

Parameters:

other – Another Language expression

Returns:

The Monitor which is now the new root node.

__mul__(other: int)

Language expression for Repeated execution. The other attribute of this operator has to be an integer.

Parameters:

other – An integer which states how often the Language expression should be repeated

Returns:

A Repeat() object which is the new root node of the language tree

__rmul__(other: int)

Language expression for Repeated execution. The other attribute of this operator has to be an integer. This is the reversed operator of __mul__ which allows to write:

2 * ParkAction()
Parameters:

other – An integer which states how often the Language expression should be repeated

Returns:

A Repeat() object which is the new root node of the language tree

simplify() Language

Simplifies the language tree by merging which have a parent-child relation and are of the same type.

 <pycram.new_language.Parallel>
 ├── <pycram.new_language.Parallel>
 │   ├── <pycram.designators.action_designator.NavigateAction>
 │   └── <pycram.designators.action_designator.MoveTorsoAction>
 └── <pycram.designators.action_designator.DetectAction>

 would be simplified to:

<pycram.new_language.Parallel>
 ├── <pycram.designators.action_designator.NavigateAction>
 ├── <pycram.designators.action_designator.MoveTorsoAction>
 └── <pycram.designators.action_designator.DetectAction>
static merge_nodes(node1: anytree.Node, node2: anytree.Node) None

Merges node1 with node2 in a tree. The children of node2 will be re-parented to node1 and node2 will be deleted from the tree.

Parameters:
  • node1 – Node that should be left in the tree

  • node2 – Node which children should be appended to node1 and then deleted

abstract interrupt() None

Base method for interrupting the execution of Language expression. To be overwritten in a sub-class.

class pycram.language.Repeat(parent: anytree.NodeMixin = None, children: typing_extensions.Iterable[anytree.NodeMixin] = None, repeat: int = 1)

Bases: Language

Executes all children a given number of times.

Initializes the Repeat expression with a parent and children for the language tree construction and a number which states how often the children should be executed.

Parameters:
  • parent – Parent node of this node, if None this will be the root node

  • children – A list of children of this node

  • repeat – An integer of how often the children should be executed.

perform()

Behaviour of repeat, executes all children in a loop as often as stated on initialization.

Returns:

interrupt() None

Stops the execution of this language expression by setting the interrupted variable to True, adding this thread to the block_list in ProcessModule and interrupting the current giskard goal

class pycram.language.Monitor(condition: typing_extensions.Union[typing_extensions.Callable, pycram.fluent.Fluent] = None)

Bases: Language

Monitors a Language Expression and interrupts it when the given condition is evaluated to True.

Behaviour:

This Monitor is attached to a language expression, when perform on this Monitor is called it will start a new thread which continuously checks if the condition is True. When the condition is True the interrupt function of the child will be called.

When initializing a Monitor a condition must be provided. The condition is a callable or a Fluent which returns True or False.

Parameters:

condition – The condition upon which the Monitor should interrupt the attached language expression.

perform()

Behavior of the Monitor, starts a new Thread which checks the condition and then performs the attached language expression

Returns:

The result of the attached language expression

interrupt() None

Calls interrupt for each child

class pycram.language.Sequential(parent: anytree.NodeMixin = None, children: typing_extensions.Iterable[anytree.NodeMixin] = None)

Bases: Language

Executes all children sequentially, an exception while executing a child does not terminate the whole process. Instead, the exception is saved to a list of all exceptions thrown during execution and returned.

Behaviour:

Return the state SUCCEEDED iff all children are executed without exception. In any other case the State FAILED will be returned.

Default constructor for anytree nodes. If the parent is none this is the root node.

Parameters:
  • parent – The parent node of this node

  • children – All children of this node as a tuple oder iterable

perform() pycram.datastructures.enums.State

Behaviour of Sequential, calls perform() on each child sequentially

Returns:

The state according to the behaviour described in Sequential()

interrupt() None

Interrupts the execution of this language expression by setting the interrupted variable to True and calling interrupt on the current giskard goal.

class pycram.language.TryInOrder(parent: anytree.NodeMixin = None, children: typing_extensions.Iterable[anytree.NodeMixin] = None)

Bases: Language

Executes all children sequentially, an exception while executing a child does not terminate the whole process. Instead, the exception is saved to a list of all exceptions thrown during execution and returned.

Behaviour:

Returns the State SUCCEEDED if one or more children are executed without exception. In the case that all children could not be executed the State FAILED will be returned.

Default constructor for anytree nodes. If the parent is none this is the root node.

Parameters:
  • parent – The parent node of this node

  • children – All children of this node as a tuple oder iterable

perform() pycram.datastructures.enums.State

Behaviour of TryInOrder, calls perform() on each child sequentially and catches raised exceptions.

Returns:

The state according to the behaviour described in TryInOrder()

interrupt() None

Interrupts the execution of this language expression by setting the interrupted variable to True, adding the current thread to the block_list in Language and interrupting the current giskard goal.

class pycram.language.Parallel(parent: anytree.NodeMixin = None, children: typing_extensions.Iterable[anytree.NodeMixin] = None)

Bases: Language

Executes all children in parallel by creating a thread per children and executing them in the respective thread. All exceptions during execution will be caught, saved to a list and returned upon end.

Behaviour:

Returns the State SUCCEEDED iff all children could be executed without an exception. In any other case the State FAILED will be returned.

Default constructor for anytree nodes. If the parent is none this is the root node.

Parameters:
  • parent – The parent node of this node

  • children – All children of this node as a tuple oder iterable

perform() pycram.datastructures.enums.State

Behaviour of Parallel, creates a new thread for each child and calls perform() of the child in the respective thread.

Returns:

The state according to the behaviour described in Parallel()

interrupt() None

Interrupts the execution of this language expression by setting the interrupted variable to True, adding the thread id of all parallel execution threads to the block_list in Language and interrupting the current giskard goal.

class pycram.language.TryAll(parent: anytree.NodeMixin = None, children: typing_extensions.Iterable[anytree.NodeMixin] = None)

Bases: Language

Executes all children in parallel by creating a thread per children and executing them in the respective thread. All exceptions during execution will be caught, saved to a list and returned upon end.

Behaviour:

Returns the State SUCCEEDED if one or more children could be executed without raising an exception. If all children fail the State FAILED will be returned.

Default constructor for anytree nodes. If the parent is none this is the root node.

Parameters:
  • parent – The parent node of this node

  • children – All children of this node as a tuple oder iterable

perform() pycram.datastructures.enums.State

Behaviour of TryAll, creates a new thread for each child and executes all children in their respective threads.

Returns:

The state according to the behaviour described in TryAll()

interrupt() None

Interrupts the execution of this language expression by setting the interrupted variable to True, adding the thread id of all parallel execution threads to the block_list in Language and interrupting the current giskard

class pycram.language.Code(function: typing_extensions.Optional[typing_extensions.Callable] = None, kwargs: typing_extensions.Optional[typing_extensions.Dict] = None)

Bases: Language

Executable code block in a plan.

Variables:
  • function – The function (plan) that was called

  • kwargs – Dictionary holding the keyword arguments of the function

Initialize a code call

Parameters:
  • function – The function that was called

  • kwargs – The keyword arguments of the function as dict

execute() typing_extensions.Any

Execute the code with its arguments

Returns:

Anything that the function associated with this object will return.

abstract interrupt() None

Base method for interrupting the execution of Language expression. To be overwritten in a sub-class.