basic functions

act name() /*this is the name of the activity all of the things inside of the activity should be inside curly brackets*/

start name(); /* start the action */

move(mm); /*moves the robot a specific number of millimeters - is backwards (blocking)

turn(degrees); /*turns robot the specified number of degrees (blocking)*/

turnto(degrees); /*turns robot to a specific heading relative to its starting position (blocking)*/

speed(mm/s); /*how fast the robot should move in mm per second (non blocking)*/

rotate(degrees/s); /*spin robot at specified degrees per second*/

halt; /*stops the robot*/

sfSonarRange(n) /*this is the value in mm of the sonar range finder specified by n*/

sfSMessage("Distance = %d", sfSonarRange(n)); /*prints to the trainer window*/

sfSetVelocity(n) /*sets velocity*/

while(n){statements;} /*while n is not 0 statements will keep looping*/

if(condition [&& condition] [|| condition] ) {statements;} /*if the condition is true or/and another condition is true execute statements*/

example
if(count < 4)\\ /*count is 0 the first time so it turns and moves then it is 1 the next time around until it is 5*/
{
turn(90);
move(100);
count = count + 1;
}

waitfor(condition && condition || condition); /*wait for my rangeer 2 to be < 200 and/ or ranger 3 to be < 100*/

blocking means that the program will wait till the command has finish until going onto the next comand so for example if you tell it to turn 90 degrees and then tell it to move 100mm it will wait until it finishes turning 90 degrees before it moves 100 mm. Non blocking doesn't wait. You can specify not to block or to wait a certain amount of time so if you want it to start turning 90 degrees and move forward 1000 mm you would say

turn(90) noblock; move(1000);

all lines that are complete must end with a semi-colon ";"

move(100); /*move 100mm forward*/

comments are surrounded by /* */

halt; /*this tells the robot to stop*/

/*this is the part of the code that will get the robot to turn 90 degrees*/ turn(90);


Page last modified October 10, 2005, at 11:57 AM