Elastic Documentation
DownloadGitHub Repository
  • Home
  • Getting Started
    • Installation
    • App Navigation
    • Connecting To Your Robot
  • Customizing your Dashboard
    • Adding and Customizing Widgets
    • Adding and Customizing Layouts
  • Additional Features and References
    • Widgets List & Properties Reference
    • ElasticLib
    • Remote Layout Downloading
    • Custom Widget Examples
    • Shuffleboard API
  • Legal
    • Open Source License
    • Privacy Policy
Powered by GitBook
On this page
  • Installing ElasticLib
  • Robot Notifications
  • Creating a Notification
  • Sending a notification
  • Customizing a Notification
  • Tab Switching
Edit on GitHub
  1. Additional Features and References

ElasticLib

PreviousWidgets List & Properties ReferenceNextRemote Layout Downloading

Last updated 3 months ago

Installing ElasticLib

For Java projects, copy this file into your robot project:

If you are using C++, you will have to copy these 2 files instead:

For Python projects, you will have to copy this file:

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.

Robot Notifications

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.

Creating a Notification

Notification data is stored in an object called Notification. Currently, this has the following properties:

  • level for the type of notification

  • title for the notification title

  • description for the notification text

  • width 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:

  1. Error

  2. Warning

  3. Info

An example of a Notification for an error notification would be

Elastic.Notification notification = new Elastic.Notification(Elastic.Notification.NotificationLevel.ERROR, "Error Notification", "This is an example error notification.");
elastic::Notification notification = {.level = elastic::NotificationLevel::ERROR, .title = "Error Notification", .description = "This is an example error notification"};
notification = Notification(level=NotificationLevel.ERROR, title="Error Notification", description="This is an example error notification")

Sending a notification

In order to send a notification, there is a method called sendNotificationin the Elastic class to send a Notification.

To send the error notification that was declared above, you would call

Elastic.sendNotification(notification);
elastic::SendNotification(notification);
send_notification(notification)

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.

/* code that created the notification */
notification.setLevel(NotificationLevel.WARNING);
notification.setTitle("Warning Notification");
notification.setDescription("This is an example warning notification");
/* code that created the notification */
notification.level = elastic::NotificationLevel::WARNING;
notification.title = "Warning Notification";
notification.description = "This is an example warning notification";
# code that created the notification
notification.level = NotificationLevel.WARNING
notification.title = "Warning Notification"
notification.description = "This is an example warning notification"

Customizing with Method Chaining (Java Only)

For example, here's how a notification can be entirely customized and sent with just one line of code.

Elastic.Notification notification = new Elastic.Notification();

/* ... */

Elastic.sendNotification(notification
    .withLevel(Elastic.NotificationLevel.INFO)
    .withTitle("Some Information")
    .withDescription("Your robot is doing fantastic!")
    .withDisplaySeconds(5.0)
);

Tab Switching

ElasticLib has functions to request the dashboard to switch the tab remotely.

To switch to a tab, use the selectTabmethod

Elastic.selectTab("Example Tab");
elastic::SelectTab("Example Tab");
select_tab("Example Tab")

Additionally, you can also select a tab at a specific index (with index 0 being the first tab). To do this, pass an integer into the selectTab method, for Python, use the select_tab_index method.

// Select the tab at index 3 (the 4th tab)
Elastic.selectTab(3);
// Select the tab at index 3 (the 4th tab)
elastic::SelectTab(3);
# Select the tab at index 3 (the 4th tab)
select_tab_index(3)

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 for more details)

https://github.com/Gold872/elastic-dashboard/blob/main/elasticlib/Elastic.java
https://github.com/Gold872/elastic-dashboard/blob/main/elasticlib/elasticlib.h
https://github.com/Gold872/elastic-dashboard/blob/main/elasticlib/elasticlib.cpp
https://github.com/Gold872/elastic-dashboard/blob/main/elasticlib/elasticlib.py
WPILib docs
Error Notification