Debugging a robot program
You can monitor, control, and manipulate cRIO processes using the debugger. This section will describe how to set up a debug session for a robot control program. (See the Wind River Workbench User’s Guide for complete documentation on how to use the debugger: Help > Help Contents > Wind River Documentation > Guides > Host Tools > Wind River Workbench User’s Guide.)
Creating a Target Server Connection
Workbench connects to your cRIO controller and can download and remotely debug programs running on it. In order to make that connection, Workbench needs to add your cRIO to its list of Remote Systems. Each entry in the list tells Workbench the network address of your cRIO and the location of a kernel file that is required for remote access.
To create the entry for your system click on the "Define a connection to remote system" button on the top bar of the tab.
Note: If the Remote Systems tab is not visible, you can show it by going to the "Window" menu and selecting "Show View" then "Remote Systems"
Specifying the connection type
In the “Select Remote System Type” window choose “Wind River VxWorks 6.x Target Server Connection” and click “Next”.
Specifying the target server options
1. Fill out the “Target Server Options” window with the IP address of your cRIO. It is usually 10.x.y.2 where x is the first 2 digits of your 4 digit team number and y is the last two digits. For example, team 190 (0190) would be 10.1.90.2.
2. Select a Kernel Image file by making sure the "File" radio button is highlighted and clicking Browse. The file is located in the WindRiver install directory in the WPILib top level directory called “C:\WindRiver\WPILib\”. Select the file that matches your cRIO version, either cRIOFRC_vxWorks (8-slot cRIO FRC) or cRIOFRCII_vxWorks (4-slot cRIO FRCII).
3. Click on the "Select" button next to the Processor box to open the Processor Selection dialog.
Processor Selection
Click the arrow next to mpc52xx to expand the tree, then click on MPC5200 to select it. Click OK to close the dialog box, then click Finish on the New Connection dialog.
Viewing the currently running processes
After making the connection you should see a list of the running tasks on the target server.
Connecting to the Target
To start a debug session, first ensure the PC is connected to the target (look for the list of running tasks below the target name in the Remote Systems tab). If you are not connected to the target, right click on the target name in the Remote Systems tab and select "Connect 'TargetName'".
Note: If the Remote Systems tab is not visible, you can show it by going to the "Window" menu and selecting "Show View" then "Remote Systems"
Verify that no User Code is running
Be sure to not use the Run/Debug configuration if you have a robot program deployed and thus starting up automatically in the background. Having two robot programs trying to run at the same time is very confusing. Use the Undeploy menu item if you think there is already a deployed program. Verify that no code is running by opening the FRC Driver Station and checking that the Communications indicator is green and the Robot Code indicator is red, if the Robot Code indicator is green and you have Undeployed the program, reset the cRIO to clear the running code.
Building a robot program
Before downloading your program to the cRIO it must be built. To do this right-click on the project in the Project Explorer and select "Build Project". This will compile and link the project files.
Create a Debug Configuration
To create a Debug Configuration, right-click on the project name in the “Project Explorer” window and select “Debug VxWorks Kernel Task…” to open the Debug dialog. Change the name of the debug target to something meaningful like “2010TargetTest” in the picture. Then click Browse to set the Entry Point.
Setting the Entry Point
Click the arrow next to "Target" to collapse the list, then click the arrows to expand the Downloads folder and the .out file listed there. Enter "FRC" in the text box. Click on "FRC_UserProgram_StartupLibraryInit" to select it, then click OK. Click Run to run the program on the cRIO.
Setting Debug Options
Check the boxes for “Break on Entry” and “Automatically attach spawned Kernel Tasks.” This tells the debugger to stop at the program’s first instruction and make the spawned task (your robot task) available to debug. The other options can normally be left at default settings. Click "Apply" to apply your changes.
Loading and starting the debug session
To start debugging right away you can hit the "Debug" button and the program will be loaded into memory. If you will be repeating this often, you can save the debug configuration on the debug menu by going to the "Common" tab and selecting "Degug". This will save the project in the debug menu in the toolbar. Next time, just select the dropdown, pick your project and start debugging.
Set a Breakpoint
Clicking the “Debug” button does several things. It changes the Workbench to the Debug Perspective which has the views Debug, Breakpoints, and Variables along the right side of the window. It starts the robot task and pauses it at the first program statement, in FRC_UserProgram_StartupLibraryInit.
Now double-click in the left margin of the source code window to set a breakpoint in your user program: A small blue circle indicates the breakpoint has been set on the corresponding line. (You can see all your breakpoints in the Workbench’s Breakpoints view.)
Run to the Breakpoint
Click the “Resume” button (the green arrow) to resume program execution up to the first breakpoint. Note that if the breakpoint you have placed is inside one of the Teleoperated or Autonomous methods, the robot will have to be set to the appropriate mode and enabled with the Driver Station in order to reach the breakpoint.
Your Breakpoint
The program will start running and then pause at the breakpoint. From here you can use the three panes on the left of the screen (Debug, Breakpoints and Variables) to monitor and control the execution of your program.
The Debug Tab
The Debug view shows all processes and threads running in the cRIO. Select the stack frame to see the current instruction pointer and source code (if available) for the selected process. When your breakpoint is reached, make sure your program is selected in the task list and your source code is displayed with a program pointer. You can continue stepping through your code using “Resume,” “Step Into,” “Step Over,” and “Step Return” buttons: If you see assembly code instead of C++ code displayed, it’s because you’ve stepped down into library code where the source is not available to the debugger. “Step Return” will bring you back up a level.
The Variables Tab
The Variables view shows the current values of variables. To see a variable that is not displayed, select the “Expressions” tab and enter the variable name. This will show the variable’s value if it’s in scope. You may also want to click on the arrows next to a variable to expand the tree and show it's members. For example, expanding our Robot Demo variable ("this") shows our "myRobot" and "stick" variables.
Stopping Debugging
To stop debugging, you can disconnect or terminate the process. Disconnecting detaches the debugger but leaves the process running in its current state. Terminating the process kills it on the target.
Debugging with NetConsole
Another way to debug your program is to use printf or cout statements in your code and receive them using NetConsole. See here for more information on using NetConsole.
Troubleshooting
Source code displayed is out of sync with cursor when debugging: The source has changed since it was loaded onto the cRIO. Rebuild the project (build clean) and make sure included projects are up to date.
Robot program not visible in the Debug View: Make sure that the “Automatically attach spawned Kernel Tasks” option is on. When you click “Debug,” the cRIO will first pause in initialization code, before it gets to your program. When you “Resume” it will soon begin your robot program.