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!

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.

The Blossoming Lotus: LEGO Kinetic Art

I call this creation The Blossoming Lotus.  It was originally posted on Online Cortex, but I have decided to repost it here because its just plain fun. Basically it is a large 2D version of a Hoberman sphere. Why did I not make a large Hoberman sphere? First, the parts to make the circle cost almost $80 US. Second, I have other more pressing projects I am working on.

The Blossoming Lotus Kinetic Art

The Blossoming Lotus Kinetic Art

It is about 4 feet in diameter when completely extended and is pretty impressive. Its relatively easy to make. My design consists of constructing each petal with two interlocking pieces: a single-claw arm and a double-claw arm. The parts needed to make the two arms are illustrated below.

Parts for a Single Lotus Petal

Parts for a Single Lotus Petal

To make the entire circle of petals, one needs 20 copies of each petal. The job then is to put them all together. I will post detailed instructions on a website in the near future. For now, here is a closeup of the blossom when completed.

Close Up of the Lotus Blossom

Close Up of the Lotus Blossom

And of course, the project wouldn’t be complete without that animation above made with MLCAD, L3PAO, and POV Ray. The animation was straightforward—once you get the geometry right (which is not straightforward). I will post a lesson on the geometry and the animation of this creation in the future as well. For now, enjoy.

Knuth: Developing Robotic Scientists for Space Exploration

The University at Albany (SUNY) has highlighted Knuth’s research in a recent news piece.

UAlbany Professor Kevin Knuth with a robot built from LEGOs. (Photo Mark Schmidt)
UAlbany Professor Kevin Knuth with a robot built from LEGOs. (Photo Mark Schmidt)

Kevin Knuth has a laboratory in the physics department of the University at Albany that is filled with LEGOs. The bricks are relatively cheap and can be used to rapidly prototype a robot’s body. Knuth’s robots are being programmed to solve such problems as mapping complex terrain.

At UAlbany Day on Saturday, Oct. 25, he will give a demonstration on Robotics and Robotic Exploration in Life Sciences Room 143 at 10:45 a.m.

More here:
http://www.albany.edu/news/update_4522.shtml

Building instructions for the robot shown in the UAlbany article can be found on Brickengineer.com

Visit Autonomous Exploration News for information on Knuth’s company Autonomous Exploration Inc.

Visit Robots Everywhere for a general blog on robotics news.

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

LEGO NXT Motor Wiring

After posting Hacking the LEGO Mindstorms NXT Standard Motor, I received several requests for more information regarding the wiring of the motor.

The NXT cable has six wires. Below I list a table with the wires and their colors:

Color Name
White Motor 1
Black Motor 2
Red GND
Green 4.3 Volts
Yellow Tach01
Blue Tach02

The WHITE and BLACK wires (Motor 1 and Motor 2) deliver power to the motor.
If standard batteries are used, the potential difference will be 9 volts, otherwise the NiMH rechargeable batteries provide 7.2 volts. If the white wire is positive and black is negative, the motor will turn one way. If you reverse the polarity, the motor will turn the other way.

The RED wire is connected to the ground (GND). Note that in the sensors, RED and BLACK are connected to one another. This is not the case in the motors.

The GREEN wire is connected to the +4.3 NXT power supply.

The YELLOW and BLUE wires are connected to the quadrature encoder, also called an incremental rotary encoder.

Basic Rotary Encoder

Square waves from quadrature encoder

As shown in the figure from Wikipedia above, (http://en.wikipedia.org/wiki/Quadrature_encoder) the wires return square wave pulses that are 90 degrees out of phase. If the rising pulse on TACH00 leads the rising pulse of TACH01 by 90 degrees, then the motor is going forward. If it instead lags by 90 degrees, the motor is rotating backwards. One complete square wave cycle corresponds to 2 degrees of rotation. In the diagram above, if TACH00 refers to A and TACH01 refers to B, we can see that the motor is going backwards as TACH00 is lagging TACH 01.

By measuring the frequency of the square wave oscillation, one can compute the rotational velocity. Since one cycle corresponds to 2 degrees of rotation, one cycle per second (1 Hz) corresponds to 2 degrees/sec. If you record a frequency of X Hz, then the rotation rate is 2X cycles/sec.

Note also that by tracking both square waves, you can identify quarter cycles, which gives you a resolution of 1/4 of 2 degrees, which is 0.5 degrees.

The motor speed is controlled by pulse-width modulation (pwm), which works by driving the motor with a variable duty cycle square wave. This effectively turns the motor on and off, fast. The longer it is on, the more torque it will generate and the faster it will go.

These details and more can be found in the excellent book: Extreme: NXT with a sneak peak here.

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.

Philo uploaded a comment, and reminded me that “Note that there are some internal photos of the NXT motor here: http://philohome.com/nxtmotor/nxtmotor.htm and schematics here: http://www.brickshelf.com/cgi-bin/gallery.cgi?i=1846577

Happy Hacking!

Content Protected Using Blog Protector By: PcDrome.