Skip to content

FlashLib in FRC

Tom Tzook edited this page Oct 9, 2017 · 14 revisions

This wiki page is still a work in progress

From the start, FlashLib was meant to support FRC teams, but was never intended to replace WPILib. We wanted to provided an extended and more enhanced support and development enviornment allowing users to easily create advanced algorithms and robots.

FlashLib was built with the concept of abstraction, allowing user to use it anywhere including in FRC. We already provided implementations of the library for FRC, but it is still possible to provide custom implementations.

WPILib Integration

To allow teams to use both WPILib and FlashLib, we designed the library to function in individual parts, so that it is possible to use only a part of FlashLib. That means that systems provided by both libraries won't intersect, but rather allow users to choose which of the two they wish to use.

Systems like the Robot Scheduling System and the Communication Management System are available in both libraries with different implementations, each with its own advantages and disadvantages. It is advised to try each of the systems in order to decide which is preferable for you.

There are 2 basic types of initializations of FlashLib for FRC:

  • Full: When using the full version of FlashLib, all FRC features are available and certain WPILib systems are replaced. This is the prefered mode when you wish to take full advantage of FlashLib. But the WPILib scheduling system should not be used.
  • Limited: When using the limited version of FlashLib, it is necessary to manually initialize wanted features in FlashLib. This allows the possible to choose what to initialize. This is the prefered mode for those who prefer WPILib bu want several tools from FlashLib.

IO

FlashLib does not provide any input-output capabilities with electronic components for the RoboRIO, meaning it is still necessary to use WPILib. However, to allow integration with motion algorithms and systems in FlashLib, wrappers are available. Use those wrapper if you wish to take advantage of built-in algorithms and systems.

Dashboard

Both FlashLib and WPILib provide dashboard for operators: Flashboard and SmartDashboard respectively. When initializing FlashLib, it is possible to select whether you wish to use Flashboard. So it is very simple to decide which dashboard you wish to use, but using both is always possible.

Communications

While FlashLib provides the Communication Management System, WPILib has its NetworkTables. The two do not intersect which means they both can be used at the same time. It is even possible to convert FlashLib Sendables to WPILib Tables.

Scheduler

When initializing FlashLib, it is possible to decide whether to use the Scheduling system. Since systems from both libraries provide similar service, choosing which is based on comfort and performance. Although it is possible to convert between Action and Command, convering between Subsystem in FlashLib and Subsystem in WPILib cannot be done. Using both Schedulers is not a advisable and you should choose which is better for you before starting to write your program.

Using FlashLib with FRC Java Project

Using FlashLib in an FRC Java Project is very simple and there can be several ways to do so.

Preperations

First it is required to build the library (or use downloaded binaries) and copy flashlib.jar to the wpilib user libraries folder under {your.user}/wpilib/user/java/lib. Once there, FlashLib will be automatically imported when a new project is created and automatically deployed to the RoboRIO with the robot project.

To update flashlib, simply replace the jar file in the lib folder with the new jar file. You may need to refresh your projects for the changes to take place, if so: right click on each project and press refresh.

Sources and Javadoc

When built, FlashLib generates a sources jar (flashlib-sources.jar) and a Javadoc jar (flashlib-javadoc.jar). To have access to each when creating you robot code, it is necessary to set them up in Eclipse.

To start, create a flashlib folder under {your.user}/wpilib/user/java/. Place both jar files in this folder. Using this will allow to easily update the files if necessary.

We will need to link those jars to our flashlib library in Eclipse.

First, we need to create a classpath variable to the folder we just created:

  • Now open Eclipse, go to Window -> Preferences.
  • Go to Java -> Build Path -> Classpath Variables.
  • Click New.
  • Choose an appropriate name, like flashlib and set it in the name field
  • Click on Folder and navigate to flashlib folder we created and click OK.
  • Click OK on the variable creation window.
  • Click Apply or Apply and Close and close the preferences window if necessary.

Now we need to link the files:

  • Go to an FRC robot project in your Package Explorer, or create one if necessary.
  • Expand Referenced Libraries.
  • Find the FlashLib entry under it and right-click -> Properties.
  • Go to Java Source Attachment
  • Click on Variable and choose the classpath variable we just created
  • Click on Extension and choose the sources jar.
  • Click on Apply
  • Go to Javadoc Location
  • Choose Javadoc in archive
  • Click on Browse and navigate to the Javadoc jar.
  • Click on Validate. A window will popup, if it says the location is most likely valid than you're good, otherwise you must have made a mistake. If so, Repeat the steps from the start to make sure everything is okay.
  • Click on Apply.
  • Close the window.

Now you have linked the javadoc and sources files to the library and can view sources and documentation. You may need to refresh your projects for the changes to take place, if so: right click on each project and press refresh.

Choosing Appropriate Project

There are many ways to use FlashLib with your robot project, so before creating the project, it is necessary to choose how you want to use FlashLib.

Full FlashLib Usage

To fully use FlashLib, ignoring most WPILib features, follow the next steps:

  • Create a Sample Robot Project
  • Delete the contents of the created Robot class
  • Extend IterativeFRCRobot instead of SampleRobot

IterativeFRCRobot provides the recommended base for FRC robots using FlashLib's robot framework. This base provides a similar robot loop to WPILib's IterativeRobot and FlashLib's IterativeRobot.

The control loop divides each operation mode into two types

  • init: initialization of the operation mode
  • periodic: execution of the operation mode

init is called every time the robot enters a new mode. periodic is called every ~10ms while the robot is in the operation mode.

When extending this class, it is necessary to implement:

  • initRobot: initialization of robot systems
  • disabledInit: initialization for disabled mode
  • disabledPeriodic: execution of disabled mode
  • autonomousInit: initialization for autonomous operation mode
  • autonomousPeriodic: execution of a autonomous operation mode
  • teleopInit: initialization for teleop operation mode
  • teleopPeriodic: execution of a teleop operation mode

initRobot is called after FlashLib systems finished initialization and are ready to be used. Use this to initialize robot systems. testInit and testPeriodic are provided for FRC's test mode. They have a default empty implementation and can be overridden if necessary.

This class provides custom initialization. When the robot is initializing, preInit is called for custom initialization. The passed object, RobotInitializer provides variables whose values are used to initialize FlashLib and control loop operations.

FlashLib's scheduling system is updated by the control loop to allow operation of that system. While the robot is operational, the scheduler is operational, insuring correct operation of that system. When operation modes change, all Action objects are interrupted so that unwanted execution will not remain and cause issues. In addition, when in disabled mode the scheduling enters tasks only mode, so Action objects are not executed, but Runnable objects are.

IterativeFRCRobot provides a power tracking feature, allowing users to log problems with the robot's power supply if necessary. If enabled, the PDP is checked periodically and data is logged into a power log if needed. This data includes a voltage drop bellow a certain level or current draw above a certain level.

For examples on using IterativeFRCRobot please refer to the examples folder.