VEX Natural Language

From ROBOTC API Guide
Jump to: navigation, search
PIC → Natural Language


The ROBOTC Natural Language Library aims at making learning and using text-based programming languages easier for beginners. The Natural Language Library is filled with commands that are both easy to use and easy to remember. Natural Language commands encompass entire robot behaviors into a single command.

Natural Language can be enabled in ROBOTC by going to the Robot menu, then Platform Type, and then by selecting one of the Natural Language options.


Contents

Color Key
Function:
Variable:


Video

This video explains the ROBOTC Natural Language:



Setup Functions

robotType

void robotType(tRobotType type = none)
Robot type vex.png (void) Choose which robot you want to write a program for.

Acceptable robots: squarebot or none (no setup).

(If you don't use this function at all, it will default to none!)

Parameter Explanation Acceptable Input
type The robot model to use.
(default: none)
none
squarebot
Default Usage and Sample
robotType();  // default (none) is used
Usage and Sample with Parameters
robotType(squarebot);  // squarebot will be used


Wait Functions

wait

void wait(long waitTime = 1)
Wait seconds.png (void) Wait an amount of time measured in whole seconds.

Whole number values only!
Parameter Explanation Acceptable Input
waitTime Amount of time to wait, in whole seconds.
(default: 1)
Any integer amount from
0 to +2,147,483,647.
Default Usage and Sample
forward();
wait();     // wait for 1 second (default)
stop();
Usage and Sample with Parameters
forward(63);  // go forward at speed 63
wait(7);      // wait for 7 seconds
stop();       // stop


waitInMilliseconds

void waitInMilliseconds(long waitTime = 1000)
Wait milliseconds.png (void) Wait an amount of time measured in milliseconds.
Parameter Explanation Acceptable Input
waitTime Amount of time to wait, in seconds.
(default: 1000)
Any integer amount from
0 to +2,147,483,647.
Default Usage and Sample
forward();
waitInMilliseconds();  // wait for 1000 milliseconds (default)
stop();
Usage and Sample with Parameters
forward(63);               // go forward at speed 63
waitInMilliseconds(2700);  // wait for 2700 milliseconds (2.7 seconds)
stop();                    // stop


Movement Functions

startMotor

void startMotor(tMotor motorPort = port6, byte speed = 95)
Set motor vex.png (void) Set a motor to a speed.

Range: -127 to 127

Acceptable Motors: ports 1 through 8, (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
motorPort The motor port to use.
(default: port6)
port1
through
port8
Or their names setup in Motors and Sensors Setup.
speed The speed to set the motor to.
(default: 95)
-127 to +127
Default Usage and Sample
startMotor();  // starts port6 at speed 95 (default)
wait();
stopMotor();
Usage and Sample with Parameters
startMotor(port8, -32);   // start port8 at speed -32
waitInMilliseconds(500);  // wait 0.5 seconds
stopMotor(port8);         // stop port8


stopMotor

void stopMotor(tMotor motorPort = port6)
Arm stop vex.png (void) Stops a motor.

Acceptable Motors: ports 1 through 8, (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
motorPort The motor port to use.
(default: port6)
port1
through
port8
Or their names setup in Motors and Sensors Setup.
Default Usage and Sample
startMotor();
wait();
stopMotor();   // stop port6 (default)
Usage and Sample with Parameters
startMotor(port8, -32);   // start port8 at speed -32
waitInMilliseconds(500);  // wait 0.5 seconds
stopMotor(port8);         // stop port8


setServo

void setServo(tMotor servoPort = port6, int position = 0)
Set servo vex.png (void) Set a motor to a speed.

Range: -127 to 127

Acceptable Motors: ports 1 through 8, (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
servoPort The motor port to use.
(default: port6)
port1
through
port8
Or their names setup in Motors and Sensors Setup.
position The position to set the servo to.
(default: 0)
-127 to +127
Default Usage and Sample
setServo();  // sets servo on port6 to position 0 (default)
Usage and Sample with Parameters
setServo(port8, 37);  // sets servo on port8 to position 37


Robot Movement Functions

forward

void forward(byte speed = 95)
Forward vex.png (void) Both wheels rotate forward at the same speed and the robot moves straight forward.

Range: -127 to 127 (Forward will always move your robot forward.)

Parameter Explanation Acceptable Input
speed The speed to move forward at.
(default: 95)
-127 to +127
Default Usage and Sample
forward();  // move forward at speed 95 (default)
wait();
stop();
Usage and Sample with Parameters
forward(63);  // move forward at speed 63
wait(2);      // wait 2 seconds
stop();       // stop


backward

void backward(byte speed = -95)
Vex backward.png (void) Both wheels rotate backward at the same speed and the robot moves straight backward.

Range: -127 to 127 (Backward will always move your robot backward.)

Parameter Explanation Acceptable Input
speed The speed to move backward at.
(default: -95)
-127 to +127
Default Usage and Sample
backward();  // move backward at speed -95 (default)
wait();
stop();
Usage and Sample with Parameters
backward(-63);  // move backward at speed -63
wait(2);        // wait 2 seconds
stop();         // stop


pointTurn

void pointTurn(tDirections direction = right, byte speed = 95)
Vex point turn.png (void) Both wheels rotate at the same speed but in opposite directions, causing the robot to turn around it's center. This makes a sharp turn in place.

Range: -127 to 127

Parameter Explanation Acceptable Input
direction The direction to turn.
(default: right)
right
left
speed The speed to move turn at.
(default: 95)
-127 to +127
Default Usage and Sample
pointTurn();  // point turn right at speed 95 (default)
wait();
stop();
Usage and Sample with Parameters
pointTurn(left, 63);      // point turn LEFT at speed 63
waitInMilliseconds(400);  // wait 0.4 seconds
stop();                   // stop


swingTurn

void swingTurn(tDirections direction = right, byte speed = 95)
Swing turn vex.png (void) One wheel rotates while the other does not move, causing the robot to turn around the stopped wheel. This makes a wide turn.

Range: -127 to 127

Parameter Explanation Acceptable Input
direction The direction to turn.
(default: right)
right
left
speed The speed to move turn at.
(default: 95)
-127 to +127
Default Usage and Sample
swingTurn();  // swing turn right at speed 95 (default)
wait();
stop();
Usage and Sample with Parameters
swingTurn(left, 63);      // swing turn LEFT at speed 63
waitInMilliseconds(750);  // wait 0.75 seconds
stop();                   // stop


stop

void stop()
Stop vex.png (void) Both wheels do not move, causing the robot to stop.
Default Usage and Sample
forward();
wait();
stop();     // stop the robot
Usage and Sample with Parameters
forward(63);  // move forward at speed 63
wait(2);      // wait 2 seconds
stop();       // stop


moveStraightForTime

void moveStraightForTime(long seconds, tSensors rightEncoderPort, tSensors leftEncoderPort)
Move straight time vex.png (void) The robot will use encoders to maintain a straight course for a length of time in seconds.
  • NOTE: This function only supports moving forward and only at one speed setting. Future implementations may include moving backwards and variable speeds.

Acceptable Sensors: A/D ports 1 through 16 + interrupts (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
seconds The amount of time in seconds to drive straight forward.
(default: NONE)
Any integer amount from
0 to +2,147,483,647.
rightEncoderPort The right-side motor encoder.
(default: NONE)
in1 to in16
Or their names setup in Motors and Sensors Setup.
leftEncoderPort The left-side motor encoder.
(default: NONE)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
moveStraightForTime(7, in5, in3);  /* move straight forward for 7 seconds, 
                                      using in5 as the right-side encoder
                                      and in3 as the left-side encoder */
stop();                            // stop


moveStraightForRotations

void moveStraightForRotations(long rotations, tSensors rightEncoderPort, tSensors leftEncoderPort)
Move straight dist vex.png (void) The robot will use encoders to maintain a straight course for a distance in rotations (360 encoder counts = 1 rotation).
  • NOTE: This function only supports moving forward and only at one speed setting. Future implementations may include moving backwards and variable speeds.

Acceptable Sensors: A/D ports 1 through 16 + interrupts (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
rotations The amount of axle rotations to drive straight forward.
(default: NONE)
Any integer amount from
0 to +2,147,483,647.
rightEncoderPort The right-side motor encoder.
(default: NONE)
in1 to in16
Or their names setup in Motors and Sensors Setup.
leftEncoderPort The left-side motor encoder.
(default: NONE)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
moveStraightForRotations(4, in5, in3);  /* move straight forward for 4 rotations, 
                                           using in5 as the right-side encoder
                                           and in3 as the left-side encoder */
stop();                                 // stop


Until Functions

untilTouch

void untilTouch(tSensors sensorPort)
Touch in vex.png (void) The robot does what it was doing until the touch sensor is pressed in.

Acceptable Sensors: A/D ports 1 through 16 (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
sensorPort The sensor port to use for the touch sensor.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);       // go forward at speed 63
untilTouch(in10);  // wait until the touch sensor in port in10 is pressed
stop();            // stop


untilRelease

void untilRelease(tSensors sensorPort)
Touch out vex.png (void) The robot does what it was doing until the touch sensor is released.

Acceptable Sensors: A/D ports 1 through 16 (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
sensorPort The sensor port to use for the touch sensor.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);         // go forward at speed 63
untilRelease(in10);  // wait until the touch sensor in port in10 is released
stop();              // stop


untilBump

void untilBump(tSensors sensorPort, int delayTimeMS = 10)
Touch bump vex.png (void) The robot does what it was doing until the touch sensor is pressed in and then released out. A delay time in milliseconds can be specified.

Acceptable Sensors: A/D ports 1 through 16 (and your names for them given in Motors and Sensors Setup.)

Acceptable Range for Delay Time: 0 to 32,767.

Parameter Explanation Acceptable Input
sensorPort The sensor port to use for the light sensor.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
delayTimeMS The amount of milliseconds that MUST PASS between
press and release of the sensor for it to count.
(default: 10)
Any whole integer amount from
0 to 32,767.
Usage and Sample with Parameters
forward(63);           // go forward at speed 63
untilBump(in10, 100);  /* wait until the touch sensor in port in10 is pressed and 
                          then released with a delay time of 100 milliseconds */
stop();                // stop


untilSonarGreaterThan

void untilSonarGreaterThan(short distance, tSensors sensorPort)
Sonar greater vex.png (void) The robot does what it was doing until the sonar sensor reads a value greater than a set distance in centimeters.

Range: 0 to 255 (A value of -1 means it cannot detect anything.)

Acceptable Sensors: A/D ports 1 through 16 + interrupt (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
distance The distance in centimeters that
an object must be farther than to count
(default: none)
Any whole integer amount from 0 to 255.
sensorPort The sensor port to use for the sonar sensor.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);                     // go forward at speed 63
untilSonarGreaterThan(45, in2);  /* wait until the sonar sensor in port in2
                                    detects an object farther than 45cm away */
stop();                          // stop


untilSonarLessThan

void untilSonarLessThan(short distance, tSensors sensorPort)
Sonar less vex.png (void) The robot does what it was doing until the sonar sensor reads a value less than a set distance in centimeters.

Range: 0 to 255 (A value of -1 means it cannot detect anything.)

Acceptable Sensors: A/D ports 1 through 16 + interrupt (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
distance The distance in centimeters that
an object must be farther than to count
(default: none)
Any whole integer amount from 0 to 255.
sensorPort The sensor port to use for the sonar sensor.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);                  // go forward at speed 63
untilSonarLessThan(45, in2);  /* wait until the sonar sensor in port in2
                                 detects an object closer than 45cm away */
stop();                       // stop


untilPotentiometerGreaterThan

void untilPotentiometerGreaterThan(int position, tSensors sensorPort)
Pot greater vex.png (void) The robot does what it was doing until the potentiometer sensor reads a value greater than a set position.

Range: 0 to 1023 (However due to mechanical stops, you may be limited to the range of 5 to 1018.)

Acceptable Sensors: A/D ports 1 through 16 (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
position The function passes if the rotation
is greater than this value
(default: none)
Any whole integer amount from 0 to 1023.
sensorPort The sensor port to use for the potentiometer sensor.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);                             // go forward at speed 63
untilPotentiometerGreaterThan(40, in4);  /* wait until the potentiometer in port in4
                                            reads a value greater than 40 (default) */
stop();                                  // stop


untilPotentiometerLessThan

void untilPotentiometerLessThan(int position, tSensors sensorPort)
Pot less vex.png (void) The robot does what it was doing until the potentiometer sensor reads a value less than a set position.

Range: 0 to 1023 (However due to mechanical stops, you may be limited to the range of 5 to 1018.)

Acceptable Sensors: A/D ports 1 through 16 (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
position The function passes if the rotation
is less than this value
(default: none)
Any whole integer amount from 0 to 1023.
sensorPort The sensor port to use for the potentiometer sensor.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);                          // go forward at speed 63
untilPotentiometerLessThan(40, in4);  /* wait until the potentiometer in port in4
                                         reads a value less than 40 (default) */
stop();                               // stop


untilButtonPress

void untilButtonPress(short button = centerBtnVEX)
Press right vex.png (void) The robot does what it was doing until a button on the LCD is pressed.

Acceptable Buttons: centerBtnVEX, rightBtnVEX, leftBtnVEX

Parameter Explanation Acceptable Input
button The button to press.
(default: centerBtnVEX)
centerBtnVEX
rightBtnVEX
leftBtnVEX
Default Usage and Sample
forward();
untilButtonPress();  /* wait until the center button
                        is pressed on the VEX LCD (default) */
stop();
Usage and Sample with Parameters
forward(63);                    // go forward at speed 63
untilButtonPress(rightBtnVEX);  /* wait until the right button
                                   is pressed on the VEX LCD */
stop();                         // stop


untilLight

void untilLight(int threshold, tSensors sensorPort)
Until light vex.png (void) The robot does what it was doing until the light sensor reads a value lighter than the threshold.

Range: (light) 0 to 1023 (dark)

Acceptable Sensors: A/D ports 1 through 16 (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
threshold The threshold value that
an object must be lighter than to count
(default: none)
Any whole integer amount from 0 to 1023.
sensorPort The sensor port to use for the sonar sensor.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);            // go forward at speed 63
untilLight(1005, in4);  /* wait until the light sensor in port in4
                           detects an object lighter than 1005 */
stop();                 // stop


untilDark

void untilDark(int threshold, tSensors sensorPort)
Until dark vex.png (void) The robot does what it was doing until the light sensor reads a value darker than the threshold.

Range: (light) 0 to 1023 (dark)

Acceptable Sensors: A/D ports 1 through 16 (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
threshold The threshold value that
an object must be darker than to count
(default: none)
Any whole integer amount from 0 to 1023.
sensorPort The sensor port to use for the sonar sensor.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);            // go forward at speed 63
untilDark(1005, in4);   /* wait until the light sensor in port in4
                           detects an object darker than 1005 */
stop();                 // stop


untilRotations

void untilRotations(float rotations, tSensors sensorPort)
Rotations vex pic.png (void) The robot does what it was doing until the quadrature encoder rotations match the desired value. Whole number values only!

Range: -32,768 to +32,767

Acceptable Sensors: A/D ports 1 through 16 + interrupt (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
rotations The amount of axle rotations to reach.
(default: none)
Any whole integer amount from -32,768 to +32,767.
sensorPort The quadrature encoder to use.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);             // move forward at speed 63
untilRotations(3, in3);  /* wait until the quadrature encoder
                            in port in3 counts 3 rotations */
stop();                  // stop


untilEncoderCounts

void untilEncoderCounts(long distance, tSensors sensorPort)
Encoder counts vex pic.png (void) The robot does what it was doing until the motor encoder counts match the desired value.

Range: -32,768 to +32,767

Acceptable Sensors: A/D ports 1 through 16 + interrupt (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
distance The amount of encoder counts to reach.
(default: none)
Any whole integer amount from
-32,768 to +32,767
sensorPort The quadrature encoder to use.
(default: none)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Usage and Sample with Parameters
forward(63);                    // move forward at speed 63
untilEncoderCounts(990, in3);   /* wait until the quadrature encoder in
                                   port in3 counts 990 encoder counts */
stop();                         // stop


Special Functions

turnLEDOn

void turnLEDOn(tSensors sensorPort = in12)
Led on.png (void) Turn an LED in a specified digital port ON.

Acceptable Sensors: A/D ports 1 through 16 (and your names for them given in Motors and Sensors Setup.)

Sensor port must be set to "Digital Output".

Parameter Explanation Acceptable Input
sensorPort The VEX LED to use.
(default: in12)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Default Usage and Sample
turnLEDOn();  // turn on LED in port in12 (default)
Usage and Sample with Parameters
turnLEDOn(in7);  // turn on LED in port in7


turnLEDOff

void turnLEDOff(tSensors sensorPort = in12)
Led off.png (void) Turn an LED in a specified digital port OFF.

Acceptable Sensors: A/D ports 1 through 16 (and your names for them given in Motors and Sensors Setup.)

Sensor port must be set to "Digital Output".

Parameter Explanation Acceptable Input
sensorPort The VEX LED to use.
(default: in12)
in1 to in16
Or their names setup in Motors and Sensors Setup.
Default Usage and Sample
turnLEDOff();  // turn off LED in port in12 (default)
Usage and Sample with Parameters
turnLEDOff(in7);  // turn off LED in port in7


turnFlashlightOn

void turnFlashlightOn(tMotor flashlightPort = port4, short brightness = 63)
Flashlight on.png (void) Turns a VEX Flashlight in a specfied motor port ON at a specified brightness.

Brightness Range: (off) 0 to 127 (bright)

Acceptable Ports: motor ports 1 through 8 (and your names for them given in Motors and Sensors Setup.)

  • NOTE* Brightness control only available in motor ports 1 through 8 when connected to a VEX Motor Controller 29.
Parameter Explanation Acceptable Input
sensorPort The VEX Flashlight to use.
(default: port4)
port1 to port8
Or their names setup in Motors and Sensors Setup.
brightness The level of brightness to
set the VEX Flashlight to.
(default: 63)
Any whole integer amount from 0 to 127.
Default Usage and Sample
turnFlashlightOn();  // turn VEX Flashlight in port4 ON to half brightness [63] (default)
Usage and Sample with Parameters
turnFlashlightOn(port8, 127);  // turn VEX Flashlight in port8 ON to full brightness [127]


turnFlashlightOff

void turnFlashlightOff(tMotor flashlightPort = port4)
Flashlight off.png (void) Turns a VEX Flashlight in a specfied motor port OFF.

Acceptable Ports: motor ports 1 through 8 (and your names for them given in Motors and Sensors Setup.)

Parameter Explanation Acceptable Input
sensorPort The VEX Flashlight to use.
(default: port4)
port1 to port8
Or their names setup in Motors and Sensors Setup.
Default Usage and Sample
turnFlashlightOff();  // turn VEX Flashlight in port4 OFF (default)
Usage and Sample with Parameters
turnFlashlightOff(port8);  // turn VEX Flashlight in port8 OFF


Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox