+ All Categories
Home > Documents > 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer...

1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer...

Date post: 26-Mar-2015
Category:
Upload: jennifer-carlson
View: 215 times
Download: 0 times
Share this document with a friend
Popular Tags:
54
1 chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University [email protected] www.Robofest.net
Transcript
Page 1: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

1chung

Robofest 2007 NXT

Programming Workshop

Jan. 27, 2007

CJ ChungAssociate Professor of Computer Science

Lawrence Tech [email protected]

Page 2: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

2chung

Assistant

• Joe Long

Page 3: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

3chung

Agenda• Intro to NXT• Construction of NXT basic model:

TriBot• Intro to NXT programming

Language: Move, Loop, Sensors, Wait, Display, Switches, and My Blocks

• 9 Class Missions (somewhat related to the Robofest Game 2007, Miner Rescue)

• Programming Tips

Page 4: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

4chung

Page 5: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

5chung

Robots to be used: TriBot

• Robo Center, Quick Start Vehicle or small booklet in the retail version box

• Left motor: A• Right motor: C

Page 6: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

6chung

Alternative guide to build the TriBot (Retail Version)• Launch the software, Mindstorms NXT • Robo Center -> Vehicles Quick Start -> TriBot

Go -> Driving Base

Page 7: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

7chung

Software Installation

• Usually be positive! Yes, Yes, Yes,…• After the installation you will see

the following icon on your desktop

Page 8: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

8chung

Exercise 0 (First NXT program): Go forward for 2 sec. and stop (1/3)• Let’s name the

program first• Click on Go >>

button• You’ll see a

programming palette

Page 9: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

9chung

First NXT program: Go forward for 2 sec. and stop (2/3)

• Click on Move button• Drag and drop the move

block to the canvas

A C

Page 10: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

10chung

First NXT program: Go forward for 2 sec. and stop (3/3)• Change parameters for the

Move Port Direction Steering Power Duration Next Action

Block

Configuration Panel

Page 11: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

11chung

How to run your 1st program (1/2)

Page 12: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

12chung

How to run your 1st program (2/2)• If “Found New Hardware”

pops up, just follow the instruction

• Click on “Download” button• Recommended to un-plug the

cable from the bot• Press the orange button 4

times (Turn on, My files, Software files, Run your program entitled go2stop)

Page 13: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

13chung

How to rerun the program

• Check the program name on the LCD

• Press the orange button just once again

Page 14: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

14chung

Just watch: Go forward for 2 rotations and come back by reversing motors

Page 15: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

15chung

Ex 1: Go forward 720 degrees and come back by reversing motors

Page 16: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

16chung

NXT motors

Page 17: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

17chung

Embedded Rotation Sensor

•Each motor has an embedded rotation sensor

•360 counts per rotation•The counter can be incremented or

decremented•Distance traveled for a rotation of a

wheel can be calculated: Circumference = 2 x radius x π

Page 18: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

18chung

Find out the distance a rotation of the wheels will travel (metric)•Method 1: Write a program to go

for a rotation then measure the distance: almost 17cm

•Method 2 Measure the diameter of the wheels: 5.5

cm Calculate Circumference: diameter x π 5.5cm x π = 17.27cm

Page 19: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

19chung

Making Turns

• Turn left:

• Spin left: (point turn)

• Face left:Left wheel

Left wheel

Right wheel

Right wheel

Left wheel Right wheel

stop

stop

Page 20: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

20chung

Spin Right 90 degrees

Page 21: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

21chung

Ex 2: Go forward 1.5 rotations and come back by spinning left

• Spinning 180 degrees?

Page 22: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

22chung

Sensors•Light•Touch•Ultrasonic (Distance measurement)• Sound (microphone)• Rotation – embedded in the motors• Timer – Internal sensor• Received Bluetooth messages • NXT buttons

Page 23: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

23chung

Light Sensor• Percent mode

5% - lowest dark 100% - very bright

• Reflected light mode: shines a red light

• The light can be turned off – detecting ambient (surrounding light)

•Live updates: See lower left corner, if your robot is connected to the computer via either USB or Bluetooth

Page 24: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

24chung

Light Sensor II• Press View | Select “Reflected Light”

| Select input port number On white area: 55%-65% On black area: 43%-48%

• If Live Update value is quite different from the View value, light sensor calibration was done (using menu Tools). Either use default or update firmware, to reset.

• Light value is affected by the gap between the sensor and the floor

Page 25: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

25chung

Light Sensor Readings

Source: HighTechKids.org

Page 26: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

26chung

Attach a Light Sensor

• Facing down• Gap: around 0.5 cm -1 cm (What

will be the problem if too close to the floor to solve the Miner Rescue problem?)

• Port No. 1

Page 27: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

27chung

