RoboCatz.com

RobotC

The Natural Language for the Fall 2015 season is as follows:

Natural Language is a sort of halfway language between English and computer code. It lets you address the important details of your program without having to worry about the less relevant parts getting in your way. Our goal when developing pseudocode will be to identify and organize the simple behaviors a robot needs to complete its mission.

The Natural Language used here is an extension of the RobotC language. All Natural Language statements below require a set of parentheses followed by a semi-colon. For some statements, a parameter (such as distance, power level, degrees, or side) is required which gives further instructions to the robot.

The Natural Language statements below are interpreted (compiled) by RobotC through the use of a library of functions stored in a single "include" file. This is why each of the examples at the bottom of this page include a reference to "#include Library2015.c". If you are curious about what the Library2015.c "include" file looks like, click here. If you wish to download the Library2015.c file, right click on the following link and choose to save it to your computer: download here.


If you end up with an error message when you press the F5 or F7 key, read the message to try to understand what it is telling you. For an explanation of common error messages, click here.

The RobotC Functions for the Fall 2015 season

Function

Parameters

Description

(with example parameter)

setPowerLevel(30);

Level of power

Sets the level of power for the global variable called "powerLevel"

+1 to +100

used by all navigation motor blocks

Moving Straight Functions

driveForward();

None

Drives forward. Optional parameters include distance. If no distance is specified, use one of the "stop" or "until" functions to stop the robot.

driveForward(12);

Distance

driveBackward();

None

Drives backward. Optional parameters include distance. If no distance is specified, use one of the "stop" or "until" functions to stop the robot.

driveBackward(12);

Distance

Turning Functions

turnRight(180);

Degrees to turn

Turns a specified number of degrees

turnLeft(90);

swingTurnRight(180);

Degrees to turn

Turns a specified number of degrees

swingTurnLeft(90);

Stopping Functions

stopMoving();

Stops moving

stopIfSonarLessThan(6);

Distance in inches

Stops if robot gets within x inches of an object

stopAfterDistance(24);

Distance to travel in inches

Stops after x inches have been traveled

stopOnTouch();

Stops if the touch sensor is pressed

stopOnColor(colorGreen);

Color: colorRed, colorGreen,colorBlack

Stops of the color sensor sees the specified color.

Until Functions

Generally, these functions are used within a loop and are then followed by some other action.

untilColor(colorGreen);

Will detect when a color is encountered

untilSonarLessThan(6);

Will detect when robot gets within x inches of an object

untilDistance(24);

Detects when a certain distance in inches has been travelled

untilTouch();

Detects touch sensor is pressed

Special Functions

accessoryUp(); accessoryDown();

accessoryUp(90); accessoryDown(90);

accessoryUp(20,55); accessoryDown(20,55);

Optional: degrees of rotation

Optional: power level

Moves accessory up/down. Optional Parameters such as degrees and power level. If no degree is specified, then motor will stop on a Stall condition.

accessoryToDegree(frontArm,90.0,100);

Name of the Motor
Degree to rotate to: 0 to 360

Power Level

Moves accessory motor to specified degree at specified power level.

Motor(motorA,90,FORWARD);

Which motor

Turns specified motor a specified number of degrees FORWARD or BACKWARD

Motor(motorC,60,BACKWARD);

Degrees to turn

Direction to turn

wait(5);

Time in seconds to wait

Waits for a specified amount of time

waitForOrangeButton();

waitForTouchSensor();

Waits for User to press the Orange button

Waits for the Touch Sensor to be pressed.Bottom of Form

Speaking Functions

say(“Some Text”);

sayPhrase(“Some Text”);

Example Programs

#include "Library2013.c";

/*---------------------------
Author: [Your name here]
Date: September 4, 2011
Description: Makes the robot go forward,
  stop, and then come back.
Filename: ComeBack.c
-----------------------------*/

task main() {
  Startup();
  SetPowerLevel(30);
  DriveForward();
  StopAfterDistance(12);
  DriveBackward();
  StopAfterDistance(12);
}
#include "Library2013.c";

/*---------------------------
Author: [Your name here]
Date: September 4, 2011
Description: Makes the robot go forward,
  turn around, and then come back.
Filename: ComeBack.c
-----------------------------*/

task main() {
  Startup();
  SetPowerLevel(30);
  DriveForward();
  StopAfterDistance(12);
  TurnClockwise(180);
  DriveForward();
  StopAfterDistance(12);
}
#include "Library2013.c";

/*---------------------------
Author: [Your name here]
Date: September 4, 2011
Description: Makes the robot run around the block.
Filename: RunAroundBlock.c
-----------------------------*/

task main() {
  Startup();
  SetPowerLevel(30);
  DriveForward();
  StopAfterDistance(12);
  TurnClockwise(90);
  DriveForward();
  StopAfterDistance(12);
  TurnClockwise(90);
  DriveForward();
  StopAfterDistance(12);
  TurnClockwise(90);
  DriveForward();
  StopAfterDistance(12);
  TurnClockwise(90);
}
#include "Library2013.c";

/*---------------------------
Author: [Your name here]
Date: September 4, 2011
Description: Makes the robot run around the block.
Filename: RunAroundBlock.c
-----------------------------*/

task main() {
  Startup();
  SetPowerLevel(30);
  While(true) {
    DriveForward();
    StopAfterDistance(12);
    TurnClockwise(90);
  }
}