ДО курс по робототехнике

Я Я-2Информация о спецкурсе тут

4 апреля 2013 г.

LEGO Mindstorms NXT 2.0 instructions

NXT и NXC - последнее под linux

LEGO Mindstorms NXT 2.0 instructions

Instructions for building the Shooterbot, Robogator, Color Sorter, and Alpha Rex.

Introduction

The instructions for building the four main LEGO Mindstorms NXT 2.0 models are distributed only on software that does not support Linux. The instructions are reproduced here.

Programming the NXT with Linux

The accompanying programs supplied here are written in NXC. NXC is a simple C-like programming language supported by NBCNBC allows you to write NXT programs and download them to the NXT. This configuration guide for NBC on Linux is useful.

Compiling an NXC program

A typical command to compile and download an NXC program by USB would be
nbc -d -S=usb filename.nxc

Shooterbot

Can you build and program a Shooterbot to guard your room while you are away?
  1. Driving base

    • Building guide
      Can you build a Shooterbot to move forward and then move back again?
      Instruction 1 of 22
      Instruction 2 of 22
      Instruction 3 of 22
      Instruction 4 of 22
      Instruction 5 of 22
      Instruction 6 of 22
      Instruction 7 of 22
      Instruction 8 of 22
      Instruction 9 of 22
      Instruction 10 of 22
      Instruction 11 of 22
      Instruction 12 of 22
      Instruction 13 of 22
      Instruction 14 of 22
      Instruction 15 of 22
      Instruction 16 of 22
      Instruction 17 of 22
      Instruction 18 of 22
      Instruction 19 of 22
      Instruction 20 of 22
      Instruction 21 of 22
      Instruction 22 of 22
    • Programming guide
      Can you program a Shooterbot to move forward on the test pad and then move in reverse to its start position?
      // shooterbot_1.nxc
      // Move forward and then reverse.
      
      task main ()
      {
        // Move forward at 75% power for 2 seconds
        OnFwd (OUT_BC ,75); Wait (2000);
      
        // Reverse at 75% power for 2 seconds
        OnRev (OUT_BC ,75); Wait (2000);
      
        // Brake
        Off (OUT_BC);
      }
      
    • Test guide
      Download your program. Place the Shooterbot on the test pad and run the program.
  2. Color detection

    • Building guide
      Can you build a Shooterbot to test colors on the test pad?
      Instruction 1 of 4
      Instruction 2 of 4
      Instruction 3 of 4
      Instruction 4 of 4
    • Programming guide
      Can you program a Shooterbot to move forward, find the red line, turn around, and then move back to its start position?
      // shooterbot_2.nxc
      // Move forward to the red line, turn around, and move back to the start
      // position.
      
      // Adjust this number to suit your surface / battery power
      #define TURN_TIME 1750
      
      task main ()
      {
        long t0, t1;
      
        // Bring the color sensor on-line
        SetSensorColorFull (S3);
      
        // Record the time when the forward movement starts
        t0 = CurrentTick ();
      
        // Move forward to the red line
        OnFwd (OUT_BC ,75);
        until (INPUT_REDCOLOR == SENSOR_3);
        t1 = CurrentTick (); // Record the time when the forward movement finishes
        Off (OUT_BC);
      
        // Turn 180 degrees to the right
        OnFwd (OUT_C, 75); OnRev (OUT_B, 75); Wait (TURN_TIME); Off (OUT_BC);
      
        // Move back to the start
        OnFwd (OUT_BC ,75); Wait (t1 - t0); Off (OUT_BC);
      }
      
    • Test guide
      Download your program. Place the Shooterbot on the test pad and run the program.
  3. Shooter

    • Building guide
      Can you build the Shooterbot to shoot balls at objects? You will have to build the shooter on the front of your Shooterbot.
      Instruction 1 of 14
      Instruction 2 of 14
      Instruction 3 of 14
      Instruction 4 of 14
      Instruction 5 of 14
      Instruction 6 of 14
      Instruction 7 of 14
      Instruction 8 of 14
      Instruction 9 of 14
      Instruction 10 of 14
      Instruction 11 of 14
      Instruction 12 of 14
      Instruction 13 of 14
      Instruction 14 of 14
    • Programming guide
      Can you program Shooterbot to drive around and shoot while showing different colored lights?
      // shooterbot_3.nxc
      // Drive around and shoot while showing different colored lights.
      
      #define BULLETS 7
      #define FLASH_DURATION 300
      #define TURN_TIME 3000
      
      int bullets_remaining = BULLETS;
      bool fire = false;
      
      task flashing_lights ()
      {
        int red_flashes;
      
        while (bullets_remaining > 0)
          {
            // Alternate between the red, green, and blue lamps
            SetSensorColorRed   (IN_3); Wait (FLASH_DURATION);
            SetSensorColorGreen (IN_3); Wait (FLASH_DURATION);
            SetSensorColorBlue  (IN_3); Wait (FLASH_DURATION);
          }
      
        // Indicate that no bullets remain
        for (red_flashes = 1; red_flashes <= 10; red_flashes++)
          {
            SetSensorColorRed   (IN_3); Wait (FLASH_DURATION / 2);
            SetSensorColorNone  (IN_3); Wait (FLASH_DURATION / 2);
          }
      
        // Stop the program
        StopAllTasks ();
      }
      
      task shoot ()
      {
        while (true)
          {
            // Check whether to fire a bullet
            if (true == fire)
              {
                // Reset the 'fire a bullet' flag to false
                fire = false;
      
                // Decrement the number of bullets remaining
                bullets_remaining--;
      
                // To fire, make motor A do a single 360 degree rotation
                RotateMotorEx (OUT_A, 75, 360, 0, false, true);
              }
          }
      }
      
      task move ()
      {
        while (bullets_remaining > 0)
          {
            // Do a random turn
            if (0 == Random (2))
              {
                // Left turn
                OnFwd (OUT_B, 75); OnRev (OUT_C, 75);
                Wait (Random (TURN_TIME));
                Off (OUT_BC);
                Wait (1000);
                fire = true;
                Wait (1000);
              }
            else
              {
                // Right turn
                OnFwd (OUT_C, 75); OnRev (OUT_B, 75);
                Wait (Random (TURN_TIME));
                Off (OUT_BC);
                Wait (1000);
                fire = true;
                Wait (1000);
              }
          }
      
      }
      
      task main ()
      {
        // Make these tasks execute simultaneously after main () is finished
        Precedes (flashing_lights, shoot, move);
      }
      
    • Test guide
      Download the program. Place the Shooterbot in the middle of the test pad and run the program.
  4. Locate objects

    • Building guide
      Can you build the Shooterbot to protect your room? You will have to add the Ultrasonic Sensor to your Shooterbot.
      Instruction 1 of 2
      Instruction 2 of 2
    • Programming guide
      Can you program the Shooterbot to scan your room and detect objects? If an object is closer than 40cm, the Shooterbot should shine a warning light and then shoot if the object does not move away.
      // shooterbot_4.nxc
      // If an object is to close, shine a warning light and then shoot if
      // the object does not move away.
      
      #define BULLETS 7
      #define FLASH_DURATION 200
      #define THRESHOLD 40
      #define WARNING_TIME 4000
      
      #define start_turning(power) OnFwd (OUT_C, power); OnRev (OUT_B, power);
      
      task main ()
      {
        long t0;
        int bullets_remaining = BULLETS;
      
        SetSensorLowspeed (S4); // Bring the ultrasonic sensor on-line
        SetSensorColorGreen (S3); // Set the lamp to show all-clear
      
        while (bullets_remaining > 0)
          {
            start_turning (50);
            until (SensorUS (S4) < THRESHOLD); // Scan for close objects
            Off (OUT_BC); // Stop turning
            t0 = CurrentTick ();
      
            while ((CurrentTick () - t0) < WARNING_TIME)
              { // Emit the warning - a flashing red lamp
                SetSensorColorNone (S3); Wait (FLASH_DURATION);
                SetSensorColorRed  (S3); Wait (FLASH_DURATION);
              }
      
            if (SensorUS (S4) < THRESHOLD)
              {
                bullets_remaining--;
                RotateMotorEx (OUT_A, 75, 360, 0, false, true); // Shoot
                Wait (1000); // Give motor A time to shoot
              }
      
            SetSensorColorGreen (S3); // Set the lamp to show all-clear
          }
      
        Off (OUT_BC); // Stop turning
        TextOut (8, LCD_LINE4, "OUT OF BULLETS", true);
        Wait (7000);
        StopAllTasks (); // Stop the program
      }
      
    • Test guide
      Download the program. Place the Shooterbot in the middle of the test pad and run the program.

