BrickEngineer: LEGO Design

LEGO Engineering for LEGO NXT and Robot Enthusiasts

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!

Little Rover with Instructions and Code

 

I have finally compiled building instructions for my Little Rover, which can be seen above in a 3D Rendering courtesy of POVRay.  An earlier version of this rover can be seen in this YouTube video:

Little Rover Prototype Video

Rover Design

The complete detailed building instructions can be found here in this 94-page pdf file.
Warning: it is about 9MB in size.  The design is not entirely compatible with the standard NXT Mindstorms Kit.  This design relies on two touch sensors, several 1×9 bent liftarms, and as far as I can tell from Peeron, the NXT Kit has only two.  This may require a little redesign.  Other compatibility issues and their solutions can be found in the Parts List in the instructions.

Remember to download the software DriveSmart here as well.
Installation instructions can be found in the zip file.

DriveSmart Code

The main file is called DriveSmart.rbt.  Drive Smart runs four threads:

Drive Thread
The Drive Thread (lowest one of the four) drives until a warning flag is set by one of the other
threads. It then waits until it gets an all clear message via the Wait Until Free block, and then
it starts driving again.

Bumper Threads
There are two threads that monitor the bumpers.
The reaction is only activated if nothing else is currently commanding the robot.  In this case the
bumper has been pressed and the robot will veer away from the hazard.

Ultrasound Thread
This thread monitors the ultrasound rangefinder.
The reaction is only activated if nothing else is currently commanding the robot.  When the robot
comes too close to a hazard, the robot is commanded to stop.  It then looks both ways and then turns
in the direction with more room.  If the robot is within 10 cm of a hazard on both sides, it then
backs up.

The robot can roam about a wide variety of rooms and not get stuck.
He does not detect stairs though!  So be careful.

Download: instructions and code.

Enjoy!
Kevin Knuth

Hacking the LEGO Mindstorms NXT Standard Motor

We are working on interfacing the LEGO sensors and motors to a compact lightweight computer for more sophisticated control. Aret Carlsen brings us a video demonstrating how one can hack into the NXT Standard Motor:

See also quadrature encoder or rotary encoder at wikipedia and the LEGO NXT Hardware Developers Kit (LEGO NXT data sheets). Philo also has the pinout diagram on his page on deriving power from the Motor A port.

Additional details can be found in the excellent book Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level (Technology in Action) by Michael Gasperi, Philippe E. Hurbain, and Isabelle L. Hurbain.

Hacking the LEGO Mindstorms NXT Light Sensor

We are working on interfacing the LEGO sensors and motors to a compact lightweight computer for more sophisticated control.  Aret Carlsen brings us a video demonstrating how one can hack into the NXT Light Sensor:

Additional details can be found in the excellent book Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level (Technology in Action) by Michael Gasperi, Philippe E. Hurbain, and Isabelle L. Hurbain.

Meta-Parts: Part III

This is a continuation from Meta-Parts: Part I and Part II and consists of a library of LEGO constructs that can in many cases act as liftarms for bracing various structures. Here we consider constructs made from the LEGO axle joiner perpendicular.

Axle Joiner Perpendicular Constructs I
These LEGO constructs are even more sturdy and can be used as extremely strong braces. These are especially good for LEGO Mindstorms NXT projects.

Axle Joiner Perpendicular Meta-Parts

Axle Joiner Perpendicular Constructs II
This figure shows the wide array of constructs that can be made with both the axle joiner perpendicular pieces. These pieces are constructed from either two or three of these joiners. An example showing seven of them is below. The number of combinations is staggering.

Axle Joiner Perpendicular Meta-Parts

I have found such LEGO constructs to be especially useful in robotics applications.

Meta-Parts: Part II

This is a continuation from Meta-Parts: Part I and consists of a library of LEGO constructs that can in many cases act as liftarms for bracing various structures. Note that these LEGO designs can easily pull apart when you apply forces in certain directions—usually within the plane of their design. They will not be stable for constructions requiring that they withstand forces in those directions. However, if you need to brace against forces that are directed out-of-plane, or to prevent torsion (twisting). These constructs may help. If you are desperate, and are willing to sacrifice purity, a drop of superglue will do wonders.

Planar Constructs
This is a strange set where the construct has round holes that lie in a plane. Some of these constructs are quite strong, but the next set is even stronger still.  These construct provide alternative ways to stabilize axles.

Planar Meta Parts

Rectangular Constructs
The following rectangular constructs are typically much stronger than the previous constructs. These examples sport round holes at either the corners of the side centers.

Rectangular Meta-Parts

Square Constructs
These squares are quite sturdy, and can be constructed to have a good number of round holes in the square interior. The constructs in the lower row enable one to firmly attach two beams at 90 degree angles to create cross shapes.

Square Meta-Parts

Intelligent Instruments

Intelligent Robotic Arm

The LEGO Mindstorm NXT robotics system is an excellent testbed for research in machine learning and artificial intelligence.  At Knuthlab Robotics at the University at Albany, we are developing intelligent instruments using LEGOs.

Our first instrument is a robotic arm that is designed to locate a characterize a white circle on a black background using the LEGO light sensor.  It relies on Bayesian inference, which is implemented using a technique called Nested Sampling, which was developed by John Skilling.  This software allows the robot to learn the characteristics of the circle using the light sensor data that it has collected.  The real advance here is the inquiry engine, which uses Bayesian adaptive exploration to decide which measurements to take next.  It does this by considering all the possible measurements that it could take, and computes the expected gain in information from each possible measurement.  It then chooses to take the measurement with the greatest expected information gain.  The process then repeats as the robot learns about the circle.

The system is easily generalized to solving other problems, such as exploring rooms, interpreting people’s emotions, and doing real science.

We recently presented our research at the MaxEnt 2007 workshop in Saratoga Springs NY.  Below are links to a video of the talk, my slides, and our research paper.

Video: Designing Intelligent Instruments, K.H. Knuth

Slides: Designing Intelligent Instruments, K.H. Knuth

Research Paper:
Knuth K.H., Erner P.M., Frasso S. 2007. Designing intelligent instruments. K.H. Knuth, A. Caticha, J.L. Center, A. Giffin, C.C. Rodriguez (eds.), Bayesian Inference and Maximum Entropy Methods in Science and Engineering, Saratoga Springs, NY, USA, 2007, AIP Conference Proceedings 954, American Institute of Physics, Melville NY, In press.

Content Protected Using Blog Protector By: PcDrome.