BrickEngineer: LEGO Design

LEGO Engineering for LEGO NXT and Robot Enthusiasts

Danny – NXT Matlab Bluetooth Router


Daniele Benedettelli introduces a MATLAB-based NXC Bluetooth Router. This router relies on connecting a master NXT Brick to a computer via USB. This master NXT Brick then can communicate messages to up to three additional slave NXT Bricks up to a distance of 10 meters from the master. This software would allow one to create small swarms of up to three LEGO robots, which is a nice starting point for investigating distributed robotic systems.

MATLAB NXT Bluetooth Router

MATLAB NXT Bluetooth Router

The system relies on the RWTH – MINDSTORMS NXT Toolbox, the NXT Fantom Library, and John Hansen’s enhanced firmware.  The brick software is written in Not eXactly C (NXC), which requires Brick CC 3.3.

Daniele Benedettelli also has a book published titled Creating Cool MINDSTORMS NXT Robots (Technology in Action)

LEGO Rendering Tutorial: The Basics

This is the first in a series of installments that describe how to render high-quality 3D images of your LEGO creations.  You will need the following free software:

  • LDraw
  • MLCad
  • L3P
  • POV-Ray v3.6

which can be downloaded with the LDraw All In One Installer

In this tutorial, we will be aiming for a nice simple still image of three bricks.  In later tutorials, we will animate them.  That will require extra software to put a series of inages together to form a video or an animated gif.  I use Adobe ImageReady to make animated gifs, but there are cheaper solutions.

You can also download all the files we will create here
BE_render_tutorial_1.zip
and follow along.

STEP 1: Create an MLCad file of the scene to be rendered

Open MLCad and prepare to place a few LEGO pieces in the scene.

Step 1.1: Set up a 1×1 brick
On the upper left-hand side, click on Brick.
Drag the 1×1 brick into one of the three viewing panels.
With the brick selected click the RED color button to color it red.
Right-click on the brick and select Enter Pos. + Rot…
Use Position Values
should be checked
Set the X and Z values all to zero and Y to -100 (negative 100)

Step 1.2: Add a 2×4 brick
Following the steps above, find the 2×4 brick in the Brick list (+ will expand the list) and add it to the scene.  Set its color to YELLOW and its position to X=100, Y=-100,  Z=50.

Step 1.3: Add a 2×6 plate
Following the steps above, find the 2×6 plate in the Plate list (you will have to scroll down to the Plate tab) and add it to the scene.  Set its color to BLUE and its position to X=100, Y=-100,  Z=-100.

Be sure that these pieces are all at Y=-100.  The -y direction points upward and this will place them above the Y=0 plane.

Step 1.4: Save your work as part-zoo-1.ldr

The screenshot below shows what you should see at this point on your MLCad screen.

MLCad Screenshot

MLCad Screenshot


STEP 2: Create a POVRay file using L3PAO

Open LP3AO (L3P-Add-on) keeping in mind where you stored your MLCad files.  This figure shows you the basic L3PAO window.

L3PAO Screenshot

L3PAO Screenshot

Step 2.1: In the L3P-Add-on window set the Model File to point to your MLCad file.  To browse, you may need to click on the button labeled …

Step 2.2: In the L3P-Add-on window set the POV-Ray Output File to point to the folder where you want your POV-Ray file to go.  To browse, you may need to click on the button labeled …

Step 2.3: In the middle of the right-hand column is the Quality Level setting.  Set this to 2.  IF you select 3 it prints the LEGO logo on every stud.  If you want this, you may leave it.  But I prefer to remove them.

Step 2.4: At the bottom of the middle column is the Render upon Completion option.  This will launch POV-Ray automatically.  However, if you have problems with the automatic launch, turn this option off and load it manually.  In later tutorials, we will edit the POV-Ray file manually anyway.

Step: 2.5: To start L3PAdd-on click on the Run L3P button in the lower right.  This will create the POV-Ray part-zoo-1.pov file in the directory you specified, and possibly launch POV-Ray depending on the settings you used in Step 2.4 above.

STEP 3: Render the Image with POV-Ray

If you launched POV-Ray automatically, you will already have your image.  Here we assume that you will render it manually.

POV-Ray Screenshot

POV-Ray Screenshot

Step 3.1: Open POV-Ray and in the File Menu, use Open File to open the .pov file that was created by L3pAO.

Step 3.2: Once the file is open, you can simply press the Run button on the upper bar.  This will create a default image, which is a 640×480 .bmp bitmap image.  This is saved automatically in the same folder as your .pov file.  Here it is:

Part-Zoo-1 Default image

Part-Zoo-1 Default image

Note that the LEGO pieces are lifted up above the floor.  This is because we set their y-coordinates to be -100, which is above the floor at zero.  Remember that negative y is up.  We now look to change a few features of our render.

Step 3.3: If you click on the Ini button (to the left of Run above), you will go to a screen that enables you to change the size of the output image.  The Section field on the right has many options that include the resolution of the final image as well as whether Anti-Aliasing (AA) is used.  Try changing the resolution and look at the differences between anti-aliased images and non-anti-aliased images.

Note however, that the output images will always be saved in either .bmp or .png format.  You will have to use another program to convert them to other formats if you are interested.

Step 3.4: You can try playing with the commands in the .pov file.  POV-Ray acts like an editor and you can manually edit your files.  For example, there is a section near the bottom that reads:

// Floor:
object {
plane { y, 24 hollow }
texture {
pigment { color rgb <0.8,0.8,0.8> }
finish { ambient 0.4 diffuse 0.4 }
}
}

