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 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. |
|||
Speaking Functions |
|||||
say(“Some Text”); sayPhrase(“Some Text”); |
|
|
|||
#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); } }