Ensayo decreto 3075

Solo disponible en BuenasTareas
  • Páginas : 8 (1811 palabras )
  • Descarga(s) : 0
  • Publicado : 14 de octubre de 2010
Leer documento completo
Vista previa del texto
ROBOTC

Fundamentals

Programming in ROBOTC

ROBOTC Rules

In this lesson, you will learn the basic rules for writing ROBOTC programs. ROBOTC is a text-based programming language based on the standard C programming language. Commands to the robot are written as text on the screen, processed by the ROBOTC compiler into a machine language file, and then loaded onto the robot, where they canbe run. Text written as part of a program is called “code”.
1 2 3 4 5 6 7

task main() { motor[motorC] = 100; wait1Msec(3000); }
Program Code Text written as part of a program is called “code”.

You type code just like normal text, but you must keep in mind that capitalization is important to the computer. Replacing a lowercase letter with a capital letter or a capital letter withlowercase, will cause the robot to become confused.
1 2 3 4 5 6 7

Task main() { motor[motorC] = 100; wait1Msec(3000); }

Capitalization Capitalization (paying attention to UPPERCASE vs. lowercase) is important in ROBOTC. Capitalizing the ‘T’ in task causes ROBOTC to no longer recognize this command.

As you type, ROBOTC will try to help you out by coloring the words it recognizes. If a word appearsin a different color, it means ROBOTC knows it as an important word in the programming language.
1 2 3 4 5 6 7

task main() { motor[motorC] = 100; wait1Msec(3000); }

Code coloring ROBOTC automatically colors key words that it recognizes. Compare this correctly-capitalized “task” command with the incorrectly-capitalized version in the previous example. The correct one is recognized as acommand and turns blue.

© Carnegie Mellon Robotics Academy / For use with LEGO® MINDSTORMS® Education NXT software and base set 9797

ROBOTC Programming • 

ROBOTC

Fundamentals

Programming in ROBOTC

ROBOTC Rules (cont.)

And now, we will look at some of the important parts of the program code itself. The most basic kind of statement in ROBOTC simply gives a command to the robot.The motor[motorC]; statement in the sample program you downloaded is a simple command. It instructs the motor plugged into the Motor C port to turn on at 100% power.
1 2 3 4 5 6 7

task main() { motor[motorC] = 0; wait1Msec(3000); }

Simple statement A straightforward command to the robot. This statement tells the robot to turn on the motor attached to motor port C at 100% power. Simplestatement (2) This is also a simple statement. It tells the robot to wait for 3000 milliseconds (3 seconds).

Statements are run in order, as quickly as the robot is able to reach them. Running this program on the robot turns the motor on, then waits for 3000 milliseconds (3 seconds) with the motor still running, and then ends.
1 2 3 4 5 6 7

task main() {
1st 2nd

motor[motorC] = 0;wait1Msec(3000);

Sequence Statements run in English reading order (left-to-right, top-to-bottom). As soon as one command is complete, the next runs. These two statements cause the motors to turn on (1st command), and then the robot immediately begins a three second wait (2nd command) while the motors remain on. End When the program runs out of statements and reaches the } symbol in task main, all motorsstop, and the program ends.

} End

© Carnegie Mellon Robotics Academy / For use with LEGO® MINDSTORMS® Education NXT software and base set 9797

ROBOTC Programming • 

ROBOTC

Fundamentals

Programming in ROBOTC

ROBOTC Rules (cont.)

How did ROBOTC know that these were two separate commands? Was it because they appeared on two different lines? No. Spaces and line breaks in ROBOTCare only used to separate words from each other in multi-word commands. Spaces, tabs, and lines don’t affect the way a program is interpreted by the machine.
1 2 3 4 5 6 7

task main() { motor[motorC] = 0; wait1Msec(3000); }

Whitespace Spaces, tabs, and line breaks are generally unimportant to ROBOTC and the robot. They are sometimes needed to separate words in multi-word commands, but...
tracking img