77
15-9-2015 1 HTHT Science 2 Society Minor Module 1: From Idea to Prototype Robotics: NXT, Programming Prof. Frank van der Velde Cognitive Psychology & Ergonomics (CPE) CTIT

Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Embed Size (px)

Citation preview

15-9-2015 1

HTHT Science 2 Society Minor Module 1: From Idea to Prototype

Robotics: NXT, Programming

Prof. Frank van der Velde

Cognitive Psychology

& Ergonomics (CPE)

CTIT

Overview

2

Mindstorms NXT 2.0: • Robot types • Programming • Installation

21 September: Ing Fjodor van Slooten will give a hands-on lecture on the NXT IO (Application Development and Design) Horstring Noord, N208 ([email protected]) (This lecture is strongly based on his presentations) At another time: Dr. Vicky Charisi will present a one-hour talk on child-robot interaction.

What is Lego Mindstorms NXT 2.0?

Technical Lego + “Computer” + Sensors + Actuators

Different robot types possible

3

Brick

Lego Brick NXT

Ports for motors

Ports for sensors

4

Lego Brick NXT

5

256 Kb memory Display 100x64 Speaker

Lego Brick NXT

6

Battery: will be empty Charge battery at least 30 min Continue charging battery during session.

Sensors NXT

Licht sensor Detects light intensity environment And reflection infrared sender

Ultrasonic sensor Determines distances with ultrasound waves

Sound sensor Records sound level (not microphone!)

Touch sensor Responds to: Pressing Release Touch

7

start

Ultrasonic sensor NXT

8

Ultrasonic sensor does not always operate on port 4! Sensor value is visible when

NXT is linked.

Color sensors NXT

9

Lego ColorSensor

HiTechnicColorSensor

RGB

Servo Motors NXT

Tachometer for build-in Rotation

Sensor Motor core Build-in gearing

Attaching a wheel

10

Programming NXT

Drag and drop programming 11

Programming NXT

Drag and drop programming 12

Common: • Move • Record/Play • Sound • Display • Wait • Loop • Switch

Programming NXT

Drag and drop programming 13

Action: • Motor • Sound • Display • Send message • Color lamp

Programming NXT

Drag and drop programming 14

Sensor: • Touch • Sound • Light • Ultrasonic • NXT button • Rotation • Timer • Receive message • Color sensor

Programming NXT

Drag and drop programming 15

Flow: • Wait • Loop • Switch • Stop

Programming NXT

Drag and drop programming 16

Data: • Logic • Math • Compare • Range • Random • Variable • Constant

Programming NXT

Drag and drop programming 17

Advanced: • Number to text • Text • Keep alive • File access • Calibrate • Reset motor • Bluetooth connection

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Configuration screen:

start

Textual commentary: what program is doing (do this!) 18

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Configuration screen:

start Wait 2 sec

19

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

start Wait 2 sec

Configuration screen:

Move forward

20

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

start Wait 2 sec

Configuration screen:

Move forward Move backward

21

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

start Wait 2 sec Move forward Move backward

Store program

22

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Transferring program to brick (PC and NXT need to be linked)

Using either: • USB • Bluetooth

Download and start program

23

Stop

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Repeating program parts is usually not good programming!

Repeat program 3 times:

24

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Instead, use a ‘loop’ by inserting repeat block

Configuration screen:

25

Programming NXT

Help gives information on programming

26

27

Programming NXT Example: present sensor values on screen

• (Light) sensor block • Number-to-Text block • Display block

Then: Connection with Data Wire

After that: place in Loop

28

Programming NXT Example: present sensor values on screen

Loop (Infinite)

Complete palette

29

Programming NXT Example: move along wall

Steering parameter gets result calculation

First:

Robot moves straight ahead?

Tip: drive slowly, need time for processing sensor information.

NXT button

30

Programming NXT

Example: avoiding collision (Bumper car)

Yes: drive back a bit and make turn (try other direction)

Is Touch sensor pressed? Driving straight ahead

31

Programming NXT

Example: using NXT buttons

Switch block (conditional, if .. then)

Condition: True or False

True

False

32

Programming NXT

Example: wait until Enter button is pressed

33

Programming NXT

Example: using variables

Menu: Edit > Manage variables Variabele name, type

34

Programming NXT

Example: using variables

Advanced example

Decision: is TurnOn True?

