LEGO NXT C Programming
Text programming for LEGO NXT is done in C using macros and functions from the ECRobot library.
The general structure of the program:
- First you connect the header files used in the program (standard C header files and ECRobot header files).
- Then the constants and variables used in the program are declared.
- These are followed by the functions
ecrobot_device_terminate. The first one is called when the program starts and the second one when it stops. They usually initialize and deinitialize sensors, encoders, and other robot devices. The random number generator is initialized in
- This is followed by the description of the
user_1ms_isr_type2function, which is called every millisecond.
- Then comes the description of the task, which is executed when the program starts:
TASK (OSEK_Task_Number_0). This is where most of the programming is done.
U32 __interpretation_started_timestamp__ = 0;
static const float pi = 3.14159265;
/* nxtOSEK hook to be invoked from an ISR in category 2 */
/* Main task */
__interpretation_started_timestamp__ = systick_get_ms();