Echelon Neuron C User Manual

Page 80

Advertising
background image

60

Functions

A number of #define literals are defined for use by the application to initialize

floating-point structures. FL_ZERO, FL_HALF, FL_ONE, FL_MINUS_ONE and
FL_TEN can be used to initialize floating-point variables to 0.0, 0.5, 1.0, -1.0, and

10.0 respectively.
Example:

float_type some_number = FL_ONE;
// initialized to 1.0 at reset

Five floating-point constants are pre-defined: fl_zero, fl_half, fl_one,
fl_minus_one, and fl_ten represent 0.0, 0.5, 1.0, -1.0, and 10.0 respectively.
Example:

fl_mul(&some_number, &fl_ten, &some_number);

// multiply some number by 10.

0

If other constants are desired, they can be converted at runtime from ASCII

strings using the fl_from_ascii( ) function.
Example:

float_type ninety_nine; // constant 99.0
when(reset) {
fl_from_ascii("99", &ninety_nine);
//

initialize

constant

}

Because this function is fairly time consuming, it could be advantageous to pre-

compute constants with the NXT Neuron C Extended Arithmetic Translator.
This program accepts an input file with declarations using standard floating-

point initializers, and creates an output file with Neuron C initializers. It

recognizes any SNVT_

xxx

_f data type, as well as the float_type type. See

Using

the NXT Neuron C Extended Arithmetic Translator

on page 69.

For example, if the input file contains the following statements:

network input float_type var1 = 1.23E4;
const float_type var2 = -1.24E5;
SNVT_temp_f var3 = 12.34;

then the output file contains the following:

network input float_type var1 = {0,0x46,0,0x40,0x3000}
/* 1.23E4 */;
const float_type var2 = {1,0x47,1,0x72,0x3000}
/* -1.24E5 */;
SNVT_temp_f var3 = {0,0x41,0,0x45,0x70a4}
/* 12.34 */;

Users of the NodeBuilder tool can also use Code Wizard to create initializer data

for float_type objects.

Variables of a floating-point network variable type are compatible with the

Neuron C float_type format. The ANSI C language requires an explicit type cast

to convert from one type to another. Structure types cannot be cast, but pointers
to structures can. The following example shows how a local variable of type

float_type can be used to update an output network variable of type

SNVT_angle_f.

Advertising