2009 Control System C++ Tips & Pitfalls

Hi everyone,

We’ve been working in C++ with our control system for a few weeks now.
By far and away, the biggest obstacles for us were getting the software installed, updated, and configured properly, and getting the hang of actually getting compiled code on to the robot and running.

Our students (mostly programming novices this year) had little trouble learning, grasping the concepts of, and using the WPI C++ library. In fact, as someone who has taught novice students programming for FRC for 5 years now, my experience has been that the C++ library DOES simplify the basics of robot programming for novice students.

(to be clear, please note that this is not to say that the new Windriver programming environment or the setup/wiring/use/running/documentation of control system as a whole is better for new students – that’s a whole different topic! I’m merely commenting above on the merits of the OO-approach and the WPI API)

Anyway, here are some of the pitfalls and tips that we encountered with programming the new system. I hope this can be helpful to some of the other teams out there.

  1. After installing and applying all available updates to Windriver, you have to configure it for FRC use before it can be used to interact with the controller. The documentation for this is at the END of the FRC C++ User Guide (http://first.wpi.edu/Images/CMS/First/C_Programming_Guide_for_FRC.pdf).

1a. Section “Setting up the Environment” – this lets your software connect to the crio. Once you do this, Windriver shows the connection info in the lower-left panel, including connection status. The software is amazingly good at auto-reconnecting to the crio following any interruption (robot power off, lost wifi signal, unplugged network cable).

1b. Section “Downloading the project to the cRIO” – this tells about using the FIRST Downloader, which is a plug-in of sorts in Windriver that lets you send your program for storage in the flash of the cRIO.
Unfortunately it doesn’t say how to set it up! To set this up, go to the “Windows” menu in Windriver, choose “Preferences”. In the tree, go to FIRST Downloader. Fill in your team #, and then the program image file you want to send to the cRIO on subsequent uses of the download. The program image file is only visible once you’ve built your project for the first time, so you’ll want to create and compile your project before doing this setup. The filename you want to browse to is under your project folder, in PPCsomething/Debug (exact name forgotten, sorry-should be obvious when you do this). The file name is YourProjectName.out.
NOTE: you need to change the image file location if you make a new project, or change your project name!
In other words, the FIRST->Download menu in Windriver is not project sensitive – it will always download the project file you configured in Windows->Preferences regardless of what project you have open in your workspace.

1c. Section “Debugging your Robot Program”. This tells you how to configure Windriver to let you send a program to the cRIO RAM and run immediately. A program sent using the debugging interface is lost when you power-cycle the robot. Follow the instructions closely here to set this up. You have to have done 1a. before doing this.

  1. There are two ways to download your code:
    2a. The FIRST Downloader – Menu FIRST->Download. This downloads your code to the flash of the cRIO and it remains there until you Download something else in this manner or you use the FIRST->Undeploy menu option to delete it from the cRIO. Programs downloaded this way do not begin running until the robot is restarted (power cycle - there is no reset button on OI or cRIO as in past years). Power cycling takes from 15-45 seconds.
    Big Note! As described in 1b above, the FIRST downloader is NOT project saavy. It MUST be reconfigured whenever you switch projects (or rename an existing project you’ve been working with) to download the proper output file from the project you want deployed to the robot.

2b. The Debug interface, as set up in 1c above. This sends your program to run immediately, but the program is lost when the cRIO reboots. You must use the FIRST->Undeploy menu BEFORE you initiate the debugging session. Otherwise, it will appear that it is debugging your current program, but in reality it will just run the version of the code sent previously with FIRST->Download.

  1. When reading the documentation, the term “Deploy” is synonymous with using the FIRST->Download menu. Similarly a “Deployed Program” is one sent using “FIRST->Download” and NOT one sent using the debugging interface.

  2. When making a project to get started, use the example templates. This is described in “Creating a Robot Project” section of the user’s guide. This makes a NEW project in your workspace, prepopulated with copies of the example sources and all the configuration necessary to compile with WPI lib. Once you have the project created this way, you can rename it to your liking by right clicking the project name in the left tree and selecting rename.

  3. The API documentation (http://first.wpi.edu/Images/CMS/First/CProgrammingReference.chm) for WPI Lib is missing things (for example, DigitalInput reading is missing the most basic Get() function documentation and the Relay class is missing docs for the internal types to indicate which direction to flip the relay in the Set function). Check the header files if you find yourself looking at the documentation feeling like some detail is lacking! The headers are easily accessible from the project tree if you make your project as described in 4 above.

I’ll try to update this as we continue to use the new system.
Happy holidays to the FIRST community!

Thanks for the great advice!

I’d ask the community to try and keep these “tips and tricks from the community” posts related to a single programming environment concentrated in a single thread - like this one - if at all possible. One for Wind River, and one for LabVIEW. It’s harder for teams to search CD when all the information is scattered across numerous threads and buried within countless “help me - I’m lost” discussions.

I will link to the best CD threads (like this one - thanks for the great info!) on http://controlsystem.neofra.com on the Software page.

Here’s a cross link to the equivalent Tips and Tricks thread I just created for LabVIEW.

Depending on how well we all follow this standard and contribute to this thread, perhaps it will be worthy of a sticky some day.