Ex 3. Stop at Edge of the table

Page 28: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

28chung

Comments• Use balloon text tool• Add the following information

Author, when Who made changes, when How to use Functions Block descriptions Assumptions: 1 - light Expected results Known bugs Rooms to improve Etc.

Page 29: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

29chung

Measure Light Sensor Values on the Miner Rescue field• White:• Black:• Foil: • Outside Edge: • Crack (gap) between home base

and ramp:• Approaching down ramp• Approaching up ramp

Page 30: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

30chung

The gap between the Light sensor and the floor!!!• Both Reflected and Ambient light

values are affected by the distance between the sensor and the floor!

• The light sensor value is in inverse proportion to the gap

Lightsensor

Lightsensor

Page 31: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

31chung

Stop when it sees the black line on the Miner Rescue field

Page 32: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

32chung

Ex 4. Stop when it sees the 2nd black line on the Miner Rescue field

What is wrong?

Page 33: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

33chung

How about stopping at the 4th line?• Loop (Repeat)

Block

Count = 4

Page 34: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

34chung

Touch Sensor

• Press View | Select Touch | Select input port number

• If released (not pressed): 0• If pressed: 1• Is it sensitive? – it seems not

• NXT-G can handle “Bumped” - (pressed and released) or (released and pressed)

Page 35: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

35chung

Attach a Touch Sensor

• Port No. 2

Page 36: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

36chung

Ex. 5 Loop until a touch sensor is pressed

Display seconds until touch sensor is pressed.

Page 37: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

37chung

Line following - Zigzag methods

Page 38: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

38chung

Ex 6. Follow the black line until a touch sensor is pressed

SwitchFor Robofest field, the power should be less than 40

Page 39: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

39chung

Ex 7. Follow the line until it detects the foil

• Need more power to climb• Use rotation sensor to locate the

robot

Page 40: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

40chung

Ex 8. Follow the line until it climbs back to the home base

Page 41: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

41chung

How to improve line following?• Three way branch• …• Use two light sensors

• http://home.earthlink.net/~xaos69/NXT/Line_Follower/Line_Follower.html

• http://www.teamhassenplug.org/NXT/ - Steve H’s line following block

Page 42: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

42chung

Ex 9. Follow the line until it climbs back to the home base – Use My Blocks

Page 43: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

43chung

My Blocks

• Wrap a procedure into a package• To do the same thing from different

places; to reuse code; to make code non-redundant

• To divide a large task into smaller meaningful modules (provide structure)

• To hide complex details

Page 44: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

44chung

How to create MyBlocks

• Start with working code• Highlight blocks to include• Click the “Create My Block” button• Name the MyBlock• Describe the MyBlock• Build icon(s)• MyBlock replaces the selected

Blocks

Page 45: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

45chung

How to reuse the MyBlock

• Select it from the Custom Tab

Page 46: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

46chung

Ultrasonic Sensor

• Uses the same scientific principle as bats: it measures distance by caluclating the time it takes for a sound to hit an object and return – just like measuring an echo.

• Measures in centimeters and in inches • 0 to 255 cm (or 0 to 100.4 inches, 8.4ft)• Precision of +/- 3cm (1.2 inches)• Press View | Select Ultrasonic cm |

Select input port number

Page 47: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

47chung

Ultrasonic Sensor II

• Large-sized objects with hard surfaces return the best readings

• Objects made of soft fabric or that are curved (like a ball) or are very thin can be difficult for the sensor to detect

• Note that two or more Ultrasonic sensors operating in the same room may interfere with each other’s reading

• Connect an ultrasonic sensor to port no. 4

Page 48: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

48chung

Can you guess what the following program is behaving?

Page 49: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

49chung

The same program – event driven

Page 50: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

50chung

Not covered advanced topics

• Variables

• Multiple tasks & Synchronization of multiple tasks

• …

Page 51: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

51chung

NXT Programming Tips

• “Out of Memory” problem Do not use sound file Do not display graphics Minimize number of programs on NXT Delete unnecessary programs

• Debugging Gradually, not all at once Display Tone

Page 52: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

52chung

Tips for Robofest 2007 Game

•Line following is required?•Ultrasonic sensor – No. 3 ball• May be light sensor for No. 4 ball in

the tunnel• NXT conversion cable: you can use

your existing RCX sensors and motors with the NXT brick! (3 cables for $10)

Page 53: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

53chung

Please go through Getting Started and Software Overview after this workshop

Page 54: 1chung Robofest 2007 NXT Programming Workshop Jan. 27, 2007 CJ Chung Associate Professor of Computer Science Lawrence Tech University CHUNG@LTU.edu .

54chung

Where to get additional Lego blocks?

• http://www.bricklink.com/• eBay for Legos


Recommended