The instructions for 2011 are at http://www.spartanrobotics.org/content/getting-started-frc-programming-under-linux.
Getting Started on C++ and FRC Programming 2009
Jerry Morrison, January 2009
Before the control kit and the robot kit arrive you can start learning about C++, the Eclipse-based development environment, and the new controller.
To start programming in C++
- Install Eclipse with the CDT (C Development Toolkit) -- or the full Wind River Workbench if you have the installer disk.
- If you're running on Windows, install Cygwin and its gcc, make, and gdb packages. (Macintosh and Linux generally come with C++ compilers, so you get to skip these steps.)
- Download Cygwin setup.exe (click the "Install or update now!" link on that page).
- Run the installer program, "setup.exe", and go through the installation wizard: Pick a mirror site. Expand the "devel" section and pick "gcc", "gdb", and "make". Then start the download.
- To enable the Wind River Workbench to find this compiler, you'll need to add this directory to the search 'Path' for executable programs. To do that, add the text
- to the end of your Path variable. The steps are:
- Go to Windows System Properties control panel > Advanced > Environment Variables > System Variables > "Path".
- Double-click on the Path variable to edit it.
- Append ;C:/cygwin/bin to the end of the Path value.
- "OK" all the way out of the control panel.
- Restart Eclipse.
- Find a book or an online tutorial on C++. Here are some examples that sound like a good fit. I have not read them so I can't review them.
- Start working through your tutorial. Write some programs using the Eclipse editor and debugger.
Try creating a sample C++ project within Eclipse: - File > New > Example... > Native Sample Project > The Complex Demonstration Program > Finish.
- Project > Build All.
- Look in the Build Console for build output. There should be no red build errors. Later when you start modifying the program, goofs will cause build errors to show up here.
- Double-click on main.cpp in the Project view to open the source code in an editor view. Read this source file to get an idea what this program does.
- The project also has files Complex.h and Complex.cpp in the "complexlib" folder, and iolib.h and iolib.cpp in the "iolib" folder. You can expand these folders and open these source files.
- Run the program using the Run icon in the toolbar. The program prints and reads text in the Console view, so look there. Exit the program.
- Run the program again using the Debug icon on the toolbar. You'll have to configure it the first time. In the Debug "Create, manage, and run configurations" dialog, pick C/C++ Local Application, click the "+ new launch configuration" button, configure the project name if needed, then click Debug. Eclipse will switch to the "Debug perspective", which is a different arrangement of views, suited to the job of debugging. This time the programs text input and output will go to a separate Console window.
- Tinker with the debugger. You can set breakpoints, step through the program, and examine & change variable values.
- E.g. set a breakpoint on the line "char do_quit='n';" in main.cpp. Resume program execution until it gets to that step. (If it has trouble finding the source code for main.cpp, use the file dialog to show it where the file is, inside WindRiver/workspace/complex_Native.
- In the Variables view, expand the info about variables a and b to see their member variables. Notice that these member variables contain garbage values. They have not been initialized. That's because the class Complex doesn't have any constructor code to initialize its member variables. In a minute we'll fix that.
- Let the program run to completion, or terminate it early using the red block icon on the toolbar.
- Try modifying the program.
- Switch back to the Application Development perspective.
- Add a constructor in Complex.h and Complex.cpp that initializes its re and im fields to 0.0.
- Debug the program again, and notice the properly initialized values a.re, a.im, b.re, and b.im. (If the debugger pauses at the beginning of main(), these values will not yet be initialized. Once it pauses at the breakpoint, they should be properly initialized.)
C++ Language
Focus on basic control structures, functions, classes, and pointers.
C++ is loaded down with complicated features that you won't need. Try to avoid macros ('#DEFINE'), exceptions ('try' and 'throw'), operator overloading, templates, the standard template library, I/O streams, 'friend', name spaces, the 5 kinds of "cast", and other subtleties. Use 'new' instead of the old style 'malloc'. Use 'const' or 'enum' instead of the old style '#DEFINE' constants.
Setting up Subversion for Source Code Control
A source code version control system enables coordination between multiple people working on a program or on the CAD drawings.
You can access Subversion using any or all of these tools:
Learning Subversion:
The team's Subversion repository is now at
svn://boardsailor.com/frc971/2009 (The old repository at https://svn.losaltosrobotics.org/frc971 is frozen.)
The first step to do in Eclipse + Subclipse is to
- Pick the Perspective "Subversion Repository Exploring"
- Right-click in the "SVN Repositories" View
- Add this repository.
More information sources
There are lots of docs in the FRC installation disks. I copied the most interesting ones to the team's Subversion server, in trunk/docs/ and trunk/docs/FRC + National Instruments docs/. Also see the installation directories:
- Workbench/FRC docs
- C:\WindRiver\docs\extensions\FRC -- esp. C Programming Guide for FRC, C++ Reference, FRC Vision API Specification
- NI docs
- C:\Program Files\National Instruments\CompactRIO\manuals -- esp. crio-frc_Operating_Instructions.pdf
- C:\Program Files\National Instruments\LabVIEW 8.5\manuals -- esp. intro parts of FRC_Programming_Guide.pdf, PID_User_Manual.pdf
- C:\Program Files\National Instruments\Vision\Documentation\Concepts_Manual.pdf
- C:\Program Files\National Instruments\Vision Assistant 8.6\manuals\VA_Tutorial.pdf
- VxWorks docs
- C:\WindRiver\docs\extensions\eclipse\plugins\com.windriver.ide.doc.vxworks\vxworks_application_programmers_guide_6.3\vxworks_application_programmers_guide_6.3.pdf, e.g. task management
Be aware that the Eclipse UI has different features with similar names like
- New > Native Application Project vs. New > Example... -> Native Sample Project
- Import... vs. adding a project from the SVN Repository Exploring perspective
- Install into Eclipse... vs. Software Updates > Find and Install...
- Project > Build Options vs. Project > Properties > Build Properties
Definitions
PID controller: A feedback loop for accurate motor control that adds Proportional, Integral, and Derivative components. See PID Controller on Wikipedia and the in-depth article from National Instruments, PID_User_Manual.pdf, mentioned above.
embedded system: A computer embedded in a special purpose device such as a robot, CD player, MRI machine, or airplane. It's typically short on memory and has no keyboard, display, hard disk, speakers, etc.
real-time software: Software that has to meet time deadlines, e.g. turn off the X-ray before over-exposing the patient, output the next audio-video data before there's a hiccup, or adjust a wing flap so the plane keeps flying. The timing must be predictable, not necessarily fast. Stopping at a debugger breakpoint will keep the program from meeting deadlines.
hard real-time: Missing a deadline may be catastrophic.
soft real-time: Missing a deadline is ugly, but recoverable.