Robot Notifications with ElasticLib
Elastic supports sending notifications to the dashboard via robot code. This could be helpful in situations where you want to grab the attention of the user when something goes wrong or if there's an important warning to display.
Sending notifications via robot code requires the use of ElasticLib. Currently the only supported languages are Java and C++, but contributions for a Python port are open.
Installing ElasticLib
For Java projects, copy this file into your robot project: https://github.com/Gold872/elastic-dashboard/blob/main/elasticlib/Elastic.java
If you are using C++, you will have to copy these 2 files instead:
For Python projects, you will have to copy this file: https://github.com/Gold872/elastic-dashboard/blob/main/elasticlib/elasticlib.py
It is recommended to put this in a folder called util
, however any location within a robot project works. Depending on where the file is located, you may need to change the top line of the file.
Creating a Notification
Notification data is stored in an object called Notification
. Currently, this has the following properties:
level
for the type of notificationtitle
for the notification titledescription
for the notification textwidth
for the notification width (optional)height
for the notification height (optional)displayTimeMillis
for the time to show the notification in milliseconds (optional)
There are 3 notification levels:
Error
Warning
Info
An example of a Notification
for an error notification would be
Sending a notification
In order to send a notification, there is a method called sendNotification
in the Elastic
class to send a Notification
.
To send the error notification that was declared above, you would call
When this is called, a popup will appear on the dashboard that looks like this
Customizing a Notification
Notifications and their settings can be customized after being created, allowing them to be reused.
For example, the error notification created above can be customized into a warning notification.
Customizing with Method Chaining (Java Only)
For Java, method chaining is the simpler and recommended way to customize notifications. This allows for customizing multiple properties with just one line of code, as well as reusing only one notification object, which is better for the Java Garbage Collector performance (see WPILib docs for more details)
For example, here's how a notification can be entirely customized and sent with just one line of code.
Last updated