Top Banner
[Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics [email protected] July 9 th 2008
34

[Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics [email protected].

Dec 28, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

[Low-level] Programming of NXT Robots

Pavel PetrovičDepartment of Applied Informatics, Faculty of Mathematics, Physics and Informatics

[email protected] July 9th 2008

Page 2: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

2

Welcome to world of LEGO

LEGO Geometry

Low-level Programming of NXT robots, July 9th 2008

Page 3: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

3

You can build everything...

Low-level Programming of NXT robots, July 9th 2008

Page 4: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

4

Programmable LEGO Manually programmable module in 1990

Low-level Programming of NXT robots, July 9th 2008

Page 5: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

5

Programmable LEGO TECHNIC Control Center 1993

Low-level Programming of NXT robots, July 9th 2008

Page 6: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

6

Programmable LEGO Control Lab Building Set 1995

Low-level Programming of NXT robots, July 9th 2008

Page 7: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

7

Programmable LEGO Code Pilot: programmed by sweeping

barcodes (1997)

Low-level Programming of NXT robots, July 9th 2008

Page 8: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

8

Programmable LEGO LEGO Mindstorms RCX

(1998) 8-bit microcontroller

Hitachi H8/300, 32kb RAM

AUTONOMOUS Excellent tool for

teaching basics of robotics, embedded systems, etc. at all levels

Low-level Programming of NXT robots, July 9th 2008

Page 9: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

9

Programming RCX Robotics Invention System – event based,

icons, visual, educational RoboLab – educational, visual, flow-chart

based NQC – C-like language translated to bytecodes Lejos – Java-like language BrickOS – GNU C/C++ compiler – produces

fast binary code, full flexibility of C language Many others...

Low-level Programming of NXT robots, July 9th 2008

Page 10: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

10

LEGO Mindstorms NXT (2006)

32-bit ARM7 microcontroller AT91SAM7S256 256 KB Flash 64 KB RAM BlueTooth, USB, I2C, high speed IEC 61158 Type 4/EN 50 170 100 x 64 graphical LCD, better sensors, motors

Programmable LEGO

Low-level Programming of NXT robots, July 9th 2008

Page 11: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

11

Built-in rotation sensors

NXT Motors

Low-level Programming of NXT robots, July 9th 2008

Page 12: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

12

Much stronger

NXT Motors

Low-level Programming of NXT robots, July 9th 2008

Page 13: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

13

Light sensor

NXT Sensors

Low-level Programming of NXT robots, July 9th 2008

Page 14: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

14

Touch sensor

NXT Sensors

Low-level Programming of NXT robots, July 9th 2008

Page 15: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

15

Sound sensor

NXT Sensors

Low-level Programming of NXT robots, July 9th 2008

Page 16: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

16

Ultrasonic distance sensor

NXT Sensors

Low-level Programming of NXT robots, July 9th 2008

Page 17: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

17

NXT Non-standard sensors: HiTechnic.com

Low-level Programming of NXT robots, July 9th 2008

Compass, Accellerometer, Gyroscope, Color, IRSeeker, …

Page 18: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

18

Master-slave: only master initiates communication

Master can connect up to 3 slaves Optional acknowledgement, request reply Mailboxes #1-10 Sending:

Master: NXTCommBTWrite(slave, mailbox) Slave: NXTMessageWrite(mailbox)

Receiving: both sides NXTMessageRead() Unreliable & Quite complex, but does not block

NXT BlueTooth Protocol

Low-level Programming of NXT robots, July 9th 2008

Silvian Toledo: http://www.tau.ac.il/~stoledo/lego/btperformance.html

Page 19: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

19

Programming NXT

Low-level Programming of NXT robots, July 9th 2008

Page 20: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

20

Programming NXT

Low-level Programming of NXT robots, July 9th 2008

Page 21: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

21

Programming NXT

Low-level Programming of NXT robots, July 9th 2008

Page 22: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

22

Standard Software NXT-G

Low-level Programming of NXT robots, July 9th 2008

Page 23: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

23

LEGO Digital Designer ldd.lego.com

Low-level Programming of NXT robots, July 9th 2008

Page 24: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

24

Not eXactly C (NXC)

Low-level Programming of NXT robots, July 9th 2008

Derivative of NQC for RCX by John Hansen BricX IDE Excellent tools and features C-like language with good documentation http://bricxcc.sourceforge.net/nbc/ NXT Power Programming book

Page 25: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

25

NXC example: line-following

Low-level Programming of NXT robots, July 9th 2008

int s;task main(){ SetSensorType(S1, SENSOR_TYPE_LIGHT_ACTIVE); SetSensorMode(S1, SENSOR_MODE_PERCENT); ResetSensor(S1); while (1) { if (Sensor(S1) < 48) { OnFwd(OUT_A, 75); Float(OUT_C); } else { OnFwd(OUT_C, 75); Float(OUT_A); } }}

Page 26: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

26

Java programming for NXT

Low-level Programming of NXT robots, July 9th 2008

iCommand – 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

Page 27: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

27

NXT Logo

Low-level Programming of NXT robots, July 9th 2008

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

Page 28: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

28

NXT Logo example: line-following

Low-level Programming of NXT robots, July 9th 2008

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 ]]

Page 29: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

29

Issues of the standard firmware

Low-level Programming of NXT robots, July 9th 2008

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

Page 30: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

30

Architecture of Standard Firmware

Low-level Programming of NXT robots, July 9th 2008

Scheduler + modules Each module:

Init() Ctrl() Exit()

Scheduler periodically calls Ctrl() on all the modules

Method1: design a new module Method2: call your code from Ctrl() function of

some module Programming Concept: STATE MACHINE

Page 31: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

31

Modifying standard firmware

Low-level Programming of NXT robots, July 9th 2008

cUiMenuCallFunction(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 cCmdCtrl(void), check the global flag: if (run_example) example(); Implement the example() function as state machine All standard functions available + direct C coding!

Page 32: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

32Low-level Programming of NXT robots, July 9th 2008

void example(){ static int example_state = 0; static ULONG x; if (example_state == 0) { cDebugString2("example", 0, 5); dOutputSetSpeed(1, MOTOR_RUN_STATE_RUNNING, 75, 1); x = dTimerRead(); example_state ++; } else if (example_state == 1) { if (dTimerRead() - x > 1000) example_state = 2; } else if (example_state == 2) { dOutputSetSpeed(0, MOTOR_RUN_STATE_IDLE, 0, 0); cDebugString2("done", 0, 5); example_state = 0; run_example = 0; }}

Page 33: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

33

Sources of Information

Low-level Programming of NXT robots, July 9th 2008

LEGO Official documentation http://mindstorms.lego.com/Overview/NXTreme.aspx NXT Firmware Open Source Software Developer Kit (SDK) Hardware Developer Kit (HDK) Bluetooth Developer Kit (BDK)

HiTechnic.com LUGNET.com

Page 34: [Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics ppetrovic@acm.org.

34

Workshop

Low-level Programming of NXT robots, July 9th 2008

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