OBJECTIVE

tankbot

Put concepts learned in Lab 1 into practice by building the TankBot and programming several tasks. You will learn how to program the RCX using a programming language, Not Quite C (NQC).

TASK

Part 1 - TankBot

  1. Create the robot as described in the attached TankBot building instructions [PDF file, 174 KB].

Part 2 - Programming Challenge

Complete the following programming activities using the Lego Mindstorm visual programming environment.

  1. Make TankBot go forward for six seconds and then stop.
  2. Make robot go backward for six seconds and then stop.
  3. Make robot turn left for six seconds.
  4. Make robot turn right for six seconds.
  5. Make robot spin for six seconds.
  6. Make robot go forward for four seconds, stop for two seconds and then go backward for four seconds.
  7. Make robot go forward for four seconds, stop for two seconds and go backward for four seconds.
  8. Have the robot play a sound for eight seconds then stop.

Part 3 - NQC using Bricx

TECHNICAL NOTE:
NQC is based on the programming language C and is an example of a text-based programming language. Other examples of programming languages like this include C++, Java, and Assembly Language

Not Quite C is a simple programming language based on the programming language C. To program this language, we will use the program Bricx.

Make sure that the infra-red port is correctly connected to the USB port and that the TankBot is turned on.

Starting Bricx Command Center

We can write programs in NQC using Bricx. Start Bricx by clicking on the Bricx Command Center icon. The program will find and establish communication with the robot. If no connection can be established, certain options will be disabled. You must establish a connection with the robot to download and run your program on the RCX.

Getting familiar with Bricx

Below are several icons you will find helpful to know when using this program.

bricx icons

Click the new file icon to begin. In the window that opens type the following code.

task main()
{
   On(OUT_A + OUT_C);
   Wait(600);
   Off(OUT_A + OUT_C);
}

Now click the compile icon. (This checks the code for errors.) If there are errors, check your code to make sure it is typed EXACTLY as shown above, fix any errors, and then recompile the code.

A Look at the Code:
On(OUT_A + OUT_C) turns the motors connected to A and C on.

Wait(600) makes the motors continue to run for 600 milliseconds (6 seconds.

Off(OUT_A + OUT_C) turns the motors connected to A and C off.

We can now download the code to the robot. Make sure the robot is turned on and in range of the infrared port. Click the download icon. Wait until the robot signals it has completed the download, and then run the program. If you notice, this code does the same thing as programming challenge #1.

Add the Fwd line to your code. This command instructs the motors to turn forward. Compile and download to your robot.

task main()
{
   On(OUT_A + OUT_C);
   Fwd(OUT_A + OUT_C);
   Wait(600);
   Off(OUT_A + OUT_C);
}

Part 4 - Programming Challenge

Program the following tasks using NQC.

  1. Make robot turn left by running motor A forward for six seconds and turn motor C off.
  2. Make robot turn right by running motor C forward for six seconds and turning motor A off.
  3. Make robot spin by running motors in opposite directions for six seconds.

Note: You can program the remaining tasks using either Bricx or the visual environment provided by Lego Mindstorm.

  1. Have robot play a sound for eight seconds then stop.
  2. Make robot go forward for four seconds, stop for two seconds and then go in reverse for four seconds.
  3. Make robot go forward for four seconds, stop for two seconds and go in reverse for four seconds at power level three.
  4. Make motor A go forward at power level five and motor C go forward at power level three for eight seconds.
  5. Make robot go forward for four seconds, stop for two seconds and go in reverse for four seconds. Have the robot repeat this five times.