12/30/12 NXT 2.0 Instructions
1/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
Categories BASH C Celestial Lego Various
Building guide Programming guide Test guideBuilding guide Programming guide Test guideBuilding guide Programming guide Test guideBuilding guide Programming guide Test guide
Building guide Programming guide Test guideBuilding guide Programming guide Test guideBuilding guide Programming guide Test guideBuilding guide Programming guide Test guide
Building guide Programming guide Test guideBuilding guide Programming guide Test guideBuilding guide Programming guide Test guideBuilding guide Programming guide Test guide
Building guide Programming guide Test guideBuilding guide Programming guide Test guideBuilding guide Programming guide Test guideBuilding guide Programming guide Test guide
Contact Home Search
LEGO Mindstorms NXT 2.0 instructions
Instructions for building the Shooterbot, Robogator, Color Sorter, and Alpha Rex.
Table of contents
IntroductionProgramming the NXT with LinuxCompiling an NXC program
Shooterbot1. Driving base2. Color detection3. Shooter4. Locate objects
Robogator1. Jaws2. Eyes3. Legs4. Tail
Color Sorter1. Dispenser2. Color detector3. Sorting tray4. Color catapult
Alpha Rex1. Legs2. Arms3. Head4. Color sensor
Introduction
The instructions for building the four main LEGO Mindstorms NXT 2.0 models are distributed only on software that doesnot 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 languagesupported by NBC. NBC allows you to write NXT programs and download them to the NXT. This configuration guide forNBC 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
12/30/12 NXT 2.0 Instructions
2/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
Can you build a Shooterbot to move forward and then move back again?
12/30/12 NXT 2.0 Instructions
3/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
4/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
5/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
6/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
7/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
8/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
9/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
10/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
11/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
12/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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);
}
12/30/12 NXT 2.0 Instructions
13/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
}
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?
12/30/12 NXT 2.0 Instructions
14/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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
12/30/12 NXT 2.0 Instructions
15/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
// 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.
12/30/12 NXT 2.0 Instructions
16/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
17/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
18/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
19/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
21/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
22/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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;
12/30/12 NXT 2.0 Instructions
23/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
// 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.
12/30/12 NXT 2.0 Instructions
24/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 ()
12/30/12 NXT 2.0 Instructions
25/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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?
12/30/12 NXT 2.0 Instructions
26/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
27/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
28/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
29/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
30/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
32/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
33/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
34/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
35/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 Along 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;
12/30/12 NXT 2.0 Instructions
36/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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?
12/30/12 NXT 2.0 Instructions
37/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
38/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 Along dps_a = 0;
task motor_speed_monitor ()
{
12/30/12 NXT 2.0 Instructions
39/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
{ 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 shouldstart biting. Move your hand away and the Robogator should stop biting.
3. Legs
Building guide
Can you build a robot that can walk?
12/30/12 NXT 2.0 Instructions
41/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
42/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
43/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
44/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
45/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
46/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
47/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
48/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
49/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
50/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
51/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
52/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
53/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
54/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
55/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
56/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
57/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
58/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
59/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
60/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
61/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
62/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
64/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
65/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
67/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
68/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
69/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
70/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
71/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
72/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 Along 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);
12/30/12 NXT 2.0 Instructions
73/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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?
12/30/12 NXT 2.0 Instructions
74/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
75/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
76/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
77/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
78/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
79/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
80/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
81/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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
12/30/12 NXT 2.0 Instructions
82/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
// The approximate 'degrees per second' rotation of motor Along 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);
12/30/12 NXT 2.0 Instructions
83/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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?
12/30/12 NXT 2.0 Instructions
84/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
85/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
86/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
87/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
90/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
91/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
92/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
93/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
95/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
96/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
97/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
98/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
99/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
100/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
101/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
102/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
103/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
104/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
105/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
106/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
107/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
108/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
109/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
110/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
111/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
112/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
113/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
114/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
115/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
116/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
117/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
118/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
119/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
120/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
121/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
122/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
123/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
124/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
125/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
126/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
127/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
129/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
130/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
131/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
132/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
133/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
134/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 positionvoid reset_dispenser (){ OnRev (OUT_B, 80); until (1 == SENSOR_1); Off (OUT_B); Wait (1000);}
// Dispense one ballvoid 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
12/30/12 NXT 2.0 Instructions
135/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
Download your program. Place the Color Sorter in the middle of the test pad. Put a couple of balls in thedispenser and run the program.
2. Color detector
Building guide
Can you build a color detector that can recognise the different ball colors?
12/30/12 NXT 2.0 Instructions
136/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
137/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 positionvoid reset_dispenser (){ OnRev (OUT_B, 80); until (1 == SENSOR_1); Off (OUT_B); Wait (1000);
}
}
// Get a ball into the dispenser slotvoid 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?
12/30/12 NXT 2.0 Instructions
140/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
141/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
142/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
143/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
144/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
145/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
146/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
147/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 truebool reset_dispenser_flag = false;bool reset_basket_flag = false;
// Get a ball into the dispenser slotvoid load_ball (){
Wait (2000);
12/30/12 NXT 2.0 Instructions
148/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 taskstring 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 positiontask 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)
12/30/12 NXT 2.0 Instructions
149/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
{ 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
12/30/12 NXT 2.0 Instructions
150/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
Can you build a color catapult that throws balls in different directions?
12/30/12 NXT 2.0 Instructions
152/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
154/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
155/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
156/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
157/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
158/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
159/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
160/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 truebool reset_dispenser_flag = false;bool reset_catapult_flag = false;
// Get a ball into the dispenser slotvoid load_ball (){
Wait (2000);
12/30/12 NXT 2.0 Instructions
161/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 taskstring 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 positiontask 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 ()
12/30/12 NXT 2.0 Instructions
162/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
{ 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);
12/30/12 NXT 2.0 Instructions
163/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
}
}
StopAllTasks ();}
Test guide
Download your program. Place the Color Sorter in the middle of the test pad and make sure the axle isplaced 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?
12/30/12 NXT 2.0 Instructions
164/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
165/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
166/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
168/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
169/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
171/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
172/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
173/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
174/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
175/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
176/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
177/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
178/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
179/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
180/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
181/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
182/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
183/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
184/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
185/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
188/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
189/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
190/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
191/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
192/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
193/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
194/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
196/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
197/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
198/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
199/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 legvoid reset_legs ()
{
12/30/12 NXT 2.0 Instructions
200/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
{ 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);
}
12/30/12 NXT 2.0 Instructions
201/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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?
12/30/12 NXT 2.0 Instructions
202/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
203/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
204/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
205/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
206/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
207/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
208/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
209/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
211/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
212/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
214/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
215/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
216/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
217/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
218/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
219/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
220/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
221/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
222/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
223/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
224/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
225/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
226/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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!
12/30/12 NXT 2.0 Instructions
227/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
228/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
229/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
230/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
231/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
232/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
12/30/12 NXT 2.0 Instructions
233/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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 legvoid 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_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?
12/30/12 NXT 2.0 Instructions
235/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
Programming guide
Can you program the Alpha Rex to ask for the green ball and then identify it? The Alpha Rex should identify andreject 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
12/30/12 NXT 2.0 Instructions
236/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
#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 legvoid 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
12/30/12 NXT 2.0 Instructions
237/237arbitrarycreations.co.uk/lego/nxt_2_instructions/#robogator_jaws_program
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'shands should be closed and pointed forward (do this by turning the gear on the right side of its back). Run theprogram.
Top Related