This code controls the floor of the image.  If you delete it completely, the floor will disappear as you can see here in this image:

Part-Zoo-1 with No Floor

Part-Zoo-1 with No Floor

Step 3.4: IF you don’t like the black background, look in the .pov file for the Background section:

// Background:
background { color rgb <0,0,0>}

Changing the rgb (red, green, and blue) colors to <0.7, 0.7, 1.0>:

// Background:
background { color rgb <0.7, 0.7, 1.0>}

Will give you an image with no floor and a light blue background:

Part-Zoo-1 with a blue blackground

Part-Zoo-1 with a blue blackground

We have explored making simple cad images in MLCad, generating a .pov file using L3PAO, and rendering a high-quality bitmap image using POV-Ray.   You should read through the .pov file and try to figure out what the different parts do.  You can change their values and re-render the image to see what impact your changes have.  Just remember that POV-Ray saves the changes on top of the original file,  so you may want to make a backup first.

Happy Rendering!

MATLAB Packages for the NXT

There are now several MATLAB packages for robotics, and specifically for the NXT.  One paradigm is to run the code on a PC and have it communicate direct commands to the NXT Brick via Bluetooth or USB.  I have found this paradigm to be a bit dangerous since in the event of a MATLAB crash or a miscommunication, the NXT Brick will continue with its last command until ordered to stop.  This has the potential to destroy your robot.  The paradigm that I prefer to use is to write several programs that run on the brick.  These programs take commands from files on the brick that can be uploaded rapidly from the PC.  The MATLAB code then is in charge of sending the command files and starting and stopping programs.  In the event of a MATLAB crash or communication failure, the software running on the NXT Brick can be designed to terminate gracefully.

Here are the MATLAB packages that I know of.  The first two are specifically geared toward the NXT; whereas the last is a general robotics package.

Basic Electronics Supplies for Beginners

I am getting interested in more general robotics projects, but will still be relying on LEGOs for their construction.  The LEGO brick is a bit too limited with its specialized programming languages and limited sensor and motor ports.

So for those interested in some LEGO electronics hacking, here is a list of supplies that will get you up and running fast for about $275… just a but more than the cost of a single Mindstorms kit.  Plus you’ll now get to learn electronics!

First, check out the book:
Making Things Talk: Practical Methods for Connecting Physical Objects

This book explains how to wire, program and interconnect various microcontrollers, some of which are very closely related to those used by the NXT Brick.

Supply List

Item Number Description Quantity Unit Price Total
Amazon.com
  Making Things Talk 1  $19.79 $19.79
Jameco.com
19166 Desoldering Pump 1 $4.95 $4.95
159291 Wire Stripper 1 $10.15 $10.15
161411 Diagonal Cutter 1 $7.49 $7.49
35474 Needlenose Pliers 1 $5.49 $5.49
127271 Mini Screwdriver 1 $1.89 $1.89
681002 Helping Hands 1 $8.75 $8.75
159611 Power Connector 2 $1.79 $3.58
10444 Alligator Test Clip Leads 2 $4.39 $8.78
103377 Header Pins 10 $0.16 $1.60
119011 Push Button (PCB Type) 10 $0.27 $2.70
29082 Potentiometer 2 $1.05 $2.10
242115 LM1117T-3.3 Voltage Regulator 3 $1.39 $4.17
51262 7805T 5v Voltage regulator 3 $0.32 $0.96
38236 2N2222A Transistor NPN 5 $0.41 $2.05
32993 TIP120 Power Transistor 5 $0.45 $2.25
643488 3.3V Zener Diode 5 $0.03 $0.16
35991 1N4004 Diode 5 $0.04 $0.20
152792 LED Yellow 10 $0.17 $1.70
152805 LED Red 10 $0.21 $2.10
153139 LED Orange 10 $0.35 $3.50
156962 LED Green (567 nm) 10 $0.20 $2.00
334529 LED Bargraph Red 1 $1.31 $1.31
334537 LED Bargraph Yellow 1 $1.23 $1.23
334511 LED Bargraph Green 1 $1.28 $1.28
17187 7-segment LED Display 3 $0.88 $2.64
38818 4-switch DIP 4 $0.48 $1.92
38842 8-switch DIP 2 $0.89 $1.78
103166 Resistor Refill 1 $12.95 $12.95
15270 0.1 uF 10 $0.15 $1.53
94161 1 uF 10 $0.12 $1.20
29891 10 uF 10 $0.06 $0.60
158394 100 uF 10 $0.11 $1.08
MPJA
4443 TE Solderless Breadboard 1 $4.95 $4.95
4447 TE Large Solderless Breadboard 1 $22.95 $22.95
7027 TE Jumpers 2 $3.95 $7.90
14213 TE Digital Multimeter 1 $14.95 $14.95
15860 TL Mini Soldering Station 1 $14.95 $14.95
Sparkfun
Wiring Platform DEV-00744 1 $84.95 $84.95
Radio Shack
64-025 Lead Free Solder 1 $3.89 $3.89

Note that the light gray items are optional, and not necessary.

Also, this list does not include some sort of power supply. Pulling one out of an old computer is an easy option. Or rechargeable batteries work well too (in which case you will need battery holders).

Last, there are special items in the book Making Things Talk that you may decide to purchase separately, such as flex sensors, or bluetooth boards, etc.

You can store your electronics in much the same way you store your small LEGO parts. Check out the article on Storage.

Enjoy Hacking!

Content Protected Using Blog Protector By: PcDrome.