Lego Central Drive Animation

I am slowly constructing my first intelligent instrument.  It will be an instrument that learns the acoustic radiation pattern emitted by a speaker.  It is not a perfect acoustic experiment—nor is it meant to be.  Uncertainties and errors abound, especially since I am using the Lego NXT Mindstorms system to construct the instrument.

Animation of the Central Driveshaft

The design is sufficiently complex that I found that I need to document it using the LDraw system, specifically MLCAD.  I have been practicing my animation skills as well.  Here you can see a short animation of the central drive shaft for the acoustic platform.  The gears are turning at the appropriate rates and everything.  However, there is an aliasing effect in this downsampled image (which used to be referred to as the wagon wheel effect).  So it may look as if some gears are rotating backwards, or not at all.  If you click on the image, you can download a 6 MB version that is much smoother. 

The longer animation will appear in two talks I am giving at the University at Albany this week:
NTIR 2007 and PASCAL 2006.

Kevin Knuth
Albany NY

Lego Geneva Mechanism

I recently designed a Geneva Mechanism that I will be using in my Lego Laser Scanner.  The Geneva Mechanism takes smooth rotary motion and converts it to intermittent rotary motion.  One can think of it in electronics terms as changing the duty cycle of the oscillation.

Geneva mechanisms were invented in Switzerland for use in clockwork so that the hands of a clock would snap rapidly to their new positions rather than move smoothly across the face of the clock.  They are also used to advance film in film projectors.  They are responsible for that clicking noise that film projectors make.

Lego Geneva Mechanism

Above is an image of my design rendered using the Lego CAD LDraw tools that I discussed in earlier posts.

I have been practicing with animating Lego designs, and I have figured it out.  Below is an animated GIF of my Geneva Mechanism.  It is a pretty big file, so it may take some time to download.  Notice that I cheated a little and included just enough frames to rotate the wheel 90 degrees, since it is mostly 4-fold symmetric (but not exactly).

Geneva Mechanism Image

The animation was challenging in that there are three moving parts: the rotating arm, the latch, and the wheel.  I designed each of the pieces in MLCAD and made sure that they were positioned so that the origin of the three pieces was centered on the axis that I wished to rotate the image about.  The rotating arm simply rotates a single rate described by 155-clock, where the clock is a variable in the ray-tracing program POV-Ray that I have set to cycle from 0 to 360. One can see that when clock equals zero, the arm starts at 155 degrees.

The arm is only able to rotate the wheel over a 50 degree range, while the wheel rotates a full 90 degrees.  This lead to the following equation that I used the describe the motion of the wheel:

angle = 45+(clock-310)*9/5

Note that the wheel starts turning when the rotating arm gets to 310 degrees, and moves almost twice as fast (9:5 ratio) so that it turns 90 degrees while the clock which controls the rotating arm counts only 50 degrees.

The latch was especially difficult as it is pushed outward by a cam, and I did not have the details of the shape of the Lego cam, nor did I have the patience to measure it myself. The latch arm moves slowly at first away from the wheel and then slows down as it approaches the limit of its motion. My first approximation was a cosine:


Note that the latch does not start moving until the clock is at 237 degrees. At this point, the argument of the cosine is zero, and its value is 1 giving a angular position of -20 degrees. The cosine picks up speed and slows down again as it approaches 30 degress. Once the cam is out of the way, a rubber band (not shown in the illustration) rapidly snaps the latch back into place. To describe this, I merely treated its motion as an acceration:

-50*((clock-305)/55)*((clock-305)/55))+30, where I have implemented the square by multiplying twice. The result is a more realistic motion.

Kevin Knuth
Albany NY

Lego Animations

I forgot my camera when I went to the lab today, so photos of my Lego Laser Scanner will have to wait.

In the meantime, I spent the early evening figuring out how to use the LDraw tools to draw and animate Lego constructions.  To start, I simply made a figure of the four angled liftarm pieces using MLCAD.  There are some nice tutorials for using MLCAD that I described in a previous posting.

I then converted the LDRAW file format to the ray-tracing POV format using L3PAO.  From there I was able use POV-Ray to access the POV script and modify it to make the animation.  The animation was performed by following the Rotation Animation Tutorial by OrionP. 

Lego Animation

The key is to go into the POV file near the end and find the object commands.  Here is one of the four (for my four Lego pieces):

