Difference between revisions of "TETRIX FTC Templates"

From ROBOTC API Guide
Jump to: navigation, search
(Created page with "<yambe:breadcrumb>TETRIX|TETRIX</yambe:breadcrumb> == Gather the Required Information == {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFF...")
 
(User Control Template)
 
(11 intermediate revisions by one user not shown)
Line 1: Line 1:
<yambe:breadcrumb>TETRIX|TETRIX</yambe:breadcrumb>
+
<yambe:breadcrumb self="FTC Templates">TETRIX|TETRIX</yambe:breadcrumb>
 +
<br />
  
== Gather the Required Information ==
+
{{tl|1|}}
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;" width="100%" cellpadding="5%" cellspacing="0" border="0"
+
<br />
|-
+
| Before you can use your Samantha Module with ROBOTC, you must install the Windows drivers and set the device up for use.
+
'''Note: There are many different router configurations, and many different combinations of network type, encryption type, etc. We are using a commonly used network setup (with the router in between the computer and modem with standard encryption). Your particular setup may be different, and may require additional steps to set up properly.
+
|-
+
|'''1.''' The first thing we will want to do is download and install FTC's Field Control Software package. This can be found on FIRST's site [http://www.usfirst.org/roboticsprograms/ftc/ftctoolbox-0 (usfirst.org)].
+
|-
+
|'''2.''' Next, we will need the SSID, encyption type, and password for the network we wish to connect to. For testing purposes, we named our router "SamoTest1" with an encryption type of WPA (TKIP).
+
|-
+
|'''3.''' You will also need a 4GB or smaller USB flash drive, formatted to FAT32 file format. To format the flash drive, navigate to the Start menu, select Computer, right click on the flash drive's name, then click Format. In the drop down box, select 'FAT32' as the file format, and check the 'Quick Format' box (for a faster format).
+
|-
+
  
 
+
== FTC Templates==
|[[File:Format One.jpg |800x451px]]
+
{|
 
|-
 
|-
|'''4.''' Navigate to the Start menu, All Programs, Samantha Field Control System, and start the program called "Samantha Network Config".  
+
| 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>
 
+
<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>
|[[File:Network Config One.jpg |800x451px]]
+
|-
+
|'''5.''' Enter all the information for your network and click. Two message boxes will pop up, the first one informing you that the password you entered will be converted to an encrypted key and the second informing you that the config file has been saved to your flash drive.
+
|-
+
 
+
 
+
|[[File:Network Config Two.jpg |800x451px]]
+
|-
+
|'''6.''' Close the program and navigate to your ROBOTC installation folder (default location of C:\Program Files(x86)\Robomatter Inc\ROBOTC Developement Environment). Navigate to the Firmware folder and copy the Samantha.hex file into your flash drive. You should also see a folder named "SMRTNTKY" on the flash drive; this is where the Network Config tool saved the config file for your network.
+
|-
+
|[[File:Firmware Location.jpg |800x451px]]
+
 
|-
 
|-
 
|}
 
|}
<br />
 
  
== Flash the Samantha Module ==
+
== Autonomous Template==
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;" width="100%" cellpadding="5%" cellspacing="0" border="0"
+
{|
 
|-
 
|-
| You must now update the Samantha Module's firmware and install the config file you created using the Network Config tool; otherwise the Samantha Module will not recognize your network.
+
| After creating a new autonomous template, you will see segments of code that you may be unfamiliar with. The first three <font color= #0033CC><STRONG>#pragma</STRONG></font> 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).
 
|-
 
|-
|'''1.'''  Unplug the USB flash drive from your computer and (making sure the battery is unplugged) plug it into the Samantha Module. Plug in the battery while holding down the red/black button on top of the module. Release the button approximately 3 seconds after the red light appears on the module.
+
|[[File:FTC Autonomous Template.png]]
 
|-
 
|-
|'''2.'''  The Samantha Module will flash the red light twice in rapid succession and then flash the white repeatedly. You may also see the flash drive's LED flickering (if applicable). This means the Samantha Module is installing the firmware. When it's done, it will flash the red, white, and blue lights in sequence, then repeat the process. Be patient; this process normally takes 20-30 seconds and as long as 2-3 minutes. When it is done it should have a solid red light and a blinking white light (meaning it is connected to the network).
+
| 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.<syntaxhighlight lang="ROBOTC">#include "JoystickDriver.c"</syntaxhighlight>
 
|-
 
|-
|}
+
| 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. <syntaxhighlight lang="ROBOTC"> void intitializeRobot()</syntaxhighlight>
<br />
+
 
+
== Installing and Updating the NXT ==
+
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;" width="100%" cellpadding="5%" cellspacing="0" border="0"
+
|-
+
|'''1.'''  Like all other Windows devices, the NXT requires a driver in order to work properly. This is normally installed with ROBOTC, but if for any reason it needs reinstalled you can find it [http://www.robotc.net/download/nxt/ here on ROBOTC's website.]
+
|-
+
|'''2.''' Next, download ROBOTC's firmware to the NXT. To do this, connect the NXT to the computer and turn it on. Navigate to the Robot menu in ROBOTC and make sure that 'LEGO MINDSTORMS NXT+TETRIX' is chosen as the Platform Type and that 'Physical Robot' is chosen as the Compiler Target. Then, click Download Firmware->Standard File to download the ROBOTC firmware to the NXT (this should take anywhere from 10 seconds up to a minute).
+
 
|-
 
|-
 +
| 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. <syntaxhighlight lang="ROBOTC">
 +
task main()
 +
{
 +
  initializeRobot();
  
 +
  waitForStart();
  
|[[File:Download Firmware.jpg]]
+
  //Autonomous code goes here.
|-
+
  }
|'''3.''' Navigate to File->Open Sample Program->NXT->Samantha Module->samostat.c. Compile and download this program onto the NXT brick.
+
</syntaxhighlight>
|-
+
|'''4.'''  Navigate to Robot->NXT Brick->Communication Link Setup and change the 'Search Selection' drop down menu to "USB, Bluetooth, or Wifi". This will enable ROBOTC to search your network for the NXT once it is connected. Click close to save the changes.
+
|-
+
|[[File:Communication Type.jpg]]
+
 
|-
 
|-
 
|}
 
|}
<br />
 
  
== Connecting the NXT and Samantha Module ==
+
== User Control Template ==
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;" width="100%" cellpadding="5%" cellspacing="0" border="0"
+
{|
 
|-
 
|-
|'''1.'''  Keeping the USB-B end connected to the NXT, disconnect the USB flash drive from the Samantha Module and the USB-A connector from the computer. Connect the USB cable to the Samantha Module instead.
+
|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.
|-
+
<syntaxhighlight lang="ROBOTC">
|'''2.'''  Turn on the NXT and the Samantha Module if you have not done so already. The NXT will show that it is connected via USB and the Samantha Module's 'NXT' LED should turn a solid blue (it may flicker from time to time; this means that it is transferring data to the NXT).
+
task main()
|-
+
{
|'''3.'''  If the blue NXT does not light up, press the red/black button on top of the Samantha module.
+
  initializeRobot();
|-
+
|'''4.'''  Run the "samostat" program on the NXT. After a few seconds, it should connect to the wireless network through the Samantha Module and display information such as the SSID, IP address, etc. You can then type in the IP address displayed into a web browser to pull up the Samantha Module's NXT Status Page.
+
|-
+
|[[File:Network Page.jpg | 600x800px]]
+
|-
+
|'''5.''' Open a program in ROBOTC, compile it, and download it to the NXT. If everything is setup correctly, the program should download and compile through the Wifi network. If so, congratulations! You've successfully set up and connected your Samantha Module through ROBOTC. If you have any problems, see our troubleshooting/reference guides below.
+
|-
+
|}
+
<br />
+
  
== References and Troubleshooting ==
+
  waitForStart();
{|
+
 
|-
+
  while(true)
|[https://sites.google.com/site/ftcsamoledcodes/  Samantha LED Code Guide:] Very useful if you have a strange combination of LED lights.
+
    {
|-
+
      //User Control code goes here.
|[http://www.youtube.com/watch?v=hh8YUswtTss FTC Video Tutorial: Updating a Samantha Module] Shows how to force the Samantha Module into boot mode and upload files from a flash drive. You can copy the samantha.hex firmware file from the location indicated in the video instead of the ROBOTC folder; they should be the same file.
+
    }
|-
+
}
|[http://www.usfirst.org/roboticsprograms/ftc/ftctoolbox-0 USFIRST's FTC Toolbox page:] Has various tutorials, guides, and downloads including the Field Control System software package (which contains the Samantha Network Config utility). 
+
</syntaxhighlight>
|
+
 
|}
 
|}
 
<br />
 
<br />

Latest revision as of 19:17, 20 November 2012

TETRIX → FTC Templates



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).
FTC Autonomous Template.png
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.
 
task main() 
 {
  initializeRobot();
 
  waitForStart();
 
  //Autonomous code goes here.
 }

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.
 
task main() 
 {
  initializeRobot();
 
  waitForStart();
 
   while(true)
     {
      //User Control code goes here.
     }
 }