Robogator

Can you build and program a Robogator that attacks objects and protects its territory?
  1. Jaws

    • Building guide
      Can you build a robot with jaws that open and close?
      Instruction 1 of 20
      Instruction 2 of 20
      Instruction 3 of 20
      Instruction 4 of 20
      Instruction 5 of 20
      Instruction 6 of 20
      Instruction 7 of 20
      Instruction 8 of 20
      Instruction 9 of 20
      Instruction 10 of 20
      Instruction 11 of 20
      Instruction 12 of 20
      Instruction 13 of 20
      Instruction 14 of 20
      Instruction 15 of 20
      Instruction 16 of 20
      Instruction 17 of 20
      Instruction 18 of 20
      Instruction 19 of 20
      Instruction 20 of 20
    • Programming guide
      Can you program your robot to open and close its jaws?
      // robogator_1.nxc
      // Open and close the jaws
      
      // Sample the motor rotation speed every this number of milliseconds
      #define ROTATION_SAMPLE_RESOLUTION 50
      
      // The approximate 'degrees per second' rotation of motor A
      long dps_a = 0;
      
      task motor_speed_monitor ()
      {
        long mrc_a_0, mrc_a_1; // mrc == motor rotation count
        unsigned long t_a_0, t_a_1;
      
        while (true)
        {
          // Record the rotation count and the time
          mrc_a_0 = MotorRotationCount (OUT_A); t_a_0 = CurrentTick ();
      
          Wait (ROTATION_SAMPLE_RESOLUTION);
      
          // Again, record the rotation count and the time
          mrc_a_1 = MotorRotationCount (OUT_A); t_a_1 = CurrentTick ();
      
          // Calculate the average rotation rate over that time interval
          dps_a = ((mrc_a_1 - mrc_a_0) * 1000) / (t_a_1 - t_a_0);
        }
      }
      
      task bite ()
      {
        while (true)
        {
          // Assume the jaws are closed to begin with - open them
          OnFwd (OUT_A, 40); Wait (100); // Wait > ROTATION_SAMPLE_RESOLUTION
          until (10 > dps_a); // Wait until the jaws have opened and are practically still
          Off (OUT_A);
      
          // Close the jaws
          OnRev (OUT_A, 40); Wait (100);
          until (-10 < dps_a); // Reverse rotations are negative
          Off (OUT_A);
        }
      }
      
      task main ()
      {
        Precedes (bite, motor_speed_monitor);
      }
      
    • Test guide
      Download and run the program. Your Robogator jaws should open and close.
  2. Eyes

    • Building guide
      Can you make your Robogator see objects and attack them if they get too close?
      Instruction 1 of 4
      Instruction 2 of 4
      Instruction 3 of 4
      Instruction 4 of 4
    • Programming guide
      Can you program your robot to bite when objects get too close?
      // robogator_2.nxc
      // Open and close the jaws when objects are close
      
      // Sample the motor rotation speed every this number of milliseconds
      #define ROTATION_SAMPLE_RESOLUTION 50
      
      // Bite objects which come closer than this
      #define THRESHOLD 40
      
      // The approximate 'degrees per second' rotation of motor A
      long dps_a = 0;
      
      task motor_speed_monitor ()
      {
        long mrc_a_0, mrc_a_1; // mrc == motor rotation count
        unsigned long t_a_0, t_a_1;
      
        while (true)
        {
          mrc_a_0 = MotorRotationCount (OUT_A); t_a_0 = CurrentTick ();
      
          Wait (ROTATION_SAMPLE_RESOLUTION);
      
          mrc_a_1 = MotorRotationCount (OUT_A); t_a_1 = CurrentTick ();
      
          dps_a = ((mrc_a_1 - mrc_a_0) * 1000) / (t_a_1 - t_a_0);
        }
      }
      
      task bite ()
      {
        SetSensorLowspeed (S4); // Bring the ultrasonic sensor on-line
      
        while (true)
        {
          until (SensorUS (S4) < THRESHOLD); // Scan for close objects
      
          // Assume the jaws are closed to begin with - open them
          OnFwd (OUT_A, 40); Wait (100); // Wait > ROTATION_SAMPLE_RESOLUTION
          until (10 > dps_a); // Wait until the motor stops
          Off (OUT_A);
      
          // Close the jaws
          OnRev (OUT_A, 40); Wait (100);
          until (-10 < dps_a); // Reverse rotations are negative
          Off (OUT_A);
        }
      }
      
      task main ()
      {
        Precedes (bite, motor_speed_monitor);
      }
      
    • Test guide
      Download and run the program. Move your hand towards the Robogator's eyes. The Robogator's jaws should start biting. Move your hand away and the Robogator should stop biting.
  3. Legs

    • Building guide
      Can you build a robot that can walk?
      Instruction 1 of 65
      Instruction 2 of 65
      Instruction 3 of 65
      Instruction 4 of 65
      Instruction 5 of 65
      Instruction 6 of 65
      Instruction 7 of 65
      Instruction 8 of 65
      Instruction 9 of 65
      Instruction 10 of 65
      Instruction 11 of 65
      Instruction 12 of 65
      Instruction 13 of 65
      Instruction 14 of 65
      Instruction 15 of 65
      Instruction 16 of 65
      Instruction 17 of 65
      Instruction 18 of 65
      Instruction 19 of 65
      Instruction 20 of 65
      Instruction 21 of 65
      Instruction 22 of 65
      Instruction 23 of 65
      Instruction 24 of 65
      Instruction 25 of 65
      Instruction 26 of 65
      Instruction 27 of 65
      Instruction 28 of 65
      Instruction 29 of 65
      Instruction 30 of 65
      Instruction 31 of 65
      Instruction 32 of 65
      Instruction 33 of 65
      Instruction 34 of 65
      Instruction 35 of 65
      Instruction 36 of 65
      Instruction 37 of 65
      Instruction 38 of 65
      Instruction 39 of 65
      Instruction 40 of 65
      Instruction 41 of 65
      Instruction 42 of 65
      Instruction 43 of 65
      Instruction 44 of 65
      Instruction 45 of 65
      Instruction 46 of 65
      Instruction 47 of 65
      Instruction 48 of 65
      Instruction 49 of 65
      Instruction 50 of 65
      Instruction 51 of 65
      Instruction 52 of 65
      Instruction 53 of 65
      Instruction 54 of 65
      Instruction 55 of 65
      Instruction 56 of 65
      Instruction 57 of 65
      Instruction 58 of 65
      Instruction 59 of 65
      Instruction 60 of 65
      Instruction 61 of 65
      Instruction 62 of 65
      Instruction 63 of 65
      Instruction 64 of 65
      Instruction 65 of 65
    • Programming guide
      Can you program the Robogator to walk forward and start biting when objects get too close?
      // robogator_3.nxc
      // Open and close the jaws and walk forward when objects are close
      
      // Sample the motor rotation speed every this number of milliseconds
      #define ROTATION_SAMPLE_RESOLUTION 50
      
      // Bite objects which come closer than this
      #define THRESHOLD 40
      
      // Walk forward for up to this many steps when an object is close
      #define MAX_STEPS_FORWARD 3
      
      // The approximate 'degrees per second' rotation of motor A
      long dps_a = 0;
      
      task motor_speed_monitor ()
      {
        long mrc_a_0, mrc_a_1; // mrc == motor rotation count
        unsigned long t_a_0, t_a_1;
      
        while (true)
        {
          mrc_a_0 = MotorRotationCount (OUT_A); t_a_0 = CurrentTick ();
      
          Wait (ROTATION_SAMPLE_RESOLUTION);
      
          mrc_a_1 = MotorRotationCount (OUT_A); t_a_1 = CurrentTick ();
      
          dps_a = ((mrc_a_1 - mrc_a_0) * 1000) / (t_a_1 - t_a_0);
        }
      }
      
      task bite ()
      {
        while (true)
        {
          until (SensorUS (S4) < THRESHOLD); // Scan for close objects
      
          // Assume the jaws are closed to begin with
          OnFwd (OUT_A, 40); Wait (100); // Wait > ROTATION_SAMPLE_RESOLUTION
          until (10 > dps_a); // Wait until the motor stops
          Off (OUT_A);
          OnRev (OUT_A, 40); Wait (100);
          until (-10 < dps_a); // Reverse rotations are negative
          Off (OUT_A);
        }
      }
      
      task walk ()
      {
        int steps;
      
        while (true)
        {
          until (SensorUS (S4) < THRESHOLD); // Scan for close objects
      
          // Walk forward while an object is close
          steps = 0;
          while (SensorUS (S4) < THRESHOLD && steps < MAX_STEPS_FORWARD)
          {
            RotateMotorEx (OUT_BC, -100, 360, 0, true, true);
            steps += 1;
          }
        }
      }
      
      task main ()
      {
        SetSensorLowspeed (S4); // Bring the ultrasonic sensor on-line
      
        Precedes (bite, motor_speed_monitor, walk);
      }
      
    • Test guide
      Download the program. Place your alligator on the test pad and run the program.
  4. Tail

    • Building guide
      Can you build the tail and add sensors to the Robogator so it knows where its legs are?
      Instruction 1 of 17
      Instruction 2 of 17
      Instruction 3 of 17
      Instruction 4 of 17
      Instruction 5 of 17
      Instruction 6 of 17
      Instruction 7 of 17
      Instruction 8 of 17
      Instruction 9 of 17
      Instruction 10 of 17
      Instruction 11 of 17
      Instruction 12 of 17
      Instruction 13 of 17
      Instruction 14 of 17
      Instruction 15 of 17
      Instruction 16 of 17
      Instruction 17 of 17
    • Programming guide
      Can you program Robogator to protect its territory: lunge forward, bite, and crawl back?
      // robogator_4.nxc
      // When an object is close: open and close the jaws, walk forward,
      // and then move back
      
      // Sample the motor rotation speed every this number of milliseconds
      #define ROTATION_SAMPLE_RESOLUTION 50
      
      // Bite objects which come closer than this
      #define THRESHOLD 60
      
      // Walk forward for up to this many steps when an object is close
      #define MAX_STEPS_FORWARD 3
      
      // The approximate 'degrees per second' rotation of motor A
      long dps_a = 0;
      
      task motor_speed_monitor ()
      {
        long mrc_a_0, mrc_a_1; // mrc == motor rotation count
        unsigned long t_a_0, t_a_1;
      
        while (true)
        {
          mrc_a_0 = MotorRotationCount (OUT_A); t_a_0 = CurrentTick ();
      
          Wait (ROTATION_SAMPLE_RESOLUTION);
      
          mrc_a_1 = MotorRotationCount (OUT_A); t_a_1 = CurrentTick ();
      
          dps_a = ((mrc_a_1 - mrc_a_0) * 1000) / (t_a_1 - t_a_0);
        }
      }
      
      task bite ()
      {
        while (true)
        {
          until (SensorUS (S4) < THRESHOLD); // Scan for close objects
      
          // Assume the jaws are closed to begin with
          OnFwd (OUT_A, 40); Wait (100); // Wait > ROTATION_SAMPLE_RESOLUTION
          until (10 > dps_a); // Wait until the motor stops
          Off (OUT_A);
          OnRev (OUT_A, 40); Wait (100);
          until (-10 < dps_a); // Reverse rotations are negative
          Off (OUT_A);
        }
      }
      
      task walk ()
      {
        int i, steps;
      
        // Use the touch sensors to align the legs initially
        OnFwd (OUT_B, -100);
        until (1 == SENSOR_1);
        Off (OUT_B); RotateMotor (OUT_B, -100, 45);
      
        OnFwd (OUT_C, -100);
        until (1 == SENSOR_2);
        Off (OUT_C); RotateMotor (OUT_C, -100, 45);
      
        while (true)
        {
          // Walk forward while an object is close
          steps = 0;
          while (SensorUS (S4) < THRESHOLD && steps < MAX_STEPS_FORWARD)
          {
            RotateMotorEx (OUT_BC, -100, 360, 0, true, true);
            steps += 1;
          }
      
          // Walk back to the original position
          Wait (1000);
          while (steps > 0)
          {
            RotateMotorEx (OUT_BC, 90, 360, 0, true, true);
            steps -= 1;
          }
        }
      
      }
      
      task main ()
      {
        SetSensorLowspeed (S4); // Bring the ultrasonic sensor on-line
        SetSensorTouch (S1); // Bring the touch sensors on-line
        SetSensorTouch (S2);
      
        Precedes (bite, motor_speed_monitor, walk);
      }
      
    • Test guide
      Download the program. Place Robogator on the test pad and run the program.

