Lego Mindstorms and NXTG Magnus Eriksson Mid Sweden

  • Slides: 55
Download presentation
Lego Mindstorms and NXT-G Magnus Eriksson, Mid Sweden University 2012 Based on a presentations

Lego Mindstorms and NXT-G Magnus Eriksson, Mid Sweden University 2012 Based on a presentations by National Instruments and Pavel Petrovič

Först några påminnelser… • Bråttom att registrera sig! (Portal. miun. se) • Kursmaterial finns

Först några påminnelser… • Bråttom att registrera sig! (Portal. miun. se) • Kursmaterial finns i Lärplattformen 2 (Moodle), som du hittar via portal. miun. se • Kursens deadlines framgår av schemat

Lego Mindstorms can be used for rapid prototyping of intelligent and sensorbased systems Rubik’s

Lego Mindstorms can be used for rapid prototyping of intelligent and sensorbased systems Rubik’s cube solver 3

Pen-Drawer Robot

Pen-Drawer Robot

The NXT 2. 0 unit (Motor ports) (Sensor ports)

The NXT 2. 0 unit (Motor ports) (Sensor ports)

Motors and Sensors

Motors and Sensors

NXT Motors • Built-in rotation sensors (“servo”) 7

NXT Motors • Built-in rotation sensors (“servo”) 7

The NXT 2. 0 Unit – an embedded system • 64 K RAM, 256

The NXT 2. 0 Unit – an embedded system • 64 K RAM, 256 K Flash • 32 -bit ARM 7 microcontroller • 100 x 64 pixel LCD graphical display • Sound channel with 8 -bit resolution • Bluetooth wireless communications • Stores multiple programs – Programs selectable using buttons

NXT-G graphical programming language Based on the Lab. VIEW programming language G Program by

NXT-G graphical programming language Based on the Lab. VIEW programming language G Program by drawing a flow chart LEGO Mindstorms for NXT (NXT-G)

NXT-G PC program interface Tutorials Toolbar Workspace Sequence Beam Palettes Controller Configuration Panel Help

NXT-G PC program interface Tutorials Toolbar Workspace Sequence Beam Palettes Controller Configuration Panel Help & Navigation Web Portal

NXT-G tools • Pointer tool: move blocks, select blocks • Pan tool: move within

NXT-G tools • Pointer tool: move blocks, select blocks • Pan tool: move within workspace • Comment tool: add notes to your code

Intro to NXT-G: Palettes Common: Complete: Most commonly used blocks All blocks Custom: Downloa

Intro to NXT-G: Palettes Common: Complete: Most commonly used blocks All blocks Custom: Downloa Own blocks

Writing a Basic Program • Drag and drop block(s) on sequence beam • Manipulate

Writing a Basic Program • Drag and drop block(s) on sequence beam • Manipulate Configuration Panel & Download

Intro to NXT-G: Controller Download & Run Selection NXT Window Stop Download & Run

Intro to NXT-G: Controller Download & Run Selection NXT Window Stop Download & Run

NXT Rotation Sensor • Built in to motors • Measure degrees or rotations •

NXT Rotation Sensor • Built in to motors • Measure degrees or rotations • Reads + and • Degrees: accuracy +/- 1 • 1 rotation = 360 degrees

Viewing Sensors • • • Connect sensor Turn on NXT Choose “View” Select sensor

Viewing Sensors • • • Connect sensor Turn on NXT Choose “View” Select sensor type Select port

NXT Sound Sensor • Sound sensor can measure in d. B and d. BA

NXT Sound Sensor • Sound sensor can measure in d. B and d. BA – d. B: in detecting standard [unadjusted] decibels, all sounds are measured with equal sensitivity. Thus, these sounds may include some that are too high or too low for the human ear to hear. – d. BA: in detecting adjusted decibels, the sensitivity of the sensor is adapted to the sensitivity of the human ear. In other words, these are the sounds that your ears are able to hear. • Sound Sensor readings on the NXT are displayed in percent [%]. The lower the percent the quieter the sound. http: //mindstorms. lego. com/Overview/Sound_Sensor. aspx

Challenge: Stop with sound • Program your NXT car to drive until you yell

Challenge: Stop with sound • Program your NXT car to drive until you yell “Stop”

Example Program: Stop with Sound

Example Program: Stop with Sound

NXT Ultrasonic/Distance Sensor • Measures distance/proximity • Range: 0 -255 cm • Precision: +/-

NXT Ultrasonic/Distance Sensor • Measures distance/proximity • Range: 0 -255 cm • Precision: +/- 3 cm • Can report in centimeters or inches http: //mindstorms. lego. com/Overview/Ultrasonic_Sensor. aspx

Challenge: Parking NXT • Program your NXT car to drive forward until you “find

Challenge: Parking NXT • Program your NXT car to drive forward until you “find a parking spot” (hit a touch sensor) • The car should then turn into the spot, and stop when it gets close enough to wall.

Example Program: Parking NXT

Example Program: Parking NXT

A note about NXT memory • Memory space is limited! • To clear space,

