2018 FRC Control System

Creating a custom control using FXML

sfx comes with a palette of built-in controls that feature a wide range of use cases. But sometimes you would like to further customize your robot dashboard with controls that you create yourself. There are two strategies for creating custom controls, either:

FXML - a XML-based markup language for describing your own controls using a declarative language without needing programming

Java-based controls can have more complex requirements and behaviors

In this lesson we'll look at creating FXML-based controls. For creating Java controls, see the Java tutorial.

Creating a pneumatic piston position indicator using FXML

Suppose you need to display the position of a pneumatic piston to make it clear to the operators the state of the piston. Ideally you would draw the piston and show the piston rod either in or out of the case. Showing it graphically might be much clearer than just having an indicator that was either red or green. FXML allows you to create more complex drawings and animate them based on, in this case, a boolean value. The illustration above shows the piston in the in and out position.

In this example we use a 2x3 grid pane to model the piston. When it is extended, the left middle cell contains a light grey panel that is visible. When it is retracted, that panel is hidden.

Creating the FXML file

FXML is a declarative markup language for describing the graphical properties of your widget. It lets you specify values for shape, color, position or other properties to describe your widget.

FXML controls have the following structure:

Header

Base

UI & Bindings

The header is made of the XML header and JVM imports to avoid fully qualifying all nodes

This contains normal FXML and was built with the JavaFX Scene Builder. Note the first pane's visibility property is bound to the base's value, thus enabling the piston to appear retracted when the value is false, and extended when true. This is all the FXML needed to define this control.

Registering your control with a manifest

To add your control to the dashboard, you need to package it in a plugin. For FXML controls you can simply put it in a folder or pack it in a jar. Either way, we need a manifest file that describes what the plugin contains. Manifests are written in YAML and can contain multiple controls and other options. For our needs, we will start with this file (please generate your own UUID. uuidgenerator.net is where the provided UUID was generated)

0
Report Errors

Use this form to report any errors with the documentation. For help with WPILib, please use the FIRST Forums at http://forums.usfirst.org For reporting WPILib bugs, please submit an issue on GitHub at https://github.com/wpilibsuite/allwpilib/issues/new