Color Sorter

Can you build and program the Color Sorter to sort balls by color?
  1. Dispenser

    • Building guide
      Can you build a dispenser that separates balls one by one?
      Instruction 1 of 102
      Instruction 2 of 102
      Instruction 3 of 102
      Instruction 4 of 102
      Instruction 5 of 102
      Instruction 6 of 102
      Instruction 7 of 102
      Instruction 8 of 102
      Instruction 9 of 102
      Instruction 10 of 102
      Instruction 11 of 102
      Instruction 12 of 102
      Instruction 13 of 102
      Instruction 14 of 102
      Instruction 15 of 102
      Instruction 16 of 102
      Instruction 17 of 102
      Instruction 18 of 102
      Instruction 19 of 102
      Instruction 20 of 102
      Instruction 21 of 102
      Instruction 22 of 102
      Instruction 23 of 102
      Instruction 24 of 102
      Instruction 25 of 102
      Instruction 26 of 102
      Instruction 27 of 102
      Instruction 28 of 102
      Instruction 29 of 102
      Instruction 30 of 102
      Instruction 31 of 102
      Instruction 32 of 102
      Instruction 33 of 102
      Instruction 34 of 102
      Instruction 35 of 102
      Instruction 36 of 102
      Instruction 37 of 102
      Instruction 38 of 102
      Instruction 39 of 102
      Instruction 40 of 102
      Instruction 41 of 102
      Instruction 42 of 102
      Instruction 43 of 102
      Instruction 44 of 102
      Instruction 45 of 102
      Instruction 46 of 102
      Instruction 47 of 102
      Instruction 48 of 102
      Instruction 49 of 102
      Instruction 50 of 102
      Instruction 51 of 102
      Instruction 52 of 102
      Instruction 53 of 102
      Instruction 54 of 102
      Instruction 55 of 102
      Instruction 56 of 102
      Instruction 57 of 102
      Instruction 58 of 102
      Instruction 59 of 102
      Instruction 60 of 102
      Instruction 61 of 102
      Instruction 62 of 102
      Instruction 63 of 102
      Instruction 64 of 102
      Instruction 65 of 102
      Instruction 66 of 102
      Instruction 67 of 102
      Instruction 68 of 102
      Instruction 69 of 102
      Instruction 70 of 102
      Instruction 71 of 102
      Instruction 72 of 102
      Instruction 73 of 102
      Instruction 74 of 102
      Instruction 75 of 102
      Instruction 76 of 102
      Instruction 77 of 102
      Instruction 78 of 102
      Instruction 79 of 102
      Instruction 80 of 102
      Instruction 81 of 102
      Instruction 82 of 102
      Instruction 83 of 102
      Instruction 84 of 102
      Instruction 85 of 102
      Instruction 86 of 102
      Instruction 87 of 102
      Instruction 88 of 102
      Instruction 89 of 102
      Instruction 90 of 102
      Instruction 91 of 102
      Instruction 92 of 102
      Instruction 93 of 102
      Instruction 94 of 102
      Instruction 95 of 102
      Instruction 96 of 102
      Instruction 97 of 102
      Instruction 98 of 102
      Instruction 99 of 102
      Instruction 100 of 102
      Instruction 101 of 102
      Instruction 102 of 102
    • Programming guide
      Can you program the dispenser to tilt and dispense one ball at a time?
      // colorsorter_1.nxc
      // Dispense one ball at a time
      
      // The number of balls to be sorted
      #define BALLS 4
      
      // Get the dispenser in a standard position
      void reset_dispenser ()
      {
        OnRev (OUT_B, 80);
        until (1 == SENSOR_1);
        Off (OUT_B);
        Wait (1000);
      }
      
      // Dispense one ball
      void dispense_ball ()
      {
        reset_dispenser ();
        RotateMotor (OUT_B, 60, 720);
        Wait (1000);
      }
      
      task main ()
      {
        int i;
      
        // Bring the tilting mechanism's touch sensor on-line
        SetSensorTouch (S1);
      
        i = 0;
        while (i++ < BALLS)
        {
          dispense_ball ();
        }
      
      }
      
    • Test guide
      Download your program. Place the Color Sorter in the middle of the test pad. Put a couple of balls in the dispenser and run the program.
  2. Color detector

    • Building guide
      Can you build a color detector that can recognise the different ball colors?
      Instruction 1 of 6
      Instruction 2 of 6
      Instruction 3 of 6
      Instruction 4 of 6
      Instruction 5 of 6
      Instruction 6 of 6
    • Programming guide
      Can you make a program that can tell the difference between the colors of the balls?
      // colorsorter_2.nxc
      // Dispense one ball at a time - display the color of each ball
      
      // The number of balls to be sorted
      #define BALLS 4
      
      // Get the dispenser in a standard position
      void reset_dispenser ()
      {
        OnRev (OUT_B, 80);
        until (1 == SENSOR_1);
        Off (OUT_B);
        Wait (1000);
      }
      
      // Get a ball into the dispenser slot
      void load_ball ()
      {
        RotateMotor (OUT_B, 60, 360);
        Wait (1000);
      }
      
      void dispense_ball ()
      {
        RotateMotor (OUT_B, 60, 360);
        Wait (1000);
      }
      
      void show_color ()
      {
        string ball_color = "";
      
        switch (SENSOR_3)
        {
          case INPUT_BLUECOLOR:
            ball_color = "BLUE";
            break;
          case INPUT_REDCOLOR:
            ball_color = "RED";
            break;
          case INPUT_GREENCOLOR:
            ball_color = "GREEN";
            break;
          case INPUT_YELLOWCOLOR:
            ball_color = "YELLOW";
            break;
          default:
            ball_color = "NONE";
            break;
        }
      
        // Show the ball color
        TextOut (30, LCD_LINE3, ball_color, true);
        Wait (1000);
      }
      
      task main ()
      {
        int i;
      
        // Bring the tilting mechanism's touch sensor on-line
        SetSensorTouch (S1);
      
        // Bring the color sensor on-line
        SetSensorColorFull (S3);
      
        i = 0;
        while (i++ < BALLS)
        {
          // Show the number of balls left to sort
          TextOut (0, LCD_LINE1, "Balls remaining: ", true);
          NumOut  (50, LCD_LINE3, BALLS - (i-1));
      
          reset_dispenser ();
          load_ball ();
          show_color ();
          dispense_ball ();
        }
      
      }
      
    • Test guide
      Download your program. Place the Color Sorter in the middle of the test pad. Run the program.
  3. Sorting tray

    • Building guide
      Can you build a sorting tray that allows the Color Sorter to sort the four different colored balls into their own basket?
      Instruction 1 of 18
      Instruction 2 of 18
      Instruction 3 of 18
      Instruction 4 of 18
      Instruction 5 of 18
      Instruction 6 of 18
      Instruction 7 of 18
      Instruction 8 of 18
      Instruction 9 of 18
      Instruction 10 of 18
      Instruction 11 of 18
      Instruction 12 of 18
      Instruction 13 of 18
      Instruction 14 of 18
      Instruction 15 of 18
      Instruction 16 of 18
      Instruction 17 of 18
      Instruction 18 of 18
    • Programming guide
      Can you program the sorting tray to spin around and place balls of the same color in the same basket?
      // colorsorter_3.nxc
      // Place balls of the same color in the same basket
      
      // Assume there are no balls remaining after this number of retries
      #define RETRIES 2
      
      // Reset the dispensing tray and the basket when these are set to true
      bool reset_dispenser_flag = false;
      bool reset_basket_flag = false;
      
      // Get a ball into the dispenser slot
      void load_ball ()
      {
        Wait (2000);
        // Shake up the balls in the dispenser
        RotateMotor (OUT_B, 90, 400);
        RotateMotor (OUT_B, -90, 400);
        Wait (500);
      }
      
      void dispense_ball ()
      {
        RotateMotor (OUT_B, -90, 360);
        Wait (1000);
      }
      
      // Show the color of the ball on the NXT display
      // Return the value of the color of the ball to the calling task
      string show_color ()
      {
        string ball_color = "";
      
        switch (SENSOR_3)
        {
          case INPUT_BLUECOLOR:
            ball_color = "BLUE";
            break;
          case INPUT_REDCOLOR:
            ball_color = "RED";
            break;
          case INPUT_GREENCOLOR:
            ball_color = "GREEN";
            break;
          case INPUT_YELLOWCOLOR:
            ball_color = "YELLOW";
            break;
          default:
            ball_color = "NONE";
            break;
        }
      
        // Show the ball color
        TextOut (30, LCD_LINE3, ball_color, true);
        Wait (500);
      
        return ball_color;
      }
      
      void align_basket (string ball_color)
      {
        // RED, YELLOW, GREEN, BLUE
        if (ball_color == "YELLOW") {
          RotateMotor (OUT_C, 30, 90);
        }else if (ball_color == "GREEN") {
          RotateMotor (OUT_C, 30, 180);
        }else if (ball_color == "BLUE") {
          RotateMotor (OUT_C, -30, 90);
        }
      }
      
      // Get the dispenser in a standard position
      task reset_dispenser ()
      {
        while (true)
        {
          if (true == reset_dispenser_flag)
          {
            // Get the dispenser into a standard position using the touch sensor
            OnRev (OUT_B, 80);
            until (1 == SENSOR_1);
            Off (OUT_B);
            reset_dispenser_flag = false;
          }
        }
      }
      
      task reset_basket ()
      {
        while (true)
        {
          if (true == reset_basket_flag)
          {
            // Get the basket into a standard position using the touch sensor
            OnFwd (OUT_C, 30);
            until (0 == SENSOR_2); // Unset the touch sensor if it is set
            until (1 == SENSOR_2);
            Off (OUT_C);
            RotateMotor (OUT_C, -30, 30);
            reset_basket_flag = false;
          }
        }
      }
      
      task main ()
      {
        int i;
        string ball_color;
      
        // Bring the tilting mechanism's touch sensor on-line
        SetSensorTouch (S1);
        // Bring the sorting mechanism's touch sensor on-line
        SetSensorTouch (S2);
      
        // Bring the color sensor on-line
        SetSensorColorFull (S3);
      
        StartTask (reset_basket);
        StartTask (reset_dispenser);
      
        while (true)
        {
          // Clear the display
          ResetScreen ();
      
          i = 0;
          do
          {
            // Reset the positions of the dispenser and the baskets in parallel
            reset_dispenser_flag = true;
            reset_basket_flag = true;
      
            // Wait until the reset tasks are both finished
            until (false == reset_dispenser_flag && false == reset_basket_flag);
      
            load_ball (); // Place a ball in the dispenser exit slot
            ball_color = show_color ();
      
            // Check for a ball in the dispenser exit slot
          } while (++i < RETRIES && "NONE" == ball_color)
      
          if ("NONE" == ball_color)
          {
            // Assume no balls are remaining
            TextOut (0, LCD_LINE3, "*** FINISHED ***", true);
            Wait (4000);
            break;
          }
      
          align_basket (ball_color);
          dispense_ball ();
        }
      
        StopAllTasks ();
      }
      
    • Test guide
      Download your program. Place the Color Sorter in the middle of the test pad. Run the program.
  4. Color catapult

    • Building guide
      Can you build a color catapult that throws balls in different directions?
      Instruction 1 of 22
      Instruction 2 of 22
      Instruction 3 of 22
      Instruction 4 of 22
      Instruction 5 of 22
      Instruction 6 of 22
      Instruction 7 of 22
      Instruction 8 of 22
      Instruction 9 of 22
      Instruction 10 of 22
      Instruction 11 of 22
      Instruction 12 of 22
      Instruction 13 of 22
      Instruction 14 of 22
      Instruction 15 of 22
      Instruction 16 of 22
      Instruction 17 of 22
      Instruction 18 of 22
      Instruction 19 of 22
      Instruction 20 of 22
      Instruction 21 of 22
      Instruction 22 of 22
    • Programming guide
      Can you program the color catapult to throw balls of the same color in the same direction?
      // colorsorter_4.nxc
      // Chuck balls of the same color in the same direction
      
      // Assume there are no balls remaining after this number of retries
      #define RETRIES 2
      
      // Reset the dispensing tray and the catapult when these are set to true
      bool reset_dispenser_flag = false;
      bool reset_catapult_flag = false;
      
      // Get a ball into the dispenser slot
      void load_ball ()
      {
        Wait (2000);
        // Shake up the balls in the dispenser
        RotateMotor (OUT_B, 90, 400);
        RotateMotor (OUT_B, -90, 400);
        Wait (500);
      }
      
      void dispense_ball ()
      {
        RotateMotor (OUT_B, -90, 360);
        Wait (1000);
      }
      
      // Show the color of the ball on the NXT display
      // Return the value of the color of the ball to the calling task
      string show_color ()
      {
        string ball_color = "";
      
        switch (SENSOR_3)
        {
          case INPUT_BLUECOLOR:
            ball_color = "BLUE";
            break;
          case INPUT_REDCOLOR:
            ball_color = "RED";
            break;
          case INPUT_GREENCOLOR:
            ball_color = "GREEN";
            break;
          case INPUT_YELLOWCOLOR:
            ball_color = "YELLOW";
            break;
          default:
            ball_color = "NONE";
            break;
        }
      
        // Show the ball color
        TextOut (30, LCD_LINE3, ball_color, true);
        Wait (500);
      
        return ball_color;
      }
      
      void align_catapult (string ball_color)
      {
        // RED, YELLOW, GREEN, BLUE
        if (ball_color == "RED") {
          RotateMotor (OUT_C, 30, 45);
        }else if (ball_color == "YELLOW") {
          RotateMotor (OUT_C, 30, 90);
        }else if (ball_color == "GREEN") {
          RotateMotor (OUT_C, -30, 45);
        }else if (ball_color == "BLUE") {
          RotateMotor (OUT_C, -30, 90);
        }
      }
      
      // Get the dispenser in a standard position
      task reset_dispenser ()
      {
        while (true)
        {
          if (true == reset_dispenser_flag)
          {
            // Get the dispenser into a standard position using the touch sensor
            OnRev (OUT_B, 80);
            until (1 == SENSOR_1);
            Off (OUT_B);
            reset_dispenser_flag = false;
          }
        }
      }
      
      task reset_catapult ()
      {
        while (true)
        {
          if (true == reset_catapult_flag)
          {
            // Get the catapult into a standard position using the touch sensor
            OnFwd (OUT_C, 30); // Unset the touch sensor if it is set by moving toward the front side
            until (0 == SENSOR_2);
      
            OnFwd (OUT_C, -30); // Move back until the touch sensor activates
            until (1 == SENSOR_2);
            Off (OUT_C);
      
            RotateMotor (OUT_C, -30, 15); // A slight adjustment for perfect alignment
            reset_catapult_flag = false;
          }
        }
      }
      
      task main ()
      {
        int i;
        string ball_color;
      
        // Bring the tilting mechanism's touch sensor on-line
        SetSensorTouch (S1);
        // Bring the sorting mechanism's touch sensor on-line
        SetSensorTouch (S2);
      
        // Bring the color sensor on-line
        SetSensorColorFull (S3);
      
        StartTask (reset_catapult);
        StartTask (reset_dispenser);
      
        while (true)
        {
          // Clear the display
          ResetScreen ();
      
          i = 0;
          do
          {
            // Reset the positions of the dispenser and the catapult in parallel
            reset_dispenser_flag = true;
            reset_catapult_flag = true;
      
            // Wait until the reset tasks are both finished
            until (false == reset_dispenser_flag && false == reset_catapult_flag);
      
            load_ball (); // Place a ball in the dispenser exit slot
            ball_color = show_color ();
      
            // Check for a ball in the dispenser exit slot
          } while (++i < RETRIES && "NONE" == ball_color)
      
          if ("NONE" == ball_color)
          {
            // Assume no balls are remaining
            TextOut (0, LCD_LINE3, "*** FINISHED ***", true);
            Wait (4000);
            break;
          }
      
          dispense_ball ();
          align_catapult (ball_color);
      
          // Fire the catapult
          OnFwd (OUT_A, 100); Wait (500); Off (OUT_A);
          OnFwd (OUT_A, -100); Wait (500); Off (OUT_A);
      
          // Move the catapult back over to the front side, ready for resetting its position
          if (ball_color == "GREEN") {
            RotateMotor (OUT_C, 30, 45+90);
          }else if (ball_color == "BLUE") {
            RotateMotor (OUT_C, 30, 90+90);
          }
      
        }
      
        StopAllTasks ();
      }
      
    • Test guide
      Download your program. Place the Color Sorter in the middle of the test pad and make sure the axle is placed in the centre. Run the program.

