Mrs. B's Disclaimer:

Mrs. B does not manage the entire Internet. :) Please view these links with your parents.

Sunday, October 30, 2011

Using "My Block" in Mindstorms NXT-G Programming

There are many reasons why one may want to use "My Block" in NXT-G Programming.  I will only discuss the writing of My Block for the purpose of streamlining/modularizing the program.  With the use of My Block for a group of blocks that are intended for a specific task, it may be possible to have a complete program fit in one page on screen, with each My Block being an individual page.


For FLL competition where the team jointly work on programming, the ease of program distribution is very important.  Without knowing how to save "My Block" inside the main program, the distribution of program can be a nightmare.

When a "My Block" is created, the "My Block.RBT" is saved in a default directory, usually as "...\My Documents\LEGO Creations\MINDSTORMS Projects\Profiles\Default\Blocks\My Blocks".  This is usually different from your working directory where you save your main program.  If you simply save your main program and distribute it, the other user will get a "Broken My Block" (see picture below.)



Note: An NXT-G program that contains a use of a My Block (an instance of a My Block inserted from the Custom Palette) does not actually store the contents My Block inside the main program file. Instead, the program contains only a reference to the My Block, which is essentially the name of the My Block along with some information about where the block came from.

To save your program with My Block altogether, do the following.  Select "Tools - Create Pack and Go" from the top menu bar.  This will generate an .RBTX file format which allows you to share the complete program (with My Block files).

Important Note!!!  If you have an earlier version of .RBTX and you have since modified your program (either My_Block.RBT or Main_Program.RBT), do NOT select "overwrite" when you open the earlier version of .RBTX.  If you select "overwrite", your updated "My_Block.RBT" will be lost.  I recommend that you save both .RBTX (by Creating Pack and Go) and .RBT (by save) each time you modify your programs.


Note:  The Create Pack and Go feature is not available on versions of the NXT software prior to NXT 2.0, and the Pack and Go file storage format (.rbtx) is not readable by earlier versions either.  If you save a program in this format, it will not be directly readable by users with the NXT 1.X software or the “NXT-G 2.0” software from LEGO Education.
 

For (lots) more information about My Block, please see the NXTPrograms page

Logging Data in Mindstorms NXT-G Program

In most situations where the robot does not perform as you expect it to, writing a test program to isolate and execute only the part in question would be a good way to debug your program.  In some cases, you can also monitor the robot sensor reading and/or other internal variables from the NXT view window and/or your laptop if the USB cable is connected.  However, if the reading is dynamic and the change is faster than your eyes can read, you would need to log your data.

Data Logging is a very good way to debug your software.  However, you should keep in mind that with NXT writing information to its memory, the data log block does take time and it may slow down the program execution just a tiny bit. 

A good example of data logging with NXT-G is shown in the figure above and its detailed description can be found in
http://thenxtstep.blogspot.com/2007/09/datalogging-with-nxt-g.html

Other data logging information can be found in

http://www.teamhassenplug.org/NXT/DataLogging/Beginning_Datalogging.htm

Note that the Education Version of NXT-G 2.0 offers a new and improved Data Logging Block.  However, most of us have the commercial NXT-G 2.0 software.  If you do have the Educational Version, you can read the link below about how to use the Data Logging Block.
http://thenxtstep.blogspot.com/2009/02/nxt-g-20-datalogging.html

Monday, October 24, 2011

Light and Color Sensors Calibration


The light sensor reads light intensity and its raw value reading ranges from 0 to 1023.  By using the Calibration Tool for light sensor that's built in in Mindstorm NXT-G software, one can NORMALIZE the light intensity reading to range between 0 and 100.  You want to calibrate the light sensor because
1)It is easier to work with a number between 0 and 100.
2)During the calibration, you already tell NXT brick/brain about the MINIMUM, i.e. the darkest black, you can find on the mat, and the MAXIMUM, i.e., the brightest white you can find.  So the NXT brick/brain doesn't need to worry about any raw value reading that's beyond the minimum and maximum.  This allow you to work with a better resolution.  That is, it allows you to read the different grey area, say, from 1 to 99.


The calibration procedure is best explain in this Millerbots instruction video


As for the color sensor, the Mindstorm NXT-G software does not have an equivalent calibration software for it.  Moreover, there is no proper built-in viewer to read the color sensor reading from the small viewing window of NXT brick.  I recommend reading the light intensity reading of a color sensor directly from the laptop, as explained in this video.  And I recommend a manual "calibration" procedure as below.  You place the robot/color sensor on the darkest black, make a note of the laptop reading.  This will be your manual minimum value.  Then you place the robot/color sensor on the brightest white, make a note of the laptop reading.  This will be your manual maximum value.  Therefore, if you need a threshold for line following, it can be the average of the two values.

P.S. I have found the line following performance using either a calibrated light and color sensor is about the same.