Programming Tips

From Team1370

(Difference between revisions)
(revert to 03:18, 14 February 2006 by 72.45.26.29)
 
(11 intermediate revisions not shown)
Line 1: Line 1:
-
''Note: This is actually a "getting started with the professional method" guide.''
+
== Aliases to keep in mind ==
 +
*pwm## where the number ranges from 01 to 12 (and up to 16 if the "Generate_Pwms(pwm13,pwm14,pwm15,pwm16);" is included in the "void Process_Data_From_Master_uP(void)" function of the user_routines.c file)
-
There are easier ways to program your robot controller, including Easy C (new for 2006), however, I am far more familiar with the classic, more complicated method using MPLab IDE. This perhaps more complicated system is the one which I desribe below, but do consider that there are other options and other tutorials available on the web. Of course, I suggest the following method. -[[User:Admin|Pierce Lopez]]
+
The pwm## alias is used to assign an output value to the speed controllers according to the pwm slots that they are each plugged into. ''Values range from 0 to 255''
-
== Collecting Your Tools ==
 
-
The system I use requires the use of a few different tools which work together (more or less). Here's what you'll need:
 
-
*'''A Laptop running Windows''' A laptop will make connecting to the robot immeasurably easier and more convenient, and most tools I use are only available for windows, and have no counterparts for other OSs (unfortunately).
+
*p#_? where the number ranges from 1 to 4 and the ? sign is either "x", "y", or "wheel"
-
*'''... with a serial port.''' You're laptop might already have one, it's like a rounded-corner trapeziod with two rows of pin-holes. My newer laptop does not have one, so I got a usb-serial adapter cable for $40 at RadioShack.
+
-
*'''MPLAB IDE v7.20''' Newer versions don't work, according to the source code documentation. Download this version [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023073 here].
+
-
*'''MPLAB C18 Compiler Student Edition v2.40''' Newer versions of this will apparently not work either, and this older version is pretty difficult to find online. I found a download link for it [http://www.acfr.usyd.edu.au/teaching/3rd-year/mtrx3700-Mx3/reference/tools/C18/c18_240_SE.zip here]. If that link doesn't still work, search for it.
+
-
*'''IFI_Loader v1.0.12''' Can be found at the bottom of [http://www.ifirobotics.com/rc.shtml this] page. But don't get the robot default code from there, if you intend to use the camera with your robot, as we will in this guide.
+
-
*'''The Default Robot+Camera Code''' Download "frc_camera.zip", the "bells-and-whistles version", from [http://kevin.org/frc/ this] page.
+
-
*'''CMUcam2_workbook.pdf''' This document contains very useful diagrams and specific sets of instructions which I'll reference, get it on the [http://kevin.org/frc/ same page] as the robot code.
+
-
*'''puTTY''' For later, when we're sending adjustment commands to the camera. You just need "putty.exe", get it [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html here].
+
-
*'''COM/Telnet Bridge''' For use with puTTY, get the "tsb.exe" package from [http://www.elifulkerson.com/projects/telnet-serial-bridge.php this] page.
+
-
== Getting it all set up ==
+
This alias represents the value of one of a specific joystick's axis positions. It may be from one of the four possible joysticks, of which it may be either the x-axis, y-axis, or throttle wheel (if one exists). ''Values range from 0 to 255''
-
That was a lot of stuff to download, now let's get it set up.
+
-
#'''Install MPLAB IDE''': Extract the files from the zip file you downloaded into a folder, and run "MPLAB v270 Install". You don't need to install support for any fancy debuggers or devices which are mentioned, we just need the basic program.
 
-
#'''Install MPLAB C18''': Extract the installer from the zip file you downloaded and run it. During the install process, select the option which register the C18 compiler and linker with MPLAB IDE, but you don't need to select the options which "Add the compiler/linker/etc. to the system path." You should almost definitely install C18 to the default location, to prevent headaches later, and save som configuration work.
 
-
#'''Install IFI_Loader''': Extract the folder from the zip file, and run "setup.exe".
 
-
#'''Unzip the code''': You need to put the folder which contains the code close to the root of your drive; in simpler terms, just extract the frc_camera folder from frc_camera.zip right to your C: drive, so the files it contains are in C:\\frc_camera\\(files here). (You need to do this because the C18 compiler simply can't handle a long directory name.)
 
-
#Start ''MPLAB IDE'' (you can do this by clicking the icon that has been created on your desktop). Click on the '''Project''' menu along the top, and click '''Open...''' in the menu shown. Browse to the folder you just put the code in, which might be ''C:\\frc-camera\'' (if you can't find it, click the icon with folder with the up-arrow until you see your C: drive, and go from there). Only one file should be shown in the window, ''camera.mcp'', so select it and open it. You will have to reopen this project file every time you start MPLAB IDE. A couple of windows should have opened, including at least a long list of files on the left side. If this hasn't happend, something might have gone wrong already.
 
-
#Now click the '''Project''' menu, click the '''Build Options...''' submenu, and click '''Project''' at the bottom of that submenu. In the window which appears, make sure that ''Include Path'' is set to ''C:\\mcc18\\h'', and ''Library Path'' is set to ''C:\\mcc18\\lib''. If you installed MPLAB C18 to the default location, everything should be set. (If you changed the install location of C18, you'll have to change these settings, as well as those under ''Project/Set Language Tool Locations'')
 
-
#Now click the '''Project''' menu, and click '''Build All'''. If a window titled ''Output'' pops up and ''Build Succeeded'' eventually appears at the bottom of the text there, the default code just compiled, and your coding environment is fully set up! If not, try to figure out what went wrong before continuing.
 
-
#Now we're going to set up some of the other little tools which we'll use later.
 
-
##Create a folder you'll put the last two little utilities in, for example a folder ''Robot Tools/'' on your desktop. Open the ''tsb.zip'' archive you downloaded, and put the folder ''tsb'' it contains, or all the files, into the folder you created.
 
-
##Open ''example.bat'', which came in the ''tsb'' archive, with Notepad (a plain text editing tool found in the ''Accessories'' submenu of the Start menu). In the very last line of the file, change the number ''9600'' to ''115200''. Also, if the com port you'll be using to communicate with the robot isn't ''COM1'', you'll need to change the lone zero in that last line to the number of the ''COM'' port you plan to use, ''minus one''. That's why ''COM1'' is represented by the ''0''.
 
-
##Also put ''putty.exe'' into that folder you created, possibly called ''Robot Tools/'', possibly located on your desktop.
 
-
##Now, click on ''putty.exe'' with the '''right''' mouse button, ''hold it down'', drag it over the desktop, and release. Click ''Create shortcut'' in the menu which pops up next to your pointer when you do this.
 
-
##Do the same ''right click drag / create shortcut'' operation to ''example.bat'' in the tsb folder.
 
-
We'll use these last couple of programs to communicate with our robot while it's running, mainly to view messages which will help you to diagnose problems, and to adjust the camera settings.
+
*p#_sw_? where the number ranges from 1 to 4 and the ? sign is either "trig", "top", "aux1", or "aux2"
-
== Setting-Up the Robot and Connecting ==
+
This alias represents the value of one of a specific joystick's buttons. It may be from one of the four possible joysticks, of which it may be either the trigger, top, or side buttons.  ''Values are either 0 (normal) or 1 (pressed)''
-
=== The Robot ===
+
-
Before we can interact with the camera or begin to test code on the robot, we need to get the robot's electronics wired to a very basic minimum. The Robot Controller needs a charged backup battery and should have a charged main battery hooked up to it (see the appropriate FIRST documentation for help with that stuff). The Operator Interface needs to be getting power from the power adapter that came with it, and needs to be connected to the Robot Controller, either with a tether or with the radio set-up.
+
-
=== The Camera ===
 
-
The camera needs to be built into its pan-and-tilt mechanism. All the parts needed are included in the Robot Kit, and instructions can be found in the first part of ''CMUcam2_Workbook.pdf''. Also in the workbook are instructions for how to wire the camera to the Robot Controller. In fact, much of what I'm about to describe is also in that workbook, so you can always go back to it as a reference. However, to prevent confusion between the instructions for various different tasks found in the workbook, I'll specify here what exactly needs to be connected. Just open the workbook to the diagram (p. 17) so you can identify the pins and ports I specify.
 
-
''in progress''
+
*pwm01 and pwm02 are used by the camera code to control the servos. One thing to remember is that, unlike with a normal motor, the value of these correspond to positions (127 is center) such that assigning 200 would make the servos jump to that position -- instead of spinning forward at the given speed. Thus, the value can also be used in reverse, to determine the position of the camera.
-
== Introduction to Programming ==
 
-
''TODO''
 
-
=== Programming Resources ===
 
-
''TODO''
 
-
== Programming Reference ==
+
== Compiling errors got you down? ==
-
=== Aliases to keep in mind ===
+
*Check for missing or extra semicolons and parentheses. They can be a real hassle.
-
''TODO''
+
 
 +
*Make sure you declare variables at the top of a function (remember, this is C, not C++)
 +
 
 +
*Functions should be prototyped in a header file that is included in the .c file
 +
 
 +
 
 +
== Other things to remember ==
 +
*The Limit_Mix function can be used to limit the value of something to between 0 and 254. Just make sure that the input sent to the function is somewhere around 2000 to 2254 in most cases (in other words, add 2000 to your equations before encasing them in a Limit_Mix).
 +
 
 +
 
 +
== Team 1370 Robot Code ==
 +
Here is a link to the current version of our [[Robot Code 2006]], which is a good example of various programming techniques we use.

Current revision as of 03:55, 2 October 2007

Contents

[edit] Aliases to keep in mind

  • pwm## where the number ranges from 01 to 12 (and up to 16 if the "Generate_Pwms(pwm13,pwm14,pwm15,pwm16);" is included in the "void Process_Data_From_Master_uP(void)" function of the user_routines.c file)

The pwm## alias is used to assign an output value to the speed controllers according to the pwm slots that they are each plugged into. Values range from 0 to 255


  • p#_? where the number ranges from 1 to 4 and the ? sign is either "x", "y", or "wheel"

This alias represents the value of one of a specific joystick's axis positions. It may be from one of the four possible joysticks, of which it may be either the x-axis, y-axis, or throttle wheel (if one exists). Values range from 0 to 255


  • p#_sw_? where the number ranges from 1 to 4 and the ? sign is either "trig", "top", "aux1", or "aux2"

This alias represents the value of one of a specific joystick's buttons. It may be from one of the four possible joysticks, of which it may be either the trigger, top, or side buttons. Values are either 0 (normal) or 1 (pressed)


  • pwm01 and pwm02 are used by the camera code to control the servos. One thing to remember is that, unlike with a normal motor, the value of these correspond to positions (127 is center) such that assigning 200 would make the servos jump to that position -- instead of spinning forward at the given speed. Thus, the value can also be used in reverse, to determine the position of the camera.


[edit] Compiling errors got you down?

  • Check for missing or extra semicolons and parentheses. They can be a real hassle.
  • Make sure you declare variables at the top of a function (remember, this is C, not C++)
  • Functions should be prototyped in a header file that is included in the .c file


[edit] Other things to remember

  • The Limit_Mix function can be used to limit the value of something to between 0 and 254. Just make sure that the input sent to the function is somewhere around 2000 to 2254 in most cases (in other words, add 2000 to your equations before encasing them in a Limit_Mix).


[edit] Team 1370 Robot Code

Here is a link to the current version of our Robot Code 2006, which is a good example of various programming techniques we use.

Personal tools