-
Notifications
You must be signed in to change notification settings - Fork 0
Team Number Command Robot
Originally written on 15 Sep 2016.
The Team Number Command Robot is an example of a C++ Command Based Robot program that uses the WPILibC++.
The robot program is not very useful and it's only functionality is to display digits on a 4 segment LED display. The program uses the roboRio PWM pins to set the LED segments and the DIO pins to control which of the segments to display (the LED display can only have a single of the four digits at any one time).
The main point of the program is to demonstrate how Command and Subsystem objects get wired up with a Command Based robot program and just as importantly how the commands can be efficiently tested from a SmartDashboard.
The C++ source code for the robot program is as minimal as it could be. There is only one Command and two Subsystems. A real robot program would be expected to have a lot more of both. The main idea behind a "Command" based robot program as opposed to an "Iterative" robot program is that the robot's tasks can be modularised into smaller chunks of code AND those modules can be relatively easily tested and verified. With an Iterative program it's more likely that the intialisation and periodic functions could keep on growing as the robot's sophistication increases AND it's very difficult to test specific blocks of code within a single function.
Working with the SmartDashboard was challenging. Bearing in mind that this was my first real attempt at writing a robot program for the roboRio I did expect a high learning curve but I had envisaged writing the robot program would be the most difficult part whereas in fact understanding the FRC Driver Station, the SmartDashboard, NetworkTables and how they all fitted together was a much bigger challenge.
Below this is a brain dump of the major stumbling blocks I had along the way. Ultimately I was able to achieve my aim of being able to do point and click testing from a SmartDashboard of the C++ robot program commands. Very surprisingly I had to try out half a dozen different SmartDashboards before I found one that was workable. Before I started this exercise I hadn't realised just what a state of flux the SmartDashboard situation is in.
The SmartDashboard I was able to get working was DotNetDash from robotdotnet. It's hot off the presses but I was able to mess around with it enough to be able to display controls and have the ones linked to the robot commands do something when clicked.
In the image below the usable DotNetDash is on the left and clicking on the checkboxes indicated by the red arrows will cause the appropriate commands to be executed in the C++ roboRio program. The dashbaord on the right is the default C++ dashboard that comes with the FRC Driver Station (still haven't worked out the difference between the Java and C++ versions).
Things I discovered along the way.
-
The LabVIEW Dashboard is a heart breaker. It's by far the best looking of any of the SmartDashboards I've looked at and has panels and controls for all the things I needed. But I couldn't work out how to do things like set options for the autonomous chooser or add commands to the table in the command tab. I did have a quick look at the LabVIEW source for the SmartDashboard but wasn't able to work it out. I'd originally assumed that calling the SmartDashboard methods from the C++ program would add items to the LV Dashboard but in the end all I could get working was changing a few label names. I'm assuming either something's broken or the LV SmartDashboard is a shell application that needs to be enhanced with LabVIEW to add the extra options to the controls.
-
The link between the robot programs running on the roboRio and the SmartDashboard applications is NetworkTables. It's obvious when you know but the documentation generally makes the assumption that readers already grasp this mechanism. NetworkTables can be thought of as an ephemeral key-value store that exists between two or more programs. Or more simply put a shared key-value store that disappears once the last program using it exits (not quite true given some key-values can be saved to a file on the roboRio but close enough).
-
The mechanism the SmartDashboard uses to inform the roboRio robot program command to execute a command is to set "running" to "true". I'd initially thought it would be more complicated and involve co-coordinating command ID's back and forth or something but instead it's as simple as setting a single NetworkTables key-value field to "true" and then back to "false" to cancel the command, it will be set to "false" automatically when the command finishes. The "running" key is defined in Command.cpp.
-
The OutlineViewer Java application is very handy for monitoring NetworkTables. The OutlineViewer .jar file is located in the tools directory of the wpilib download (which I currently can't find the link for).
-
There are a LOT of SmartDashboard options out there. Unfortunately at this stage they all seem to be "cutting edge" and take some effort to build, understand and use. Ideally the default LabVIEW Dashboard would just work for basic scenarios but that aside it's likely one of the new dashboards on the block will become the defacto in the next year or two provided the FRC software suite doesn't undergo anything too radical.
Default options included with FRC Software Distribution:
Others: