Lowlevel Programming of NXT Robots Pavel Petrovi Department
[Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm. org July 9 th 2008
Welcome to world of LEGO Geometry Low-level Programming of NXT robots, July 9 th 2008 2
You can build everything. . . Low-level Programming of NXT robots, July 9 th 2008 3
Programmable LEGO Manually programmable module in 1990 Low-level Programming of NXT robots, July 9 th 2008 4
Programmable LEGO TECHNIC Control Center 1993 Low-level Programming of NXT robots, July 9 th 2008 5
Programmable LEGO Control Lab Building Set 1995 Low-level Programming of NXT robots, July 9 th 2008 6
Programmable LEGO Code Pilot: programmed by sweeping barcodes (1997) Low-level Programming of NXT robots, July 9 th 2008 7
Programmable LEGO Mindstorms RCX (1998) 8 -bit microcontroller Hitachi H 8/300, 32 kb RAM AUTONOMOUS Excellent tool for teaching basics of robotics, embedded systems, etc. at all levels Low-level Programming of NXT robots, July 9 th 2008 8
Programming RCX Robotics Invention System – event based, icons, visual, educational Robo. Lab – educational, visual, flow-chart based NQC – C-like language translated to bytecodes Lejos – Java-like language Brick. OS – GNU C/C++ compiler – produces fast binary code, full flexibility of C language Many others. . . Low-level Programming of NXT robots, July 9 th 2008 9
Programmable LEGO Mindstorms NXT (2006) 32 -bit ARM 7 microcontroller AT 91 SAM 7 S 256 KB Flash 64 KB RAM Blue. Tooth, USB, I 2 C, high speed IEC 61158 Type 4/EN 50 170 100 x 64 graphical LCD, better sensors, motors Low-level Programming of NXT robots, July 9 th 2008 10
NXT Motors Built-in rotation sensors Low-level Programming of NXT robots, July 9 th 2008 11
NXT Motors Much stronger Low-level Programming of NXT robots, July 9 th 2008 12
NXT Sensors Light sensor Low-level Programming of NXT robots, July 9 th 2008 13
NXT Sensors Touch sensor Low-level Programming of NXT robots, July 9 th 2008 14
NXT Sensors Sound sensor Low-level Programming of NXT robots, July 9 th 2008 15
NXT Sensors Ultrasonic distance sensor Low-level Programming of NXT robots, July 9 th 2008 16
NXT Non-standard sensors: Hi. Technic. com Compass, Accellerometer, Gyroscope, Color, IRSeeker, … Low-level Programming of NXT robots, July 9 th 2008 17
NXT Blue. Tooth Protocol Master-slave: only master initiates communication Master can connect up to 3 slaves Optional acknowledgement, request reply Mailboxes #1 -10 Sending: Master: NXTComm. BTWrite(slave, mailbox) Slave: NXTMessage. Write(mailbox) Receiving: both sides NXTMessage. Read() Unreliable & Quite complex, but does not block Silvian Toledo: http: //www. tau. ac. il/~stoledo/lego/btperformance. html Low-level Programming of NXT robots, July 9 th 2008 18
Programming NXT Low-level Programming of NXT robots, July 9 th 2008 19
Programming NXT Low-level Programming of NXT robots, July 9 th 2008 20
Programming NXT Low-level Programming of NXT robots, July 9 th 2008 21
Standard Software NXT-G Low-level Programming of NXT robots, July 9 th 2008 22
LEGO Digital Designer ldd. lego. com Low-level Programming of NXT robots, July 9 th 2008 23
Not e. Xactly C (NXC) Derivative of NQC for RCX by John Hansen Bric. X IDE Excellent tools and features C-like language with good documentation http: //bricxcc. sourceforge. net/nbc/ NXT Power Programming book Low-level Programming of NXT robots, July 9 th 2008 24
NXC example: line-following int s; task main() { Set. Sensor. Type(S 1, SENSOR_TYPE_LIGHT_ACTIVE); Set. Sensor. Mode(S 1, SENSOR_MODE_PERCENT); Reset. Sensor(S 1); while (1) { if (Sensor(S 1) < 48) { On. Fwd(OUT_A, 75); Float(OUT_C); } else { On. Fwd(OUT_C, 75); Float(OUT_A); } } } Low-level Programming of NXT robots, July 9 th 2008 25
Java programming for NXT i. Command – direct command mode Lejos Object oriented language Preemptive threads Arrays, including multi-dimensional Recursion Synchronization Exceptions Java types including float, long, and String Most of the java. lang, java. util and java. io classes A Well-documented Robotics API Low-level Programming of NXT robots, July 9 th 2008 26
NXT Logo Combines the power of educational programming language Logo with robots wiki. robotika. sk/index. php/Logo_for_NXT 1. Interactive Imagine Logo project 2. Loadable imagine library (nxt. imt) 3. Interpreter of Logo 4. Stand-alone Low-level Programming of NXT robots, July 9 th 2008 27
NXT Logo example: line-following to "follow [] [ setsensor 3 5 128 motor 0 "onrev 40 while ["true] [ while [ge? sensor 3 59] [] motor 0 "float 0 motor 2 "onrev 40 wait 50 while [lt? sensor 3 60] [] motor 2 "float 0 motor 0 "onrev 40 ] ] Low-level Programming of NXT robots, July 9 th 2008 28
Issues of the standard firmware Limited multi-tasking Complex motor model Simplistic memory management Not suitable for development of tools Design your own firmware! NXT GCC project http: //nxtgcc. sourceforge. net/ Approach: Take the standard firmware and modify it Low-level Programming of NXT robots, July 9 th 2008 29
Architecture of Standard Firmware Scheduler + modules Each module: Init() Ctrl() Exit() Scheduler periodically calls Ctrl() on all the modules Method 1: design a new module Method 2: call your code from Ctrl() function of some module Programming Concept: STATE MACHINE Low-level Programming of NXT robots, July 9 th 2008 30
Modifying standard firmware c. Ui. Menu. Call. Function(Function, Parameter) is called when user presses button to trigger various functions, set a global flag: if ((Function == 8) && (Parameter == 248)) run_example = 1; In c. Cmd. Ctrl(void), check the global flag: if (run_example) example(); Implement the example() function as state machine All standard functions available + direct C coding! Low-level Programming of NXT robots, July 9 th 2008 31
void example() { static int example_state = 0; static ULONG x; if (example_state == 0) { c. Debug. String 2("example", 0, 5); d. Output. Set. Speed(1, MOTOR_RUN_STATE_RUNNING, 75, 1); x = d. Timer. Read(); example_state ++; } else if (example_state == 1) { if (d. Timer. Read() - x > 1000) example_state = 2; } else if (example_state == 2) { d. Output. Set. Speed(0, MOTOR_RUN_STATE_IDLE, 0, 0); c. Debug. String 2("done", 0, 5); example_state = 0; run_example = 0; } } Low-level Programming of NXT robots, July 9 th 2008 32
Sources of Information LEGO Official documentation Hi. Technic. com LUGNET. com http: //mindstorms. lego. com/Overview/NXTreme. aspx NXT Firmware Open Source Software Developer Kit (SDK) Hardware Developer Kit (HDK) Bluetooth Developer Kit (BDK) Low-level Programming of NXT robots, July 9 th 2008 33
Workshop Today & tomorrow afternoon 7 NXT bricks available Hands-on creative exercise Build and program the robot in your favourite environment, preferably modify the firmware Welcome & Thank you for the attention Low-level Programming of NXT robots, July 9 th 2008 34
- Slides: 34