Value variable enters Decision via data wire

TurnOn=False

MotorRunning=True

35

Programming NXT

Example: multiple tasks

• Tasks in sequence • Disadvantage: if something happens in one task, it could be ignored in other

Task 1 Task 2

Loop

36

Programming NXT

Example: multiple tasks

• Tasks simultanously • Disadvantage: programming more difficult • E.g., cannot just use same sensor • Solution: variables

Task 1

Task 2 Pull ends to make connections

37

Programming NXT

Example: using timer

There are 3 timers. Start with 0 at beginning of program

Have 5 sec passed?

Reset timer

Timer 1

38

Programming NXT

Example: using timer

Is someone gone for longer as 30 sec?

Task 1

Reset timer if close So, timer runs as long as far away

Keep repeating loop

39

Programming NXT

Example: using timer

Is someone gone for longer as 30 sec?

Task 1

Use result (logical) comparison to see if timer has ‘turned on’ (if 30 sec have passed)

Reset timer

Task 2 Keep repeating loop

Timer passed: play sound

and reset timer

Programming NXT

40

For using Lego software: Possibly Java firmware installed on NXT Install also Lego Firmware on NXT Zip-file, map lego\firmware\1.31 See INSTALLATIE.TXT

41

Programming NXT

More complicated and flexible programming: • Use programming language LeJOS. • Based on JAVA, suited for NXT

Software and documentation can be found on Website APPLICATIEBOUW http://module4.io.utwente.nl/applicatiebouw/

Lectures (Dutch)

Download

Programming NXT

43

Unpack zip file

See info:

Programming NXT

44

Unpack zip file

See info:

Building robots

45

Unpack zip file

See info:

Lego parts:

46

Unpack zip file

See info:

Working with Lego parts:

Lego parts: Box Box is owned by the UT. Use is carefully! Use lock for the box! Check content of box Fill in list: http://module4.io.utwente.nl/aftekenlijst/ If parts are missing: Mail Fjodor van Slooten

Building robots

Robot examples

47

Unpack zip file

See info:

Ultrasonic sensor: detects object

Instructions for building this robot

Sound sensor: reacts to commands

Touch sensor: detects object

between claws

Claws to grasp and transport

object

Light sensor: stay within area

Robot examples

48

Castor Bot

Instructions for building this robot: nxtprograms.com

Robot examples

49

Castor Bot

Instructions for building this robot: nxtprograms.com

Robot examples

50

Castor Bot

Instructions for building this robot: nxtprograms.com

Simple design

Extra sensors can be

added easily

Two separately

driving wheels

Assistance wheel

Robot examples

51

Robot Arm

Instructions for building this robot: nxtprograms.com

Robot examples

52

Instructions for building this robot: nxtprograms.com

Turns around

an axis

Moves up and down

Robot Gripper: Grabbing and moving object

Light sensor detects colour of object

Claw can open and close

Touch sensor detects presence of object

Robot examples

