Main Page | Modules | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Numerical Calculations

In addition to allowing you to apply operations at different frames of reference, the CDL has the ability to evaluate numerical expressions. As most people are very familiar with it, the syntax was modeled after Matlab, with one principal exception. While Matlab works with complex numbers as default, the CDL is only capable of working with real numbers. Any operations returning a complex number will give NaN instead of the desired number. This is a known limitation, and is being considered for future improvements.

Numbers can be input as integers (e.g. 5), in floating point notation (3.1415926), or in scientific notation (3e8, 1.6726e-27). They are all stored internally as double precision floating point numbers. If you would like to store a number as a variable, you must first initialize the variable by preceding it with the keyword "var".

var y;       // y is initialized without a value (defaults to 0)
var x = 1.0; // x is initialized with a value of 1.0
y = x + 1;   // y now has a value of 2
It is a syntax error to initialize a variable twice.

Now that we know how to input and reuse numbers and variables, we can use them in numerical function calls and expressions. The basic algebraic operators are all defined. Of particular note is that exponentials are done with carats, a la Matlab, and not like C, which requires a separate function call. The following are all valid expressions:

var x = sqrt(9);
var golden = ( 1 + sqrt(5) ) / 2.0;
var mymin = min(x,golden);
var iszero = sin(pi/3) - sqrt(3)/2;
"pi" is a predefined variable, and all trigonometric functions operate in radians. A complete list of implemented functions, with descriptions, follows:

Trigonometric Functions

Rounding, Sign, and Comparison Functions Exponential Functions Other Functions This limited set of numerical functions forms a wide basis to build geometries for robot designs. However, this list is by no means complete, and for that reason, it is extremely simple to modify the source to include additional functions.
SimLib Reference Documentation