Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to NXT Programming October 16, 2010 Joe Long (Special RoboParade edition) Brought to you by a generous grant from Tardec.

Similar presentations

Presentation on theme: "Intro to NXT Programming October 16, 2010 Joe Long (Special RoboParade edition) Brought to you by a generous grant from Tardec."— Presentation transcript:

1 Intro to NXT Programming October 16, 2010 Joe Long (Special RoboParade edition) Brought to you by a generous grant from Tardec

2 2 Agenda Basic Movements Loop, Sensors, Wait, Switches, and line following Program Beams Determining speed Extra Tips

3 3 Creating a Program Start the NXT-G program Use meaningful names!!! Upon clicking [Go >>] a programming palette will appear.

4 4 Exercise 0: Go Forward For Two Seconds Click on the Move button Drag it to the canvas

5 5 Exercise 0: Go Forward For Two Seconds Change settings (parameters) for the block: Port Direction Power Duration Steering Next Action

6 6 Lets test it!!! Connect the NXT to the laptop (if this is the first time, then a Found New Hardware message will appear) Click on the Download button Its recommended to always unplug the cable from the bot before running the program Navigate through the NXTs menu: Turn On > My Files > Software Files Then select your program and run it!

7 7 Sensors Touch Light Ultrasonic (distance measurement) Sound (microphone: decibel level) Rotation (Embedded in motor) Timer (Internal Sensor) Received Bluetooth Messages NXT Buttons (two grays and the orange)

8 8 Getting Sensor Values NXT-G offers a Live Update feature that lets you see what your robot is seeing, through the computer. When you click on a block that uses the light sensor (and the NXT is plugged into the computer and turned on), you can view the light sensor value.

9 9 Light Sensor Percent Mode: 5% = lowest dark 100% = very brigh Reflected Light Mode: shines a red light The light can be turned off – detecting ambient light (surrounding light)

10 10 Light Sensor Navigate the NXTs menu: View > Reflected Light On White Area:55% - 65% On black area:43% - 48% If the Live Update value is VERY different from the view value, then odds are a calibration was set up and it is skewing the results. Calibrations can be created / edited / deleted in the Tools Menu of the computer program.

11 11 Light Sensor Readings 50% 45% 40% 45% 40% 30% 35% 30% 35% 50% Based off of sources from:

12 12 Attaching a Light Sensor Facing Down Gap: around 0.5 to 1 inch off the ground The default port is port 3, so well use that!

13 13 Exercise 1: Stop at the Edge of the Table Program:

14 14 Commenting Your Code Use the comment tool ( ) to note the following information: Author, date of creation How to use the program Descriptions Expected sensor values Known bugs Functions to improve upon etc, etc, etc…

15 15 Light Sensor Values on the RoboParade Course Be able to detect white area and the black line If necessary, detect the edge of the field so as not to fall off

16 16 What could go wrong? Some robot in front of you might have lights Unintentionally reflected light could blind the light sensor One end of the track might have more light than the other

17 17 Exercise 2: Infinite Line Following (touch) The NXT default for the touch sensor is port 1, so well go with that. Possible outputs: PRESSED or NOT PRESSED!

18 Exercise 2: Infinite Line Following (Intro) Loops and Switches (beep on press): 18

19 19 Exercise 2: Infinite Line Following The Zig-Zag Method

20 20 Exercise 3: Follow the line until touched Switch For the RoboParade field, the power should be less than 40.

21 21 How to improve in line following Use a three way branch Use two light sensors Use a dynamic threshold (the program gets the light value before moving, then bases all of its decisions off of that value)

22 Dual Light Sensors Bounce along the line! 22

23 Dual Light Sensors 23

24 24 Ultrasonic Sensor Uses the same scientific principle as bats. The NXT can measure in centimeters or in inches 0 – 255 cm (0 – inches) Precision: +/- 3cm (1.2 inches) View the sensor information: View > Ultrasonic cm > select port number Battery Glitch! Dont go under ½ power!

25 25 Ultrasonic Sensor Large objects with hard surfaces return the best readings. Objects made of fabrics or something curved (like a foil wrapped tennis ball) are difficult to detect Two or more ultrasonic sensors in the same room interfere with eachothers readings!

26 26 Exercise 4: Ultrasonic Distance

27 Exercise 5: Move until ultrasonic detection 27

28 28 My Blocks Wrap a complex procedure into a single block. Save what little memory the NXT has and avoid redundancy. Hide complex details.

29 29 Creating My Blocks Start with working code Highlight blocks to include Click the Create MyBlock button Name the MyBlock Build the icon(s) MyBlock replaces the selected code It is also now available in the custom menu

30 Program Beams Multi-tasking, NXT style! 30

31 31 Creating Variables In the computer program, go to the Edit menu and select Define Variables Enter the variable name and type. Text = hello world! Number = 1337 Logic = true / false Also called boolean

32 32 Editing Variables 1)Open the Complete menu 2)Next to the plus sign, select the suitcase block 2 modes: Read write

33 33 Variables and Dynamic Threshold Part 1 Get the light value of the white space Subtract 7 Save it to a variable called Light Threshold

34 34 Variables and Dynamic Threshold Part 2 Read the current light sensor value and see if it is greater or less than the threshold, act accordingly.

35 35 Editing the Memory A utility called the NXT Window will be your best friend for this! When the window pops up, click on the Memory tab, select a file type from the chart on the left. This window can also upload and download files to / from the NXT. NOTE: No system files are shown! This means that you can delete at random and the NXT will still work without a hitch.

36 36 Tips: Out of Memory problem: Do not use sound files, or delete the currently existing files Do not display graphics Minimize the number of programs on the NXT Delete Unnecessary programs

37 37 Tips: Debugging: Code gradually, not all at once. Beeps help, make the robot beep whenever it thinks that it sees a line and your coding gets a LOT easier. Displaying values helps too! Game Details: Ultrasonic sensor on #3 ball Light sensor on #4 ball

38 38 Something Cool: Getting rid of the startup sound If you open the Memory window (shown three slides ago) and navigate to the Sound files, you can delete the startup sound. Now the NXT will turn on WITHOUT THE MUSIC!!! If you want to reload it, its one of the sound effects available to the sound block. Just make a program that uses that sound and it will be saved again, even if you delete the program.

39 39 Use RCX sensors and motors with the NXT NXT conversion cable 3 cables for $10 Available through Robofest office, M219.

40 40 Acquiring More Parts You can purchase spare parts (and a couple recently developed sensors, including a color sensor) at Interested in buying pieces? Bricklink allows people to sell and buy lego bricks, many a rare part can be found there, and the prices are EXCELLENT! Lots of 3 rd party companies sell sensors and other parts that are available nowhere else!

41 41 Thats it! Questions? Comments? Concerns? Restraining orders? (…hope not…) Feel free to drop me an for any of the above (although any notices for restraining orders can be forwarded to my evil twin).

Download ppt "Intro to NXT Programming October 16, 2010 Joe Long (Special RoboParade edition) Brought to you by a generous grant from Tardec."

Similar presentations

Ads by Google