-
Notifications
You must be signed in to change notification settings - Fork 11
expressiongraph_ex
You'll find this example program under ./examples/tutorial1.cpp
.
The following example defines a simple expression graph
Line 11 of this example shows the definition of a simple scalar expression graph. As it can be seen, the definition looks very similar to a typical C++ expression. the input
function represents an input variable, Constant
is used to convert a constant value to an expression graph, such that it can be used in an expression.
Line 12-14 define an array with values for the input variables. Line 17 calls setInputValues
to set these values for the expression defined by expr
. Then value()
is used to request the value of the expression. derivative(0)
is used to request the derivative of the expression towards the 0-th input variable. value()
should always be called before derivative(..)
. setInputValues(..)
should always be called before value()
.
To verify the results in this simple example, the derivatives are computed symbolically in line 24-28.
Line 19 shows how to print a representation of the expression graph on the console. Line 30-24 show how to write a .dot file in order to later generate a diagram of the expression graph.
After compiling this example, it can be run in the shell and a figure can be generated from the generated graphviz .dot file:
This results in the following visualization:
Fig. 1 Expression graph defined in the tutorial1.cpp example.
You'll find this example program under ./examples/tutorial2.cpp
.
The goal of this example is to explain the use of geometric entities and the use of cached
nodes. This tutorial example defines a kinematic chain by specifying the individual transformations. The example specifies the kinematics of a LWR-robot.
The computation of the kinematic chain is split up into the computation of the pose of the elbow( elbow
), the computation of the pose of the wrist(wrist
), and the computation of the pose of the end effector (kinchain
). The rot_x
function specifies a rotation matrix of a rotation around the x-axis with the given input expression. Frames are specified using a rotation matrix specifying the orientation and a Vector specifying the origin. Notice the use of Constant
to define constant expressions. The argument of the Constant
function is a KDL statement, i.e. of scalar type (double), Frame, Vector, Rotation, Twist, or Wrench type. This program gives the following output.
The following image shows the resulting expression graph:
Fig. 2 Expression graph for the kinematic chain of a KUKA LWR robot.