System architecture of LEGO MINDSTORMS NXT:
The below figure provides a graphical overview of LEGO MINDSTORMS NXT system architecture according to LEGO MINDSTORMS NXT Hardware Developer Kit.
This figure tells that communication between the main ARM7 processor (ATMEL AT91SAM7S256) and Sensors/Servo Motors is done via the co-processor (ATMEL AVR) except for the Ultrasonic Sensor and acquisition of Servo Motor revolutions. For nxtOSEK, most important factor to access Sensors/Servo Motors is the communication with the co-processor via I2C serial bus. This system architecture definitely influences on the software run-time environment of nxtOSEK. The main ARM7 processor accesses to Sensors (to read sensor A/D value) and Servo Motors (to set PWM duty ratio and breake mode) independently every 2 msec through a 1 msec periodical Interrupt Service Routine (ISR) of LEJOS NXJ platform. Servo Motors revolutions are directly captured by pulse triggered ISRs of LEJOS NXJ platform. Ultrasonic Sensor has its brain to directly communicate with the main ARM7 processor via another I2C communication channel.
TOPPERS ATK1 is similar to the
following version of OSEK OS/OIL according to TOPPERS project. OSEK API
Reference and detailed information are described in the documents at the
OSEK/VDX site:
OSEK
OS Version 2.2.1
OSEK OIL
Version 2.5
nxtOSEK restricts several TOPPERS ATK1 features due to the
system architecture. User should not use ISR definitions and Interrupt
handling API.
For those who can understand Japanese, under
nxtOSEK\toppers_osek\doc directory, there are detailed documents written
in Japanese about TOPPERS ATK1.
ECRobot API consists of low level device API and ECRobot
wrapper API (prefix of the API is ecrobot_) that is designed for real-time
control application programming. Gray colored wrapper API in the below
tables has duplicated feature of the original low level device API, so it
is better to use the original API to reduce the run time overhead. When
you use ECRobot API, you need to include ecrobot_interface.h in your source code.
Accessing to the Servo Motor is a bit complicated. NXT uses
I2C communication between the ARM7 and the AVR to set Motor PWM value and
brake mode. However, acquisition of the Motor count is done by pulse input
capture of the ARM7 directly.
Servo Motor
API |
Description |
int |
gets Servo Motor revolution count in degree. Parameters: |
void |
sets Servo Motor revolution count in degree. Parameters: |
void |
sets Servo Motor PWM value and brake mode. Parameters: |
S32 |
gets Servo Motor revolution value in degree. Wrapper of nxt_motor_get_count. Parameters: |
void
ecrobot_set_motor_speed(U8 port_id, S8 speed) |
sets Servo Motor PWM value. Wrapper of nxt_motor_set_speed, but brake mode is fixed as brake. Parameters: |
void |
sets Servo Motor brake mode and PWM value. Wrapper of nxt_motor_set_speed Parameters: |
NXT uses I2C communication
between the ARM7 and the AVR to access the Light Sensor. The AVR uses
10bit A/D converter to get Light Sensor data.
Light Sensor
API |
Description |
void |
turns on infra-red light of Light Sensor. This function should be implemented in the device initialize hook routine. Parameters: |
void |
turns off infra-red light of Light Sensor. This function should be implemented in the device terminate hook routine. Parameters: |
U16 |
gets Light Sensor raw A/D data. Greater value means darker (or lower reflection). Parameters: |
NXT uses I2C communication
between the ARM7 and the AVR to access the Touch Sensor. The AVR uses
10bit A/D converter to get Touch Sensor data. In ecrobot_get_touch_sensor
API, A/D data is converted to be 0/1.
Touch Sensor
API |
Description |
U8 |
gets Touch Sensor status.
Parameters: |
NXT uses I2C communication
between the ARM7 and the AVR to access the Sound Sensor. The AVR uses
10bit A/D converter to get Sound Sensor data.
Sound Sensor
API |
Description |
U16 |
gets Sound Sensor raw A/D data. Smaller value means louder sound. Parameters: |
Ultrasonic Sensor has its
brain to communicate with the ARM7 via another I2C communication channel.
ecrobot_get_sonar_sensor sends a protocol data to communicate with the
Ultrasonic Sensor. However, actual data transaction between the ARM7 and
the Ultrasonic Sensor is done by an ISR triggered by this function call,
so there is one execution cycle delay to achieve consistent data
acquisition.
Ultrasonic Sensor
API |
Description |
void |
initializes a port for I2C communication for Ultrasonic Sensor. This function should be implemented in the device initialize hook routine. Parameters: |
S32 |
gets Ultrasonic Sensor measurement data in cm via I2C. Parameters: |
void |
terminates I2C communication used for Ultrasonic Sensor. This function should be implemented in the device terminate hook routine. Parameters: |
NXT Color Sensor
API |
Description |
void |
initializes a port for NXT Color Sensor. This function should be implemented in the device initialize hook routine. Parameters: |
void |
comunicates with the NXT Color Sensor repeatedly. This function should be executed in a background Task to keep communicating the sensor. (For more detailed information, see C/C++ samples) Parameters: |
void ecrobot_set_nxtcolorsensor(U8 port_id, U8 mode) |
sets the sensor mode. Parameters: |
U8 ecrobot_get_nxtcolorsensor_mode(U8 port_id) |
gets the sensor mode. Parameters: |
U16 ecrobot_get_nxtcolorsensor_id(U8 port_id) |
gets color ID. This API returns valid data when the
sensor is in color sensor mode. Parameters: |
void ecrobot_get_nxtcolorsensor_rgb (U8 port_id, S16 rgb[3]) |
gets color RGB raw data. Parameters: |
U16 ecrobot_get_nxtcolorsensor_light(U8 port_id) |
gets light sensor A/D data. Parameters: |
void |
terminates the NXT Color Sensor. This function should be implemented in the device terminate hook routine. Parameters: |
RS485 API |
Description |
void |
initializes NXT sensor port 4 for RS485 communication. RS485 is configured as asynchronous mode, 8 bits character length, 1 stop bit and no parity check. This function should be implemented in the device initialize hook routine. Parameters: |
U32 |
send RS485 data. Maximum length of send data is 64 [bytes]. Parameters: |
U32 |
receive RS485 data. Maximum length of receive data is 64 [bytes]. Parameters:buf: buffer to receive data off: buffer offset len: length of the data to be received Returns: Number of received data |
void |
terminates RS485 communication. This function should be implemented in the device terminate hook routine. Parameters: |
I2C API |
Description |
void |
initializes a NXT sensor port for I2C communication. This function should be implemented in the device initialize hook routine. Parameters: |
SINT |
send I2C data. Parameters: |
SINT |
read I2C data. Parameters: |
void |
terminates a NXT sensor port used for I2C communication. This function should be implemented in the device terminate hook routine. Parameters: |
Inside of the NXT, there
is a Bluecore chip to handle Bluetooth communication. The ARM7 uses UART
to communicate with the Bluecore chip. In LEGO MINDSTORMS NXT Bluetooth
Developer Kit, standard LEGO firmware supports a lot of communication
protocols, however, ECRobot API does not support all LEGO standard
communication protocol (i.e. no direct control, no diagnosis...).
- In
case of NXT-PC Bluetooth communication, A Windows application program (NXT GamePad) is available to remotely control a
NXT and acquire the NXT internal data (data logging).
- In case of
NXT-NXT, only one NXT to one NXT communication is supported. Device
configurations for a Bluetooth connection needs to be implemented in the
code.
Bluetooth API |
Description |
void ecrobot_init_bt_master(const U8 *bd_addr, const CHAR *pin) |
initializes NXT as the Bluetooth master device and
establish a connection with a slave NXT. Parameters: |
void ecrobot_init_bt_slave(const CHAR *pin) |
initializes NXT as the Bluetooth slave
device and establish a connection with a master device (PC, master
NXT). This API needs to be implemented in a loop (e.g.
ecrobot_device_initialize or a background
Task). Parameters: pin: pin code string. Maximum character length is 16. (e.g. "LEJOS-OSEK") Returns: none |
void |
initializes Bluetooth device and establish a connection with PC. PINCODE for the connection is pre-fixed as "MATLAB". This API needs to be implemented in a loop (e.g. ecrobot_device_initialize or a background Task). Parameters: |
U8 |
get Bluetooth friendly device name. Parameters: |
U8 |
sets Bluetooth friendly device name.
Parameters: |
SINT |
gets the status of Bluetooth device. To communicate with other device, Bluetooth device status has to be BT_STREAM. Parameters: |
S16 |
gets Bluetooth signal strength. Parameters: |
U32 |
sends data packet to a Bluetooth device (PC, master/slave NXT). Parameters: |
U32 ecrobot_send_bt(const void* buf, U32 off, U32 len) |
[RECOMMENDED TO USE] sends data to a Bluetooth device (PC, master/slave NXT). Parameters: |
U32 |
reads data packet from a Bluetooth device (PC, master/slave NXT). Parameters: |
U32 ecrobot_read_bt(void* buf, U32 off, U32 len) |
[RECOMMENDED TO USE] reads data from a Bluetooth device (PC, master/slave NXT).
Parameters: |
U8 |
resets all settings in the persistent settings in the BlueCore chip. The BlueCore chip should be restarted (may need to remove the battery) after calling this function. Otherwise old values can be floating around the BlueCore chip causing unexpected behavior. Parameters: |
void |
terminates Bluetooth connection with a device (PC, master/slave NXT). Parameters: |
void |
sends pre-fixed NXT internal status data. Data packet size is
32bytes and the following NXT internal status data is sent to PC via
Bluetooth. This API is designed for NXT GamePad and NXT GamePad will
save all data as a CSV file. |
nxtOSEK uses LibUsb and LibNXT for USB host
application program. Under samples directory, a USB target example
(usbtest) and a USB host example (usbhost) are available. Currently, only
one NXT can be communicated with a host via USB.
January, 2009:
The new nxtOSEK v2.05 uses LEGO Fantom driver for USB host application
program and USB communication protocol becomes more consistent(i.e.
explict connect/disconnect) and provides more functionalities(i.e.
multiple NXT connections with a host) compared to the previous
version. For more detailed information about nxtOSEK USB API, see
samples\usbtest directory. On the host side programming, see also
samples\usbtest\usbhost directory.
USB API |
Description |
void |
initializes USB functionality in the NXT. This function must be invoked in ecrobot_device_initialize. Parameters: |
SINT ecrobot_set_name_usb(U8* name) |
sets name to the NXT. By default, "nxt" is set as the device name in ecrobot_init_usb. Parameters: |
U8 ecrobot_process1ms_usb(void) |
USB process handler to establish a connection with a host. This function must be invoked every 1msec. (i.e. in a loop with 1msec wait, OSEK/JSP 1msec peiodical Task) Parameters: |
SINT |
reads USB data from host after a USB connection was established. Parameters: |
SINT ecrobot_send_usb(U8* buf, U32 off, U32 len) |
sends USB data to host after a USB connection was established. Parameters: |
SINT ecrobot_disconnect_usb(void) |
disconnects a current connection with host. This API enables to implement connect/disconnect sequence in application. This function makes USB device name being default, so it needs to invoke ecrobot_set_name_usb to change the device name to be user specified device name. Parameters: |
void |
terminates USB functionality in the NXT. Parameters: |
nxtOSEK supports for monochrome BMP files to draw graphics in the LCD display. User can design LCD graphics in BMP editor on PC and the BMP image can be displayed in the LCD on the NXT. GCC provides objcopy which enables to link BMP files to a nxtOSEK binary executable. Under samples directory, there are two BMP file examples (anime and bmptest).
LCD display API |
Description |
SINT |
converts a monochrome BMP file image to a BMP array data. Parameters: |
void display_bitmap_copy(const U8 *data, U32 width, U32 depth, U32 x, U32 y) |
displays a BMP array data to LCD. Parameters: |
void |
updates LCD display. Parameters: |
void display_clear(U32 updateToo) |
clears LCD display buffer. Parameters: |
void display_goto_xy(int x, int y) |
specifies text display position. Top left is (0,0). Parameters: |
void display_string(const char *str) |
stores string into LCD display buffer. Parameters: |
void display_hex(U32 val, U32 places) |
stores integer value into LCD display buffer to display hex expression. Parameters: |
void display_unsigned(U32 val, U32 places) |
stores unsigned integer value into LCD display buffer. Parameters: |
void display_int(int val, U32 places) |
stores signed integer value into LCD display buffer. Parameters: |
void
ecrobot_status_monitor(const CHAR *target_name) |
displays NXT internal status (application name, system tick, battery voltage, raw A/D data, motor revolutions, Bluetooth connection status, and Ultrasonic Sensor data) on the LCD. It is recommended to invoke this API in a low speed periodical Task (i.e. 500msec). Parameters: |
nxtOSEK supports for 8bit monoral PCM WAV file to play a sound. WAV file sound (e.g. music, voice...) can be directly played in the NXT. GCC provides objcopy which enables to link WAV files to a nxtOSEK binary executable. Under samples directory, there is a WAV file example (wavtest).
Sound API |
Description |
SINT |
plays a tone, given its frequency,
duration and volume. Frequency is audible from about 31 to 2100
Hertz. The duration argument is in hundreds of a seconds
(centiseconds, not milliseconds) and is truncated at 256, so the
maximum duration of a tone is 2.56 seconds. |
SINT |
plays a 8bit monoral PCM WAV sound file. Parameters: |
void |
plays a tone, given its frequency and
duration. Frequency is audible from about 31 to 2100 Hertz. The
duration argument is in hundreds of a seconds (centiseconds, not
milliseconds) and is truncated at 256, so the maximum duration of a
tone is 2.56 seconds. Parameters: freq: frequency of the tone in Herz. ms: duration of the tone in hundreds of a second. Returns: none |
NXT internal API |
Description |
U8
ecrobot_is_ENTER_button_pressed(void) |
returns the status of ENTER (ENTR)
button. Parameters: none Returns: Status of ENTER (ENTR) button 1: button is pressed 0: button is not pressed |
U8 |
returns the status of RUN
button. Parameters: none Returns: Status of RUN button 1: button is pressed 0: button is not pressed |
U16 |
gets battery voltage data. Parameters: |
U32 |
gets system tick in msec. system tick is started when the NXT is turned on (not started when an application begins) Parameters: |
U32 |
gets system tick in msec. Wrapper of systick_get_ms. Parameters: |
void |
waits for specified msec. Parameters: |
NXT acquires three axes
acceleraton data from the HiTechnic Acceleration Sensor (NAC1040) via I2C
communication. However, actual data transaction between the ARM7 and
the Acceleration Sensor is done by an ISR triggered by a function call, so
there is one execution cycle delay to achieve consistent data
acquisition. According to HiTechnic,
data reflesh rate on the Sensor is approximately 100 times per second and
acceleration is measured in the range of ?2g to +2g
with scaling of approximately 200 counts per
g.
For more detailed
information about Acceleration Sensor, please visit HiTechnic Web site.
HiTechnic Acceleration Sensor
API |
Description |
void |
initializes a port for I2C communication for Acceleration Sensor. This function should be implemented in the device initialize hook routine. Parameters: |
void |
gets acceleration data in three axes. Parameters: |
void |
terminates I2C communication used for Acceleraton Sensor. This function should be implemented in the device terminate hook routine. Parameters: |
NXT uses I2C communication
between the ARM7 and the AVR to access the HiTechnic Gyro Sensor
(NGY1044). The AVR uses 10bit A/D converter to get Gyro Sensor data.
According HiTechnic, The Gyro Sensor can
measure up to +/- 360° per second of rotation and the rotation rate can be
read up to approximately 300 times per second.
For more detailed information about Gyro Sensor,
please visit HiTechnic Web
site.
HiTechnic Gyro Sensor
API |
Description |
U16 |
gets Gyro Sensor raw A/D data. The sensor data has offset value (approximately 600). Parameters: |
NXT acquires direction and intesity data from the HiTechnic
IR Seeker (NSK1042) via I2C
communication. However, actual data transaction between the ARM7 and
the IR Seeker is done by an ISR triggered by a function call, so there is
one execution cycle delay to achieve consistent data
acquisition. For more detailed
information about IR Seeker, please visit HiTechnic Web site.
HiTechnic IR Seeker
API |
Description |
void |
initializes a port for I2C communication for IR Seeker. This function should be implemented in the device initialize hook routine. Parameters: |
void |
gets direction and intensity data. Parameters: |
void |
terminates I2C communication used for IR Seeker. This function should be implemented in the device terminate hook routine. Parameters: |
NXT acquires magnetic heading in degree from the HiTechnic
Compass Sensor (NMC1034) via I2C
communication. However, actual data transaction between the ARM7 and
the Compass Sensor is done by an ISR triggered by a function call, so
there is one execution cycle delay to achieve consistent data
acquisition. For more detailed
information about Compass Sensor, please visit HiTechnic Web site.
HiTechnic Compass Sensor
API |
Description |
void |
initializes a port for I2C communication for Compass Sensor. This function should be implemented in the device initialize hook routine. Parameters: |
void |
calibrates the Compass Sensor. There is a
detailed description about calibration of the Compass Sensor at HiTechnic Web site. |
S16 |
gets magnetic heading in degree(0 to 359). South is 180 degrees. Parameters: |
void |
terminates I2C communication used for Compass Sensor. This function should be implemented in the device terminate hook routine. Parameters: |
NXT
acquires Red/Green/Blue color raw data from the HiTechnic Color Sensor (NCO1038) via I2C
communication. However, actual data transaction between the ARM7 and
the Color Sensor is done by an ISR triggered by a function call, so there
is one execution cycle delay to achieve consistent data
acquisition. For more detailed
information about Color Sensor, please visit HiTechnic Web site.
HiTechnic Color Sensor
API |
Description |
void |
initializes a port for I2C communication for the Color Sensor. This function should be implemented in the device initialize hook routine. Parameters: |
void |
gets Red/Green/Blue color raw data. Parameters: |
void |
terminates I2C communication used for the Color Sensor. This function should be implemented in the device terminate hook routine. Parameters: |
NXT communicates with a HiTechnic Prototype Sensor (NPS1055) via I2C communication. However, actual data transaction between the ARM7 and
the Prototype Sensor is done by an ISR triggered by a function call,
so there is one execution cycle delay to achieve consistent data
acquisition. For more detailed
information about the Prototype Sensor, please visit HiTechnic
Web site.
HiTechnic Prototype
Sensor API |
Description |
void |
initializes a port for I2C communication for the Prototype Sensor. This function should be implemented in the device initialize hook routine. Parameters: |
void |
gets the Prototype Sensor analog data. Parameters: |
U8 |
gets the Prototype Sensor digital data. Parameters: |
void |
sends the Prototype Sensor digital data. Parameters: |
void |
terminates I2C communication used for the Prototype Sensor. This function should be implemented in the device terminate hook routine. Parameters: |
RCX Active Sensor
API |
Description |
void |
supplies power source to RCX Active Sensor. This function should be implemented in the device initialize hook routine. Parameters: |
S16 ecrobot_get_RCX_sensor(U8 port_id) |
gets RCX Active Sensor raw data. Parameters: |
void ecrobot_term_RCX_power_source(U8 port_id) |
stops power source to RCX Active Sensor. This function should be implemented in the device terminate hook routine. Parameters: |
RCX Touch Sensor is compatible with
NXT A/D Sensors such as NXT Touch Sensor. This API is implemend to just
dinstiguish those RCX/NXT Touch Sensors. (ecrobot_get_touch_sensor also
could be used to access RCX Touch Sensor)
RCX Touch Sensor
API |
Description |
U8 |
gets Touch Sensor
status.
Parameters: |
nxtOSEK provides 3 hook routines
for user. These hook routines have to be defined in the user code.
ecrobot_main.c file of NXTway sample is useful to understand how to use
these hook routines.
|
|
|