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;
var x = 1.0;
y = x + 1;
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
- sin(a) : the sine of an angle
- cos(a) : the cosine of an angle
- tan(a) : the tangent of an angle
- asin(x) : the arcsine of a value, NaN if abs(x) > 1
- acos(x) : the arccosine of a value, NaN if abs(x) > 1
- atan2(x,y) : the four quadrant arctangent, returning values between -pi and pi
- csc(a) : the cosecant of an angle
- sec(a) : the secant of an angle
- cot(a) : the cotangent of an angle
Rounding, Sign, and Comparison Functions
- ceil(x) : the nearest integer rounded up
- floor(x) : the nearest integer rounded down
- round(x) : the nearest integer
- sign(x) : the sign
- abs(x) : the absolute value
- max(x,y) : the larger of two numbers
- min(x,y) : the smaller of two numbers
Exponential Functions
- sqrt(x) : the square root, NaN if x < 0
- log(x) : the natural logarithm, NaN if x <= 0
- log10(x) : the base 10 logarithm, NaN if x <= 0
- exp(x) : the exponential, e^x
Other Functions
- rand(y) : a floating point random number between 0.0 and y (NB: this differs from the Matlab notation)
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