object {
  matrix <1-SW/98,0,0,0,1-SW/20,0,0,0,1-SW/178,SW/2.45,0,SW/-2.225>
  matrix <1,0,0,0,1,0,0,0,1,38,23,-2>
  #if (version >= 3.1) material #else texture #end { Color0 }

The second matrix specification has two parts:
38, 23, -2
The first part is the 3×3 identity matrix, and the second is a translation.

To rotate the pieces, simply remove the translation.  Then apply a rotation about the objects center of mass, then translate it.  The code looks like this…

 object {
  matrix <1-SW/98,0,0,0,1-SW/20,0,0,0,1-SW/178,SW/2.45,0,SW/-2.225>
  matrix <1,0,0,0,1,0,0,0,1,0,0,0>  rotate<0,0,45> translate<38,23,-2>  translate<0,-50,0>
  #if (version >= 3.1) material #else texture #end { Color0 }

This will rotate the piece about the z-axis by 45 degrees.

To make an animation, we simply replace 45 by clock (or clock * some number).  POV has a variable clock, which advances in time with each rendering.  This will increase the rotation.

To pull this off, you need an .ini file.  Following OrionP’s lead, this is what mine looks like:

; Animation INI File

Final_Frame= 30

;Subset_Start_Frame = 1
;Subset_End_Frame = 30



; T – Uncompressed Tar 24-bit File
; N – New PNG (portable network graphics) format
; S – System-specific such as Mac Pict or Windows BMP
; C – Compressed Targa-24 format (RLE, run length encoded)
; P – Unix PPM format   

This gives me 30 frames with the clock going from 0 to 360 (around the clock so to speak).
To get POV-Ray to use the .ini file, you have to click on the ini icon and set the ini file.
Then run it!

I then took the 30 .png images and converted them to gifs in Adobe Photoshop.
Last, I used Adobe ImageReady to put the gifs together into an animated gif.

This is admittedly a crappy tutorial… its late!
So I promise that I will write up a more detailed one in the near future.

In the immortal words or Tor Johnson, “Time for go to bed!”

Tor Johnson in THE UNEARTHLY (featured on MST3K) 

Kevin Knuth
Albany NY

Lego Mechanisms

I am in the process of making a Lego Laser Scanner. The instrument is designed to move a mirror both back and forth and up and down to reflect a laser beam in any direction within a solid angle defined by the range of motion of the mirror. At this stage, the Lego Laser Scanner is more like a Lego Laser Show as it has two motors that rotate at distinct and programmable rates to produce Lissajous figures with the reflected laser beam. Stay tuned, as next week, I plan to have photos and a movie.

To make a useful scanner, I would prefer to use one motor rather than two. This will require some complex gearing, but it is straight-forward. The part that had me a bit puzzled was the fact that I want the scanner to make one horizontal sweep while maintaining a constant vertical position. Once the horizontal sweep is finished, I need it to nudge the vertical orientation of the mirror just a bit, and then perform another horizontal sweep and so on. How to do this with a single motor was not clear. Until I came across a set of fabulous mechanisms by Leo Dorst of the Intelligent Systems Laboratory Amsterdam at the University of Amsterdam in The Netherlands.

Leo Dorst's Design for a Geneva Mechanism

Leo Dorst created a Lego version of the Geneva Mechanism, which moves film through a projector by holding it still while intermittently feeding it through the mechanism. His sketch is above, but better images and instructions exist on his website. He has a wide variety of Lego Mechanisms, that I am sure I will find useful in the near future.

In the meantime, his design (below) of a six degree-of-freedom robotic arm is fantastic!!!

Leo Dorst's Design of a Robotic Arm

I have found the books below to be very good.

Kevin Knuth
Albany NY

Rendering Lego Figures

A couple of weeks ago, I described the free software package called LDraw that with MLCad and POV-Ray allows you to design Lego creations and illustrate them with ray tracing software.  The software actually goes far beyond this, as MLCad is a real Computer Aided Design program that allows you to save the steps so that you can automatically generate instructions for your Lego creations.  It also generates a Parts List so that you know which parts you will need beforehand.

I was playing around with it this weekend, and made one of the spaceships described in a good online tutorial.  Then I rendered him with POV-Ray, and then overlaid the Lego image over a lovely picture of Saturn.  The result is: Our Hero Races Past Saturn

Our Hero Races Past Saturn

Go ahead and laugh… that’s the whole point!
Kevin Knuth
Albany NY