Getting Started
RobotC is based upon the C language system and prior programming experience is needed for the following tutorials. It is assumed that the reader has used or is familiar with a C based language, most likely Java, and can understand basic programming syntax.
The start of any program in RobotC begins with the following lines:
task main()
{
Always remember to close the bracket of your program when it is complete. Making the simplest program possible in RobotC:
task main()
{
}
RobotC will execute any commands within the body of text following these lines in a sequential order. For instance, if one were to write:
task main()
{
motor[ port1 ] = 127;
wait1Msec( 200 );
motor[ port1 ] = 0;
}
The specific terms of each line will be discussed in greater detail in later tutorials. The syntax used in this example is only provided to show a working piece of code. The program would first perform the command listed on the “motor[port1] = 127;” line (setting the speed of a motor to 127). Then, the program would wait 200 seconds, stemming from the “wait1Msec(200);” line. Lastly, the program will stop the motor, “motor[port1] = 0;”
Now it’s time to create your first program!!! Open up RobotC and create a new file (File -> New -> New File or just press Control N). Now copy the following text into the new document and REMEMBER TO HIT Control S after doing so to save the file:
task main()
{
writeDebugStream( “Hello World” );
}
writeDebugStream(“PLACE TEXT HERE”); is exactly the same as printf in C and C++. But, for now, we will just use writeDebugStream to output text rather than variables. As of right now, all you need to know is that any text written between the quotes in the above statement will appear in a window known as Debug Stream which we will use later. Debug Stream is the same thing as the console in Java and C / C++, but it does not accept text input from the user.
Go to Robot -> Platform Type -> VEX Robotics -> Vex 2.0 Cortex to ensure we are compiling for the right microsystem. Let’s specify that we are programming for the RobotC Emulator (Robot -> Compiler Target -> PC-Based Emulator). Now let’s compile the code in order to figure out whether or not it works (Robot -> Compile Program or press F7). Lastly, we need to run the code to see that it does what is expected of it (Robot -> Compile and Download Program or press F5). When the box containing the Start button pops up, DO NOT HIT START. Let’s open the output window to see what the program wishes to tell us (Robot -> Debugger Windows -> Debug Stream). Now you may hit the Start button and bask in the glory of your success. If everything was done correctly, a line of text that says “Hello World” should appear in the Debug Stream window.
You've completed your first program in RobotC.
Cheers!
The start of any program in RobotC begins with the following lines:
task main()
{
Always remember to close the bracket of your program when it is complete. Making the simplest program possible in RobotC:
task main()
{
}
RobotC will execute any commands within the body of text following these lines in a sequential order. For instance, if one were to write:
task main()
{
motor[ port1 ] = 127;
wait1Msec( 200 );
motor[ port1 ] = 0;
}
The specific terms of each line will be discussed in greater detail in later tutorials. The syntax used in this example is only provided to show a working piece of code. The program would first perform the command listed on the “motor[port1] = 127;” line (setting the speed of a motor to 127). Then, the program would wait 200 seconds, stemming from the “wait1Msec(200);” line. Lastly, the program will stop the motor, “motor[port1] = 0;”
Now it’s time to create your first program!!! Open up RobotC and create a new file (File -> New -> New File or just press Control N). Now copy the following text into the new document and REMEMBER TO HIT Control S after doing so to save the file:
task main()
{
writeDebugStream( “Hello World” );
}
writeDebugStream(“PLACE TEXT HERE”); is exactly the same as printf in C and C++. But, for now, we will just use writeDebugStream to output text rather than variables. As of right now, all you need to know is that any text written between the quotes in the above statement will appear in a window known as Debug Stream which we will use later. Debug Stream is the same thing as the console in Java and C / C++, but it does not accept text input from the user.
Go to Robot -> Platform Type -> VEX Robotics -> Vex 2.0 Cortex to ensure we are compiling for the right microsystem. Let’s specify that we are programming for the RobotC Emulator (Robot -> Compiler Target -> PC-Based Emulator). Now let’s compile the code in order to figure out whether or not it works (Robot -> Compile Program or press F7). Lastly, we need to run the code to see that it does what is expected of it (Robot -> Compile and Download Program or press F5). When the box containing the Start button pops up, DO NOT HIT START. Let’s open the output window to see what the program wishes to tell us (Robot -> Debugger Windows -> Debug Stream). Now you may hit the Start button and bask in the glory of your success. If everything was done correctly, a line of text that says “Hello World” should appear in the Debug Stream window.
You've completed your first program in RobotC.
Cheers!