Skip to content
eaertbel edited this page Nov 25, 2014 · 4 revisions

Basic infrastructure

Expression graphs are have a given type. This type determines the output type when the value of the expression graph is requested. The expression graph type is represented by the class definition:

Expression<T>

Functions and operators however, never work directly on these objects, but always via a smart pointer:

Expression<T>::Ptr

::Ptr is defined in the graph expression nodes and refers to a boost smart pointer. The underlying expression graph object is destroyed when the last smart pointer referring to it has gone out of scope.

where T is a template parameter that corresponds to one of the types in the table below:

Description C++ Type C++ Type of derivative
Scalar value double double
Position, velocity, acceleration vectors, rotational velocities, ... KDL::Vector KDL::Vector
Orientation of a frame KDL::Rotation KDL::Vector
Representation of a frame, including its origin KDL::Frame KDL::Twist
Representation of the velocity or acceleration of a frame KDL::Twist KDL::Twist
Representation of the force, (or rate of change of force) KDL::Wrench KDL::Wrench

Each node of of an expression graph is represented by a class. Typically these classes are not manually instantiated. Their instantiation occurs automatically when using a set of special purpose functions and operators. These functions and operators always operate on expression graph types, and correspond as good as possible to KDL API for the primitive types. The different nodes of an expression graphs are implemented using the following hierarchy of objects (implementation inheritance). The corresponding functions are indicated in blue:

  • FunctionType<ResultType> representing an expression that is a function of the input variables.
    • ConstantType<Resultype> representing a constant value, i.e. a value whose derivative is zero (Constant<...>).
    • InputType reflects an input variable with given number back as an output of the expression. This is how input variables are introduced in expression graphs. (Input).
    • CachedType<ResultType;> caches the values that it computes, such that only changed parts of an expression graph have to be recomputed. The cache can be reset by calling one of the setInputValue methods or it can be reset by the ExpressionOptimizer. (Cached<...>).
  • UnaryExpression<ResultType,InputType> representing an expression that takes another expression as an input.
    • BlockWave represents a blockwave with parametrizable levels and periods in function of its input expression. In its discontinuous points, the derivative evaluates to the left derivative. (blockwave(input expression, period, level1, level2)).
  • BinaryExpression<ResultType,InputType 1, InputType 2> representing an expression that takes two other expression as an input.
  • TernaryExpression<ResultType,InputType 1, InputType 2, InputType 3> representing an expression that takes three other expression as an input.
    • Conditional evaluates its first argument,a double expression, and returns the second argument if the double expression is larger or equal than zero, otherwise it returns the third argument. (conditional<...>(a1,a2,a2)).
    • NearZero evaluates its first argument, a double expression, and returns the second argument if the double expression is within tollerance from zero, otherwise it returns the third argument. (near_zero<...>(a1,tolerance, a2, a3).

ExpressionOptimizer is a class that takes care of setting the input variables and clearing the cached nodes for a set of expression graphs. It is used to efficiently evaluate a set of expression graphs.