Lego Fair

I’ve built this Lego Fair after visiting an amusement park. Looking at some attractions, I figured that it couldn’t be too difficult to build one myself.

And actually, I’m quite happy with the result.

Lego Fair

As you can see, I used a mix of Lego Duplo pieces for a sturdy base. The mechanics were built mostly with Lego Technic parts, and the electronics come from my Lego Mindstorms set.

You can see it in action in this video. Just look at the smile on the face of those stormtroopers!

Lego Fair from Baruman on Vimeo.

Lego Mindstorms comes out of the box with a visual programming language.

But if you want, you can do your programming in java using LeJOS. The site clearly explains the steps on how to set this up. And you can revert back to visual programming in a matter of seconds if you grow tired of java.

With visual programming, you can develop much faster. But when you start to work with some variables, then I have a preference for java.

Here’s my coding:

FairProgram.java


package fair;

import lejos.utility.Delay;

public class FairProgram {

                Lever l;

                Rotator r;

                public FairProgram(){

                               l = new Lever();

                               r = new Rotator();

                }

                public void startProgram1() throws Exception{

                               l.lift("UP", "SMALL");

                               r.rotate("FORWARD","SLOW");

                               Delay.msDelay(5000);

                               r.rotate("FORWARD","MEDIUM");

                               Delay.msDelay(5000);

                               r.rotate("FORWARD","FAST");

                               Delay.msDelay(5000);

                               l.lift("UP", "LARGE");

                               r.rotate("FORWARD","MEDIUM");

                               Delay.msDelay(5000);

                               r.rotate("BACKWARD","SLOW");

                               Delay.msDelay(5000);

                               l.lift("DOWN", "LARGE");

                               r.rotate("BACKWARD","FAST");

                               Delay.msDelay(5000);

                               r.stop();

                               l.lift("DOWN", "SMALL");

                               l.close();

                               r.close();

                                               }

} 

Lever.java


package fair;

import lejos.hardware.motor.EV3LargeRegulatedMotor;

import lejos.hardware.port.MotorPort;

import lejos.robotics.RegulatedMotor;

public class Lever {

                private RegulatedMotor lever;

                private static int liftSpeed = 90;

                private static int smallRotation = 360;

                private static int largeRotation = smallRotation * 3;

                private static int acceleration = 60; // default = 6000

                public Lever(){

                               lever = new EV3LargeRegulatedMotor(MotorPort.C);

                               lever.setSpeed(liftSpeed);

                               lever.setAcceleration(acceleration);

                }

                public void lift(String direction, String liftSize) throws Exception{

                               int multiplier;

                               int rotation;

                               switch(direction){

                                               case("UP"): 

                                                               multiplier = 1;

                                                               break;

                                               case ("DOWN"): 

                                                               multiplier = -1;

                                                               break;

                                               default: 

                                                               throw new Exception();

                               }

                               switch(liftSize){

                                               case("SMALL"): 

                                                               rotation = smallRotation;

                                                               break;

                                               case ("LARGE"): 

                                                               rotation = largeRotation;

                                                               break;

                                               default: 

                                                               throw new Exception();

                               }

                               lever.rotate(multiplier * rotation);

                }

                public void close(){

                               lever.close();

                }

} 

Rotator.java


package fair;

import lejos.hardware.motor.EV3MediumRegulatedMotor;

import lejos.hardware.port.MotorPort;

import lejos.robotics.RegulatedMotor;

public class Rotator {

                private RegulatedMotor rotator;

                private static int slowSpeed = 150;

                private static int mediumSpeed = 300;

                private static int fastSpeed = 450;

                private static int acceleration = 60; // default = 6000

                public Rotator(){

                               rotator = new EV3MediumRegulatedMotor(MotorPort.A);

                               rotator.setAcceleration(acceleration);

                }

                public void rotate(String direction, String speed) throws Exception{

                               switch(speed){

                                               case("SLOW"):

                                                               rotator.setSpeed(slowSpeed);

                                                               break;

                                               case("MEDIUM"):

                                                               rotator.setSpeed(mediumSpeed);

                                                               break;

                                               case("FAST"):

                                                               rotator.setSpeed(fastSpeed);

                                                               break;

                                               default: throw new Exception();

                               }

                               switch(direction){

                                               case ("BACKWARD"):

                                                               rotator.forward();

                                                               break;

                                               case("FORWARD"):

                                                               rotator.backward();

                                                               break;

                                               default: throw new Exception();

                               }

                }

                public void stop(){

                               rotator.flt();

                }

                public void close(){

                               rotator.close();

                }

} 

Note: after the windows 10 upgrade, my PC failed a recognise the Mindstorms brick for LeJOS. I had to apply the workaround mentioned in this post.

2 thoughts on “Lego Fair

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s