Alpha Rex

Can you build and program the Alpha Rex to walk?
  1. Legs

    • Building guide
      Can you build a pair of legs that can walk?
      Instruction 1 of 73
      Instruction 2 of 73
      Instruction 3 of 73
      Instruction 4 of 73
      Instruction 5 of 73
      Instruction 6 of 73
      Instruction 7 of 73
      Instruction 8 of 73
      Instruction 9 of 73
      Instruction 10 of 73
      Instruction 11 of 73
      Instruction 12 of 73
      Instruction 13 of 73
      Instruction 14 of 73
      Instruction 15 of 73
      Instruction 16 of 73
      Instruction 17 of 73
      Instruction 18 of 73
      Instruction 19 of 73
      Instruction 20 of 73
      Instruction 21 of 73
      Instruction 22 of 73
      Instruction 23 of 73
      Instruction 24 of 73
      Instruction 25 of 73
      Instruction 26 of 73
      Instruction 27 of 73
      Instruction 28 of 73
      Instruction 29 of 73
      Instruction 30 of 73
      Instruction 31 of 73
      Instruction 32 of 73
      Instruction 33 of 73
      Instruction 34 of 73
      Instruction 35 of 73
      Instruction 36 of 73
      Instruction 37 of 73
      Instruction 38 of 73
      Instruction 39 of 73
      Instruction 40 of 73
      Instruction 41 of 73
      Instruction 42 of 73
      Instruction 43 of 73
      Instruction 44 of 73
      Instruction 45 of 73
      Instruction 46 of 73
      Instruction 47 of 73
      Instruction 48 of 73
      Instruction 49 of 73
      Instruction 50 of 73
      Instruction 51 of 73
      Instruction 52 of 73
      Instruction 53 of 73
      Instruction 54 of 73
      Instruction 55 of 73
      Instruction 56 of 73
      Instruction 57 of 73
      Instruction 58 of 73
      Instruction 59 of 73
      Instruction 60 of 73
      Instruction 61 of 73
      Instruction 62 of 73
      Instruction 63 of 73
      Instruction 64 of 73
      Instruction 65 of 73
      Instruction 66 of 73
      Instruction 67 of 73
      Instruction 68 of 73
      Instruction 69 of 73
      Instruction 70 of 73
      Instruction 71 of 73
      Instruction 72 of 73
      Instruction 73 of 73
    • Programming guide
      Can you build a pair of legs that test walk in place, and then walk forwards and backwards?
      // alpharex_1.nxc
      // Walk in place, and forwards, and backwards.
      
      // Three directions for walking
      #define INPLACE   0
      #define FORWARDS  1
      #define BACKWARDS 2
      
      
      // Get the legs in a standard position
      // Motor B & touch sensor 1 ---> right leg
      // Motor C & touch sensor 2 ---> left leg
      void reset_legs ()
      {
        if (1 == SENSOR_1)
          {
            OnFwd (OUT_B, 50); Wait (300);
            until (0 == SENSOR_1);
            Off (OUT_B);
          }
        OnFwd (OUT_B, 50);
        until (1 == SENSOR_1);
        Off (OUT_B);
      
        if (1 == SENSOR_2)
          {
            OnFwd (OUT_C, 50); Wait (300);
            until (0 == SENSOR_2);
            Off (OUT_C);
          }
        OnFwd (OUT_C, 50);
        until (1 == SENSOR_2);
        Off (OUT_C);
      }
      
      void walk (int direction, unsigned long duration)
      {
        unsigned long t0;
      
        reset_legs ();
        Wait (2000);
      
        RotateMotor (OUT_B, 70, 45); // Put right leg down
        RotateMotor (OUT_C, -70, 150); // Put left leg up
      
        t0 = CurrentTick ();
      
        switch (direction)
          {
            case INPLACE:
      
              while (CurrentTick () - t0 < duration)
                {
                  OnFwd (OUT_B, 70); OnFwd (OUT_C, -70);
                }
              break;
      
            case FORWARDS:
      
              while (CurrentTick () - t0 < duration)
                {
                  OnFwdSync (OUT_BC, 50, 0);
                }
              break;
      
            case BACKWARDS:
      
              while (CurrentTick () - t0 < duration)
                {
                  OnRevSync (OUT_BC, 50, 0);
                }
              break;
          }
      
        Off (OUT_BC);
      }
      
      task main ()
      {
        // Bring the touch sensors on-line
        SetSensorTouch (S1); SetSensorTouch (S2);
      
        walk (INPLACE,   5000); Wait (2000);
        walk (BACKWARDS, 5000); Wait (2000);
        walk (FORWARDS,  5000); Wait (2000);
      
      }
      
    • Test guide
      Download the program. Place the Alpha Rex on the test pad. Run the program.
  2. Arms

    • Building guide
      Can you build the Alpha Rex with a pair of arms and moveable hands?
      Instruction 1 of 51
      Instruction 2 of 51
      Instruction 3 of 51
      Instruction 4 of 51
      Instruction 5 of 51
      Instruction 6 of 51
      Instruction 7 of 51
      Instruction 8 of 51
      Instruction 9 of 51
      Instruction 10 of 51
      Instruction 11 of 51
      Instruction 12 of 51
      Instruction 13 of 51
      Instruction 14 of 51
      Instruction 15 of 51
      Instruction 16 of 51
      Instruction 17 of 51
      Instruction 18 of 51
      Instruction 19 of 51
      Instruction 20 of 51
      Instruction 21 of 51
      Instruction 22 of 51
      Instruction 23 of 51
      Instruction 24 of 51
      Instruction 25 of 51
      Instruction 26 of 51
      Instruction 27 of 51
      Instruction 28 of 51
      Instruction 29 of 51
      Instruction 30 of 51
      Instruction 31 of 51
      Instruction 32 of 51
      Instruction 33 of 51
      Instruction 34 of 51
      Instruction 35 of 51
      Instruction 36 of 51
      Instruction 37 of 51
      Instruction 38 of 51
      Instruction 39 of 51
      Instruction 40 of 51
      Instruction 41 of 51
      Instruction 42 of 51
      Instruction 43 of 51
      Instruction 44 of 51
      Instruction 45 of 51
      Instruction 46 of 51
      Instruction 47 of 51
      Instruction 48 of 51
      Instruction 49 of 51
      Instruction 50 of 51
      Instruction 51 of 51
    • Programming guide
      Can you program the arms to move back and forth while the hands open and close?
      // alpharex_2.nxc
      // Move the arms back and forth
      
      task main ()
      {
        while (true)
          {
            // turn right - open left hand
            RotateMotor (OUT_A, 100, 2*60);
      
            // back to center
            RotateMotor (OUT_A, -100, 2*60);
      
            Wait (1000);
      
            // turn left - open right hand
            RotateMotor (OUT_A, -100, 2*60);
      
            // back to center
            RotateMotor (OUT_A, 100, 2*60);
      
            Wait (1000);
          }
      }
      
    • Test guide
      Download the program. Place the Alpha Rex on the test pad. Run the program.
  3. Head

    • Building guide
      Can you build the Alpha Rex to see? You will have to build a head on it!
      Instruction 1 of 13
      Instruction 2 of 13
      Instruction 3 of 13
      Instruction 4 of 13
      Instruction 5 of 13
      Instruction 6 of 13
      Instruction 7 of 13
      Instruction 8 of 13
      Instruction 9 of 13
      Instruction 10 of 13
      Instruction 11 of 13
      Instruction 12 of 13
      Instruction 13 of 13
    • Programming guide
      Can you program the Alpha Rex to move forward when it sees an object?
      // alpharex_3.nxc
      // Move forward when an object is visible
      
      // Walk forward when objects come closer than this
      #define THRESHOLD 50
      
      // Three directions for walking
      #define INPLACE   0
      #define FORWARDS  1
      #define BACKWARDS 2
      
      
      // Get the legs in a standard position
      // Motor B & touch sensor 1 ---> right leg
      // Motor C & touch sensor 2 ---> left leg
      void reset_legs ()
      {
        if (1 == SENSOR_1)
          {
            OnFwd (OUT_B, 50); Wait (300);
            until (0 == SENSOR_1);
            Off (OUT_B);
          }
        OnFwd (OUT_B, 50);
        until (1 == SENSOR_1);
        Off (OUT_B);
      
        if (1 == SENSOR_2)
          {
            OnFwd (OUT_C, 50); Wait (300);
            until (0 == SENSOR_2);
            Off (OUT_C);
          }
        OnFwd (OUT_C, 50);
        until (1 == SENSOR_2);
        Off (OUT_C);
      }
      
      void walk (int direction, unsigned long duration)
      {
        unsigned long t0;
      
        RotateMotor (OUT_B, 70, 45); // Put right leg down
        RotateMotor (OUT_C, -70, 150); // Put left leg up
      
        t0 = CurrentTick ();
      
        switch (direction)
          {
            case INPLACE:
      
              OnFwd (OUT_B, 50); OnFwd (OUT_C, -50);
              until (CurrentTick () - t0 > duration);
              break;
      
            case FORWARDS:
      
              OnFwdSync (OUT_BC, 50, 0);
              until (CurrentTick () - t0 > duration);
              break;
      
            case BACKWARDS:
      
              OnRevSync (OUT_BC, 50, 0);
              until (CurrentTick () - t0 > duration);
              break;
          }
      
        Off (OUT_BC);
        reset_legs ();
      }
      
      task main ()
      {
        SetSensorTouch (S1); SetSensorTouch (S2); // Bring the touch sensors on-line
      
        SetSensorLowspeed (S4); // Bring the ultrasonic sensor on-line
      
        reset_legs ();
        Wait (500);
      
        while (true)
          {
            until (SensorUS (S4) < THRESHOLD);
            walk (FORWARDS,  5000); Wait (2000);
          }
      
      }
      
    • Test guide
      Download the program. Place the Alpha Rex on the test pad. Run the program.
  4. Color sensor

    • Building guide
      Can you make the Alpha Rex detect colors by adding the Color Sensor?
      Instruction 1 of 2
      Instruction 2 of 2
    • Programming guide
      Can you program the Alpha Rex to ask for the green ball and then identify it? The Alpha Rex should identify and reject balls in other colors.
      // alpharex_4.nxc
      // Ask for a green ball
      
      // TODO Use a voice to ask for a green ball when nxc adds
      // support for sound files on Linux
      
      // Ask for a ball when an object is closer than this
      #define THRESHOLD 50
      
      // Three directions for walking
      #define INPLACE   0
      #define FORWARDS  1
      #define BACKWARDS 2
      
      void drop_ball ()
      {
        RotateMotor (OUT_A, -100, 2*60); Wait (800);
        // back to center
        RotateMotor (OUT_A, 100, 2*60);
      }
      
      // Get the legs in a standard position
      // Motor B & touch sensor 1 ---> right leg
      // Motor C & touch sensor 2 ---> left leg
      void reset_legs ()
      {
        if (1 == SENSOR_1)
          {
            OnFwd (OUT_B, 50); Wait (300);
            until (0 == SENSOR_1);
            Off (OUT_B);
          }
        OnFwd (OUT_B, 50);
        until (1 == SENSOR_1);
        Off (OUT_B);
      
        if (1 == SENSOR_2)
          {
            OnFwd (OUT_C, 50); Wait (300);
            until (0 == SENSOR_2);
            Off (OUT_C);
          }
        OnFwd (OUT_C, 50);
        until (1 == SENSOR_2);
        Off (OUT_C);
      }
      
      void walk (int direction, unsigned long duration)
      {
        unsigned long t0;
      
        RotateMotor (OUT_B, 70, 45); // Put right leg down
        RotateMotor (OUT_C, -70, 150); // Put left leg up
      
        t0 = CurrentTick ();
      
        switch (direction)
          {
            case INPLACE:
      
              OnFwd (OUT_B, 50); OnFwd (OUT_C, -50);
              until (CurrentTick () - t0 > duration);
              break;
      
            case FORWARDS:
      
              OnFwdSync (OUT_BC, 50, 0);
              until (CurrentTick () - t0 > duration);
              break;
      
            case BACKWARDS:
      
              OnRevSync (OUT_BC, 50, 0);
              until (CurrentTick () - t0 > duration);
              break;
          }
      
        Off (OUT_BC);
        reset_legs ();
      }
      
      task main ()
      {
        SetSensorTouch (S1); SetSensorTouch (S2); // Bring the touch sensors on-line
        SetSensorLowspeed (S4); // Bring the ultrasonic sensor on-line
        SetSensorColorFull (S3); // Bring the color sensor on-line
      
        reset_legs ();
        Wait (500);
      
        while (true)
          {
            until (SensorUS (S4) < THRESHOLD);
      
            // Display a message
            TextOut (0, LCD_LINE1, "    GIVE ME A    ", true);
            TextOut (0, LCD_LINE3, "  *** GREEN ***  ", false);
            TextOut (0, LCD_LINE5, "       BALL      ", false);
      
            // Wait until a ball is placed in the right hand
            until (INPUT_BLACKCOLOR != SENSOR_3);
      
            Wait (2000);
            ResetScreen ();
      
            if (INPUT_GREENCOLOR == SENSOR_3)
              {
                // Do a dance
                walk (INPLACE, 5000);
                // Release the ball
                drop_ball ();
              }
            else
              {
                // Move forward
                walk (FORWARDS, 5000);
                // Drop the ball
                drop_ball ();
                // Move back
                walk (BACKWARDS, 5000);
              }
      
            Wait (1000);
          }
      }
      
    • Test guide
      Download the program. Place the Alpha Rex on the test pad. Before running the program, the Alpha Rex's hands should be closed and pointed forward (do this by turning the gear on the right side of its back). Run the program.

Комментариев нет:

Отправить комментарий