A note about NXT memory • Memory space is limited! • To clear space, use NXT window • Show and delete system files for more space

NXT Structure: Loops

NXT Structure: Loops

Challenge: Stay on Table • Program your NXT to stay on the table

Challenge: Stay on Table • Program your NXT to stay on the table

Example Program: Stay on Table

Example Program: Stay on Table

NXT Structure: Switch

NXT Structure: Switch

Challenge: Remote Control • Program car to drive while the touch sensor is pushed

Challenge: Remote Control • Program car to drive while the touch sensor is pushed and stop while the touch sensor is released

Example Program: Remote Control

Example Program: Remote Control

NXT Sound • NXT can play sound files or notes • Sounds take up

NXT Sound • NXT can play sound files or notes • Sounds take up more memory space

 • • NXT Display images, text, or drawings Choose location on display screen

• • NXT Display images, text, or drawings Choose location on display screen 100 x 64 pixels (up to 7 lines of text) Graphics take up memory space

Challenge: Say Hello • Have the NXT say hello using sound and the display

Challenge: Say Hello • Have the NXT say hello using sound and the display screen • Don’t forget – the program ends after the last block. You may need a wait for to see the display. • Caution: one of the options in the configuration panel is Clear – use it to clear screen. Otherwise, uncheck the box!

Example Program: Say Hello

Example Program: Say Hello

My Blocks • Create custom blocks • Saved in custom palette • Download blocks

My Blocks • Create custom blocks • Saved in custom palette • Download blocks from the web

Creating My Blocks • Write the code for the My Block

Creating My Blocks • Write the code for the My Block

Creating My Blocks • Select all the blocks to be used for My Block

Creating My Blocks • Select all the blocks to be used for My Block

Creating My Blocks • Choose “Create My Block” on toolbar • Or, go to

Creating My Blocks • Choose “Create My Block” on toolbar • Or, go to the Edit menu and select “Make a new My Block”

Creating My Blocks • Name My Block • Add a description

Creating My Blocks • Name My Block • Add a description

Creating My Blocks • Create a custom icon

Creating My Blocks • Create a custom icon

Creating My Blocks • My Block appears in Custom Palette

Creating My Blocks • My Block appears in Custom Palette

Signal flows and variables

Signal flows and variables

An advanced program 42

An advanced program 42

Multi-treading 43

Multi-treading 43

LEGO Mindstorms 3. 0 EV 3

LEGO Mindstorms 3. 0 EV 3

Getting started with mindstorms EV 3 https: //www. youtube. com/watch? v=vv 5 X 3

Getting started with mindstorms EV 3 https: //www. youtube. com/watch? v=vv 5 X 3 zzk. Bk 4

NXT Blue. Tooth Protocol • • • Master-slave: only master initiates communication Master can

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 46

LEGO Digital Designer ldd. lego. com CAD-verktyg – Eventuellt för Civing Teknisk design 47

LEGO Digital Designer ldd. lego. com CAD-verktyg – Eventuellt för Civing Teknisk design 47

Pneumatics För Civing Teknisk design 48

Pneumatics För Civing Teknisk design 48

NXT Non-standard sensors: Hi. Technic. com För Elektroniksystemstudenter • Compass • Gyroscope • Accellerometer/tilt

NXT Non-standard sensors: Hi. Technic. com För Elektroniksystemstudenter • Compass • Gyroscope • Accellerometer/tilt sensor, • Color sensor • IRSeeker • Prototype board with A/D converter 49 for the I 2 C bus

Issues of the standard firmware Only one data type Unreliable bluetooth communication Limited multi-tasking

Issues of the standard firmware Only one data type Unreliable bluetooth communication Limited multi-tasking Complex motor control Simplistic memory management Not suitable for large programs Not suitable for development of own tools or blocks För datateknikstudenter 50

Other programming languages and environments – Java le. JOS – Microsoft Robotics Studio –

Other programming languages and environments – Java le. JOS – Microsoft Robotics Studio – Robot. C – NXC - Not e. Xactly C – NXT Logo – Lego NXT Open source firmware and software development kit För datateknikstudenter

le. JOS • A Java Virtual Machine for NXT • Freely available – http:

le. JOS • A Java Virtual Machine for NXT • Freely available – http: //lejos. sourceforge. net/ • Replaces the NXT-G firmware • Le. JOS plug-in is available for the Eclipse free development environment • Faster than NXT-G För datateknikstudenter

Example le. JOS Program sonar = new Ultrasonic. Sensor(Sensor. Port. S 4); Motor. A.

Example le. JOS Program sonar = new Ultrasonic. Sensor(Sensor. Port. S 4); Motor. A. forward(); Motor. B. forward(); while (true) { if (sonar. get. Distance() < 25) { Motor. A. forward(); Motor. B. backward(); } else { Motor. A. forward(); Motor. B. forward(); } } För datateknikstudenter

NXT Logo example: line-following to "follow [] [ setsensor 3 5 128 motor 0

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 ] ] För datateknikstudenter 54

Gruppindelning

Gruppindelning