Main   Next

Basic Construction


Topics
Design principles
General familiarity with robots


Preparation
Enough kits for groups of 3-4.
Pre-program each RCX with sample programs (see bottom for examples) that only use motors. Having a program th\ at moves the robot erratically around the floor and crashes into walls helps emphasize the need for solidly cons\ tructed robots.


Handouts
Tankbot building instructions (designed by Carnegie Mellon)


Lesson
Have the students form groups of 3-4. Give each group a kit and instruct them to build a robot that has 2 motors, 4 wheels and an RCX. An example robot may be shown briefly but should be removed once the building starts.

Instructors should wander to all the groups suggesting ways to build more durable robots. Instructors should also make use of the pre-programmed programs to show why some designs work better than others.

After all the groups have a working robot hand out the tankbot instructions and have all the groups build it. It is ok if the end robot varies slightly but it works better if all the groups have simmiler robots.


Below are two programs that make good inital programs to place on the RCX before students start building. These are NOT simple programs, do not expect your students to understand this code yet.

Play Mary Had A Little Lamb
  import josx.platform.rcx.*;
/**
* Plays Marry had a little lamb as the robot
* moves arround the floor
*
**/


public class Mary{
    public static void main (String[] args)
    throws Exception {
        // the length of the note plus the length
        // of the pause. 40 centiseconds = 400 milliseconds
        // so 400 milliseconds of note and 100 milliseconds of pause
        int pause = 500;

        // Robot starts forward
        Motor.A.forward();
        Motor.C.forward();

        // begin playing song
        Sound.playTone(494,40);// B
        Thread.sleep(pause);
        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(392,40);// G
        Thread.sleep(pause);
        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);

        // Robot turns right
        Motor.A.backward();

        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);
        Sound.playTone(294,40);// D
        Thread.sleep(pause);
        Sound.playTone(294,40);// D
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);

        // Robot goes backward
        Motor.C.backward();

        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(392,40);// G
        Thread.sleep(pause);
        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);

        // Robot goes forward
        Motor.A.forward();
        Motor.C.forward();

        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(494,40);// B
        Thread.sleep(pause);
        Sound.playTone(440,40);// A
        Thread.sleep(pause);
        Sound.playTone(392,40);// G
        Thread.sleep(pause);

        // Robot Stops
        Motor.A.stop();
        Motor.C.stop();

    }
}


Move arround the floor randomly
  import josx.platform.rcx.*;
import java.util.Random;

/**
* Moves the robot randomly arround the floor
* randomly turns right or left and makes a
* different sound for each
**/



public class Rand
{
    public static void main (String[] args)
    throws Exception
    {
    // start the random number generator
    int rand; // var to temperarily hold random values

    // set motors to their top power
    Motor.A.setPower(7);
    Motor.C.setPower(7);

    // create an infinite loop so the robot will continue
    // the program till turned off
    while (true){
        // robot forward for a random time 0 - 2 seconds
        Motor.A.forward();
        Motor.C.forward();
        rand = (int)(Math.random() * 2000);
        Thread.sleep( rand );

        // robot backward for a random time 0-2 seconds
        Motor.A.backward();
        Motor.C.backward();
        rand = (int)(Math.random() * 2000);
        Thread.sleep( rand );

        // randomly turn left or right for a random time
        // 0 - 2 seconds, play a different sound for
        // left and right
        rand = (int)(Math.random() * 2000);
        if (rand > 1000) {
            Motor.A.forward();
            Sound.systemSound(true, 2); // play decending sound
        }
        else {
            Motor.C.forward();
            Sound.systemSound(true, 3); // play accending sound
        }
        rand = (int)(Math.random() * 2000);
        Thread.sleep( rand );
        }
    }
}


Main   Next