01 - Opening/Using RobotC Program

Opening the Program

Double click the desktop icon seen below and titled "ROBOTC for VEX Cortex and PIC"

Your program will open and look similar to the screen capture below. If you are prompted to sign in, sign in as a guest. There are a few main parts of the screen. In the image below, I have placed colored polygons around a few key areas. The key below briefly explains the basic functions of these areas.

RED - This area holds the tabs of what you are working on, just like the tabs of an internet browser (Chrome, Safari, Mozilla, etc). You can click on these to switch between programs/code that you have open and are working on.

GREEN - This is the main area that you will be working in. This is where you will type your code once you have a new coding file open (see how in the next section).

BLUE - This area has two main jobs. You can switch between "Function Library" and "Solutions Explorer" tabs at the bottom of this section. The "Function Library" is an organized collection of all the available functions you can use in RobotC, such as what commands control the motor and what parameters these functions have. The "Solutions Explorer" is something that we won't use. It lets you look at all of the files in your project.

YELLOW - This area shows you any errors that arise when compiling your code.

Creating Your First Program

In your main RobotC interface, select "File ---> New ---> New File". Images are shown below.

This opens a new tab with a new, empty C programming file. You will write your code in this program.

Settings we need to change once (Which "brain" and robot we are using)

First, we need to select which "brain" we are using. In the top menu select "Top Menu --> Robot --> Platform Type --> VEX Robotics --> VEX 2.0 Cortex"

Then we select which robot setup we are using (aka which motors and sensors are plugged into which ports).

Select "RVW CLAWBOT"

What is the RVW CLAWBOT?

As every robot is different, and thus has different motors/sensors in different set-ups, it is vitally important that you know exactly what type of robot you are using and how it is set up.

In our class, we will almost exclusively be using the standard CLAWBOT setup (image shown below).

We need to clearly tell our C program file what robot set-up we are dealing with. By selecting this in the menu screen above, it adds the below line of code below at the top of every C programming file we write that will be used by our robot.

#pragma config(StandardModel, "RVW CLAWBOT")

An image of this is shown below.

This line of code is similar to #include "stdio.h" in your other C programming. As we discussed earlier, #include "stdio.h" includes a standard library of input and output functions such as "printf" and "scanf". In RobotC, #pragma config(StandardModel, "RVW CLAWBOT") does the similar job of including a standard library of functions and set-up. Some of the main parts of this setup are defining which ports each motor is plugged into, and giving them names such as "leftMotor" and "rightMotor".

Here is a link to a spreadsheet of the standard CLAWBOT setup: Link

Compiling to your Virtual World Robot

To use your first virtual robot you need two things:

    1. A program - A set of code written in C that is a set of instructions for what you want the robot to do.

    2. Download the program onto your robot - In this case, you will send the program you write to a virtual robot, instead of a physical robot. We will practice with the virtual robots until you are ready for the physical ones.

Below is a basic program that you can copy and paste into your already open file. This basic program will drive the robot forward for two seconds and then stop the robot.

#pragma config(StandardModel, "RVW CLAWBOT")

task main()

{

//Sets the left and right motors to move forward at full power

motor[leftMotor] = 127;

motor[rightMotor] = 127;


/**********************************************************************************************************************************************

* "wait1Msec(input_time)" Tells the program to wait 2000ms or 2 seconds before going on to read the next code.

* Note though that the previous code is still set so the motors are still at full power during these 2 seconds.

*********************************************************************************************************************************************/


wait1Msec(2000);


//Sets the left and right motors to zero power, in other words, it stops the robot's forward motion.

motor[leftMotor] = 0;

motor[rightMotor] = 0;

}

To test your first program, you need to:

    1. Select a compiling target (real robot or virtual world robot).

    2. Select which Virtual World to use.

Select a compiling target by going to "Robot ---> Compiler Target ---> Virtual Worlds". An image of this is shown below.

Select a virtual world to use by going to "Window ---> Select Virtual World to Use ---> Curriculum Companion 4.2.7". An image of this is shown below.

What is Curriculum Companion 4.2.7?

This is a collection of pre-built challenges and practice levels. Some of these are open levels to explore and practice with. Other levels have a definite challenge/goal to meet and will display either "Incomplete!" or "New Progress Badge Earned" depending on what your virtual robot does. More information about this can be found in the next tutorial.

Compile Your First Program

Now that you have your first program typed in, and your target robot and virtual world selected, you can compile your first program. You want to "Compile and Download" your program meaning you will compile the C program into 1's and 0's for the robot's CPU to read and then download the program to your (virtual) robot.

Go to the menu and select "Robot ---> Compile and Download Program". An image of this is shown below.

Downloading a Pre-written C Program File and Compiling It

Here is the basic movement program from above, except instead of copying and pasting code you can just download it from the link below. The file has an extension of .c

Basic Movement With Notes

To use this code with your Virtual World CLAWBOT, select "File ---> Open and Compile". An image of this is shown below.

Go onto the next tutorial about how to begin using the Curriculum Companion 4.2.7: 02 - Using Curriculum Companion 4.2.7