Upload
alexandro-huish
View
217
Download
2
Tags:
Embed Size (px)
Citation preview
Lego Mindstorms and NXT-G
Magnus Eriksson, Mid Sweden University 2012Based 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 i Lärplattformen 2
(Moodle), som du hittar via portal.miun.se • Projektgrupperna kommer att ändras lite -
högst 7 studenter i varje• Kursens deadlines framgår av schemat• Börja fundera på en intelligent produkt med
realistisk marknad redan nu!
3
Lego Mindstorms can be used for rapid prototyping of intelligent and
sensor-based systems
Rubik’s cubesolver
The NXT2.0 Unit – an embedded system
• 64K RAM, 256K Flash• 32-bit ARM7 microcontroller• 100 x 64 pixel LCD graphical
display• Sound channel with 8-bit
resolution• Bluetooth wireless
communications • Stores multiple programs
– Programs selectable using buttons
LEGO Mindstorms for NXT
(NXT-G)
NXT-G graphical programming language
Based on the LabVIEW programming language GProgram by drawing a flow chart
NXT-G PC program interface
Toolbar
Workspace
Configuration Panel
Help & Navigation
ControllerPalettes
Tutorials
Web Portal
Sequence Beam
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: Custom:Most All blocks Downloa Own blockscommonlyused blocks
Writing a Basic Program• Drag and drop block(s) on sequence beam
• Manipulate Configuration Panel & Download
NXT Rotation Sensor
• Built in to motors• Measure degrees
or rotations• Reads + and -• Degrees: accuracy
+/- 1• 1 rotation =
360 degrees
NXT Sound Sensor• Sound sensor can measure in dB and dBA
– dB: 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.
– dBA: 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
NXT Ultrasonic/Distance Sensor
• Measures distance/proximity
• Range: 0-255 cm• Precision: +/- 3cm• 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 a parking spot” (hit a touch sensor)
• The car should then turn into the spot, and stop when it gets close enough to wall.
A note about NXT memory• Memory space is limited!• To clear space, use NXT window• Show and delete system files for more space
Challenge: Remote Control
• Program car to drive while the touch sensor is pushed and stop while the touch sensor is released
NXT Display• 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 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!
Creating My Blocks• Choose “Create My Block” on toolbar• Or, go to the Edit menu and select “Make a
new My Block”
Getting started with mindstorms EV3
https://www.youtube.com/watch?v=vv5X3zzkBk4
46
• 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
Silvian Toledo: http://www.tau.ac.il/~stoledo/lego/btperformance.html
49
NXT Non-standard sensors: HiTechnic.com
• Compass• Gyroscope• Accellerometer/tilt sensor, • Color sensor• IRSeeker• Prototype board with A/D converter
for the I2C bus För Elektroniksystemstudenter
50
Issues of the standard firmware
För datateknikstudenter
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
Other programming languages and environments
– Java leJOS– Microsoft Robotics Studio– RobotC – NXC - Not eXactly C– NXT Logo– Lego NXT Open source firmware and software
development kit
För datateknikstudenter
leJOS
• A Java Virtual Machine for NXT• Freely available
– http://lejos.sourceforge.net/• Replaces the NXT-G firmware• LeJOS plug-in is available for the Eclipse free
development environment• Faster than NXT-G
För datateknikstudenter
Example leJOS Programsonar = new UltrasonicSensor(SensorPort.S4);Motor.A.forward();Motor.B.forward();while (true) { if (sonar.getDistance() < 25) { Motor.A.forward(); Motor.B.backward(); } else { Motor.A.forward(); Motor.B.forward(); } }
För datateknikstudenter
54
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