| ROBOTC has built-in FTC templates that can be used to quickly and easily program a robot for both the autonomous and tele-op (remote control) portions of a competition. To open a template through ROBOTC, navigate to the File menu and select "New". There are three options under this menu (for FTC competitions we want to focus on the latter two options, Autonomous Template and User Control Template.):

+

| ROBOTC has built-in FTC templates that can be used to quickly and easily program a robot for both the autonomous and tele-op (remote control) portions of a competition. To open a template through ROBOTC, navigate to the File menu and select "New". There are three options under this menu (for FTC competitions we want to focus on the latter two options, Autonomous Template and User Control Template):

<ul><li><em>New File</em> - Creates a blank ROBOTC file.</li>

<ul><li><em>New File</em> - Creates a blank ROBOTC file.</li>

−

<li><STRONG>Autonomous Template</STRONG> - Creates a FTC Autonomous Template (used for the autonomous portion of the competition.)</li>

+

<li><STRONG>Autonomous Template</STRONG> - Creates a FTC Autonomous Template (used for the autonomous portion of the competition).</li>

−

<li><STRONG>User Control Template</STRONG> - Creates a FTC User Control Template (used for the user control (tele-op) portion of the competition.)</li></ul>

+

<li><STRONG>User Control Template</STRONG> - Creates a FTC User Control Template (used for the user control (tele-op) portion of the competition).</li></ul>

|-

|-

|}

|}

Line 51:

Line 55:

}

}

}

}

−

+

</syntaxhighlight>

|}

|}

<br />

<br />

Latest revision as of 19:17, 20 November 2012

Contents

FTC Templates

ROBOTC has built-in FTC templates that can be used to quickly and easily program a robot for both the autonomous and tele-op (remote control) portions of a competition. To open a template through ROBOTC, navigate to the File menu and select "New". There are three options under this menu (for FTC competitions we want to focus on the latter two options, Autonomous Template and User Control Template):

New File - Creates a blank ROBOTC file.

Autonomous Template - Creates a FTC Autonomous Template (used for the autonomous portion of the competition).

User Control Template - Creates a FTC User Control Template (used for the user control (tele-op) portion of the competition).

Autonomous Template

After creating a new autonomous template, you will see segments of code that you may be unfamiliar with. The first three #pragma statements are automatically generated by ROBOTC to set up a basic TETRIX bot and will more than likely be changed as ROBOTC is configured for your specific robot (through the Motors and Sensors Setup page).

The next line of code is what is called an include directive. These directives tell ROBOTC to look at other files (in this case, the file named "JoystickDriver.c") for functions and commands. This is useful if certain segments of code are used in multiple programs; instead of having to copy the code into every program that would use it, said programs only have to have to 'include' the include file. For instance, the JoystickDriver.c file has all of the commands and functions needed to use the Logitech USB Joystick Controller with ROBOTC. By right-clicking on the 'JoystickDriver.c' line of code in the Autonomous Template and selecting "Open include file 'JoystickDriver.c', we can see all the code that is in the include file. Again, without the include directive this code would be needed in every program that needed to use a Joystick Controller.

#include"JoystickDriver.c"

After the include directive there is a function called 'initializeRobot' of the void type. This function is used to 'initialize' the robot before the autonomous period. It should be used to perform pre-autonomous actions such as setting servo positions and calibrating sensors; normally, it should not be used to move the robot, as most competitions require the robots to be still before the start of the match.

void intitializeRobot()

The next segment of code is task main. It first calls the 'initializeRobot' function and (when program flow is returned to it from the function) it has a 'waitForStart();' command. This command tells the robot to wait for the start signal from the FTC Field Control System (FCS) before it runs the autonomous code. If this command was not in the code, the robot would have no way of knowing when to start running its autonomous code. When the autonomous period ends the FCS will end the program whether it has completed its code or not.

User Control Template

The User Control Template is exactly the same as the Autonomous template with one small (but crucial) difference. Inside of the User Control Template's task main() there is a infinite loop that all the User Control code should go inside of. This loop allows user control code to run until the FCS stops the match.