CSC 126

Create robot

Comments

Programming the NXT


Objectives

Tools and Parts Needed



In this lab, you will learn to use a new robotic platform, called the NXT, which like the RCX is created by Lego.

The Mindstorm Robots: The RCX and the NXT 

The first retail version of Lego Mindstorms was released in 1998 and marketed commercially as the Robotics Invention System (RIS). The next version was released in 2006 as Lego Mindstorms NXT. Note that they are both Mindstorm robots.

Let's look at the specifications for both the RCX and NXT:

RCX Specifications RCX

As you know, the RCX has three input ports for attaching sensors, called Ports 1, 2, and 3, and has three output ports for attaching motors, called Ports A, B and C. You can download programs from your computer to the RCX via the IR tower.

RCX Buttons
RCX Technical specifications

NXT SpecificationsNXT

The NXT has four input ports for attaching sensors, called Ports 1, 2, 3 and 4, and has three output ports for attaching motors, called Ports A, B and C. You can connect a USB cable to the USB port and download programs from your computer to the NXT (or to upload data from the robot to your computer). 

NXT Buttons
NXT Technical specifications
NXT vs RCX

Most RoboLab programs written for the RCX will work AS IS on the NXT, but there are a few improvements which work only on the NXT and which are worth discussing.  
For example, the begin icon: Green Light will work fine on the NXT, but every program will simply be listed as "rbl" (RoboLab).  If instead you use NXT start icon then you can give each program a meaningful name which will be displayed in the NXT's menu system.  For example, in the following program which plays a scale, "scale" will be listed in the menu:
NXT scale
Create something like the above program and try running this on the NXT. It will also run on the RCX if you swap out the green stoplight which starts the program for the one we have used on the RCX.

 
Musicalcompostions for the Mindstorm robots are also available from
To use this music, do the following:
  1. Click the song title you want to download, saving the song file in the "My Songs" folder located in "My Documents/ROBOLAB Data/Songs/My Songs" on your laptop.
  2. Open Robolab Inventor Level 4 and choose Project>Piano Player from the menu bar.
  3. Once in the Piano Player, Open the song file. The notes of the song should appear in the Piano Player.
  4. Next push one of the following scroll icons: . Note that using one of the colored scroll icons will allow you to run your program without a dialog box. The last scroll icon is called "load scroll from file" and will allow you to save into a file after editing.
  5. Then to play the music just include the same scroll icon in your RoboLab code. Note that when you use the "load scroll from file" icon, you will have to type the filename into a dialog box when the program runs.
  6. Note:  You may also compose your own music for the RCX and the NXT, but please do this after you finish the rest of the lab or outside of class.

Changing the NXT Display

It is easy to write a program which will run on both the RCX and the NXT.  The following program will run on both robots.

RCX and NXT

Note that the NXT does not have the same kind of screen as the RCX, so the set display LCD sceen icon, LCD, will not run properly on the NXT and will need to be removed from programs before trying to run them on the NXT, so the following program will not run on the NXT.

RCX only

Of course, one can display values on the NXT, but the screen differs from the RCX.  The following program will display the value of the red container on the NXT, but will not run on the RCX.

NXT display

The NXT allows many programs to be stored, so naming programs is important.  The following program will be easier to find on the NXT.  It will not run on the RCX.

NXT menu

Multitasking

Humans are naturals at multitasking.  Did you ever try to walk and chew gum at the same time?  How about whistling while you work--okay maybe humming while you listen to music AND working at the same time?  As the word itself is suggests, multitasking means processing two or more tasks at the same time. In previous assignments, all the RoboLab programs ran sequentially--never at the same time.  This was true for all of our labs, even when you used conditionals because the execution of the program after the condional branch followed only one of the two possible branches at a given instant in time, NOT both branches at the same time.

With the use of the multitasking property, tasks can be run on our robots at the same time, like chewing gum while walking or whistling while you work. This property helps robots do several tasks simultaneously and hence makes the programs more versatile.

In RoboLab, multitasking can be accomplished on both the RCX and the NXT  is enabled by the Task Split icon:

task split

For example, the following program uses a Task Split to drive in a circle for 4 seconds while playing music continuously.  Observe also, that when multitasking there cannot be a fork join to a common program end for the two tasks--each task must have an individual end as follows:

task split program

In this example, there are two tasks: Task 1 drives motor A forward for 4 seconds and then stops, while Task 2 plays the musical note forever. You will observe that the music will play simultaneously while motor A is moving and even after the motor stopped because Task 2 involves an infinite loop created by the green land and jump icons. 

The above has just two tasks, but by using multiple Task Split icons, a programmer can have as many tasks running at the same time as he/she wants. It is just a matter of having additional task structures.


Your Main Task

In this lab you are required ultimately  to program your NXT robot to whistle while it works.  It is suggested that you first program the RCX and then make changes to your program to make it work on the NXT.

First, you must use a task split to get the robot to multitask.  
Once this is working in a simple fashion, which tune is played on the music branch should be selected randomly, with approximately equal likelihood of each of the two or more tunes being played.  Note that you must use different scrolls on each branch.  (For example, do not use the red scroll on both branches.)

Hints: You may need random numbers and nested conditional forks to make this work.  Use the red, blue, or yellow scrolls.  Be sure that once the tune is chosen, it still will play over and over forever.

Once all of the above is working, add complexity to the random driving patterns.

Once all this is working on the RCX, see if you can run the same program on the NXT.  
  1. Be sure to include explanatory comments to your RoboLab code by using the Edit Text icon: edit text icon  In particular, it is required that you add the following comments:
    • Lab L14
    • All of your team member's names
    • Comments about what the robot will do on each fork.
  2. When using the NXT, use the "Begin NXT" NXT start icon to begin your program.  Give this start icon the name of L14-tablename 
  3. Finally, modify your pseudocode, robot, and RoboLab program to improve your robot's performance. 
  4. Answer the questions in your Lab Report.

Your Lab Report

This lab report should contain all of the following information at the top: As usual, for this lab, your team will submit two files: the Lab Report entitled yourusername1-yourusername2-L14 and the NXT version of the RoboLab program entitled yourusername1-yourusername2-L14. For the report, your team should discuss the answers to each of these questions. Using correct spelling and good grammar, this lab should then address the following questions:
  1. Scale Program: Try the something like a scale program on the NXT.  Describe what modifications need to make to make it  run  on the NXT as compared to what  it would have looked like on the RCX.
  2. Your Pseudocode for the main task: Include the final version of your pseudocode in your Lab Report.
  3. Your Success: Be sure to use an NXT start icon such as with L14-initials where "initials" represents your initials and your partner's initials.
    (Jan Pearce and Josh Absher is JP-JA)
    L14-initials
    Describe how to use your program and whether or not your NXT robot functions as desired. If not, what goes wrong and under what conditions?
  4. Testing and Refining: Describe what changes you made in your algorithm during the testing and refining phase for the NXT.
  5. The NXT: What is your team's reaction to programming on the NXT?
  6. Future Modifications: Discuss at least on idea for changes you might consider making which would make this an even cooler program for the outreach to kids.  (Remember that kids love interaction!)
  7. Comments and Suggestions: Write a paragraph that summarizes your team's reaction to RoboLab and to this lab. If there are any problems you encountered or any questions that remain, please ask! Also, be sure to include any suggestions you have for how this lab could be improved.

http://faculty.berea.edu/pearcej/CSC126/ | Licensed under a Creative Commons Attribution-Share Alike 3.0 United States License