Information about robots can be found in: • In Lego software: building guides • Zip file Applicatiebouw • nxtprograms.com • Books (contact Fjodor van Slooten,

Horstring Noord, N208 ([email protected])

53

Installation of programmes

See: See: “Installatie” (For Mac and Windows) Windows: Start script install.bat by right clicking mouse. Choose Run as Administrator. You need the following programmes (in this order!) - Java Development Kit (JDK), 32 bits versie - Eclipse IDE for Java Developers, 32 bits versie - Lego Mindstorms NXT software - LeJOS - Eclipse plugin voor LeJOS

http://module4.io.utwente.nl/applicatiebouw/index.php?dir=download

54

Java Development Kit (JDK) Go to Unpacket Zip map To map 'Java'. Dubbelclick on: jdk-8u45-windows-i586.exe Wizard installs JDK and Java Runtime environment (JRE, version 8) Installation via Next (a number of times) Close

Installation of programmes

55

Installation of programmes

56

Eclipse: IDE

Installation of programmes

57

Eclipse: IDE

Eclipse can run without installation For this copy the folder Eclipse to: "C:\Program Files (x86)" or "C:\Program Files". Doubleclick on Eclipse to see its content Click on file “eclipse.exe”with right mousebutton Select "Send to > Desktop (create shortcut)"

Installation of programmes

58

Start Eclipse: First time program asks for making a Workspace Use your Documents folder "Make New folder". Give distinctive name eg. “EclipseWorkspace”. Activate option "Use this as the default ..." OK.

Installation of programmes

After OK:

59

You can click this away to start using Eclipse

Installation of programmes

60

Lego Mindstorms NXT software Start by activating setup.exe in folder 'Lego\LegoMindstorms2.0'. Ignore ‘wrong Windows-version’ or ‘lack of memory’ (continue with Next) After installation install 2 updates: Install first patch 2.0f3 in folder Lego\2.0f3_patch via setup.exe in that folder. Install latest version Lego Mindstorms NXT driver in folder Lego\driver_1.1.3 via setup.exe in that folder

Installation of programmes

61

LeJOS installation: Remove old version with uninstall.exe (then restart computer) Driver of Lego Mindstorms NXT must be installed (see previous slide) Installation of LeJOS: doubleclick leJOS_NXJ_0.9.1beta-3_win32_setup.exe in folder 'LeJOS' After Next select Java Development Kit. Select latest version (jdk1.7.0_51 or higher).

Installation of programmes

62

LeJOS installation: Location: standard Continue with Next

Installation of programmes

63

LeJOS installation: Select "Sample and Example Projects" Leave other options as they are Continue with Next.

Installation of programmes

LeJOS installation: In other screens leave it as it is. Continue with Next (a number of times) Press Install to start installation.

64

Installation of programmes

65

LeJOS installation: After installation start NXJ Flash utility by selecting "Launch NXJ Flash utility" Press Finish If LeJOS firmware is not on NXT, install with NXJ Flash utility: Connect NXT to computer and turn it on Wait until driver is installed. Press button 'Flash LeJOS firmware'. After 'Ok' en 'Yes' LeJOS firmware is installed on NXT More information (Dutch) In file TIPS.txt (in folder 'LeJOS‘)

Installation of programmes

Eclipse plugin for LeJOS Is ‘enclosed’ in Eclipse (based on ZIP-file Applicatiebouw) Hence installation of the plugin is not needed. Ckeck and control the options of the Eclipse plugin for LeJOS: Select in Eclipse: Window > Preferences from menu Then select "LeJOS NXJ". If under NXJ_HOME you find the folder where LeJOS geinstalleerd is installed, the plugin is fine.

66

Installation of programmes

Eclipse plugin for LeJOS Otherwise: Browse to find path to LeJOS (NXJ_HOME). This is folder where LeJOS is installed. Is usually: C:\Program Files\LeJOS NXJ or C:\Program Files (x86)\LeJOS NXJ

67

Installation of programmes

Eclipse plugin for LeJOS After installation you find the LeJOS icon in menu bar of Eclipse

68

New LeJOS project in Eclipse

See: http://www.lejos.org/nxt/nxj/tutorial/Preliminaries/UsingEclipse.htm

Go the "File" menu of Eclipse and select "New" and then "Project...""

69

New LeJOS project in Eclipse

See: http://www.lejos.org/nxt/nxj/tutorial/Preliminaries/UsingEclipse.htm

Then:

Two options:

70

New LeJOS project in Eclipse

This opens the wizard for creating new leJOS PC projects:

71

Enter name e.g., NewPCProject (but use more informative names for yourself) Press Finish

New LeJOS project in Eclipse

In Eclipse, you will see your new project: NewPCProject And JAR files from Libraries (JAR: Java Archive)

72

New LeJOS project in Eclipse

Right click the src folder and select "New" and then "Class" in the context menu

73

"Src“: folder where the project's source files are located. In a Java project, src folder and its sub folders hold the .java files.

New LeJOS project in Eclipse

This opens the wizard for creating new Java classes

74

Press Finish: Editor opens You can type in program

The package name com.mydomain (lowercase!) corresponds to the DNS domain "mydomain.com". Make sure to chose appropriate names.

Source folder name: NewPCProject

Package name (= namespace)

File name: HelloWorld

New LeJOS project in Eclipse

Example program ”HelloWorld.java”

75

Notice order: • package

• import (if any)

• class

• void main

Appear when opening file (except import) File name = class name + .java

New LeJOS project in Eclipse

Example program ”HelloWorld.java”

76

Run program: right-click on the class which contains the main method. Select "Run As"→"Java Application" in the context menu.

New LeJOS project in Eclipse

Example program ”HelloWorld.java”

77

Run program: Output on the local console in Eclipse.