C++ Dashboard Usage

After some recent questions regarding getting a dashboard connected to C++ code, I decided to share the class that we used this year to interface to our dashboard and the way we used it. Our version had more than 100 data members, so the attached example is much more simplified, but it should give a good starting point for people looking to use the dashboard.

The attached zip file contains the following
WsRobot.h - A very simple robot definition that includes a WsDashboard object

WsRobot.cpp - The implementation of the robot. It has a very simple, rather useless TeleopPeriodic function. Values are read from Joystick 1 and internal variables based on those values are then written to the dashboard object.

WsDashboard.h - Contains a class that abstracts the WPILib Dashboard class. Data type classes are also defined here.

WsDashboard.cpp - The implementation of the dashboard class. It defines what pieces of data are to be sent to the dashboard as well as what data type each element is.

In the Dashboard directory, the DashboardMain.vi file is a stripped down version of the dashboard that we used this year, which was based on the dashboard example provided with Labview. I included a few supporting VI files that came from the example that handle the communication protocols.

Focusing on the C++ side first, the code should be fairly straight forward, but here are a few general comments.

We chose this approach because early on when we were experimenting we found that we were constantly adding new data elements. We wanted to make this data addition as easy as possible, so we designed the classes to be as flexible as possible.

We found that we only needed 3 data types (float, bool, UINT32). If a different data type is needed (must be supported by WPILib Dashboard class), the following should be done:

  • Add it to the DashboardDataType enum
  • Create a new class based on DashboardDataBase to handle the setting/getting/resetting of the data.
  • Add a mapping in WsDashboard::update()

When adding a new parameter, the following is done

  • Add an index to the DashboardIndexT enum
  • Instantiate the index with the correct data type in WsDashboard::WsDashboard
  • Set the value where needed (in our case WsRobot.cpp)

On the LabView side of things, we simply took the example and stripped out their processing and added our own. The key to the whole process is the packet parsing which is done via the data structure on the far left. The order that the data is packed on the C++ side must match the order that the elements are in the LabView data container. Once the data packet format is set up, it’s as easy as adding the necessary processing on the right side of the diagram. You can make it as simple or complex as you’d like.

Hopefully this will give programmers that are intimidated by the dashboard a good point to jump in from.

As a disclaimer, the code in the zip file is copied from the production code for our 2009 robot, but has been stripped down. Same goes for the LabView diagram. While I have compiled the C++ code, I haven’t tested it on a robot. If you come across problems let me know and I can put out an update.

If you have questions, I’ll do what I can to answer them.

Enjoy.

DashboardExample.zip (106 KB)


DashboardExample.zip (106 KB)

I realized that there may be people here that are interested in seeing the labview side of things that don’t have immediate access to it. I’ve attached a screenshot of both the front and back end diagrams.