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