Skip to content

FlashLib in FRC

Tom Tzook edited this page Oct 1, 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.

Note that when using FlashLib with FRC robot, it is important to avoid the edu.flash3388.flashlib.robot.sbc package. This package was intended for non-FRC robots only. All FRC-only code can be found under edu.flash3388.flashlib.robot.frc.

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 is the base for an iterative robot fully using FlashLib. The base automatically initializes FlashLib according to given parameters and runs a control loop similar to IterativeRobot provided by WPILib. When extending this class you must implement the following methods:

  • preInit: This method is called before initializing FlashLib and receives an instance of RobotInitializer. This class holds variables which provide data about the initialization of FlashLib. A default empty implementation is provided for this method so implementing this method is a choice.
  • initRobot: called after FlashLib was initialized. Here you should initialize your robot and systems.
  • disabledInit: called when the control loop enters disabled mode. Use to initialize your robot systems to disabled mode.
  • disabledPeriodic: called while the robot is in disabled mode every ~10 ms after the scheduler has run.
  • teleopInit: called when the control loop enters teleop mode. Use to initialize your robot systems to teleop mode.
  • teleopPeriodic: called while the robot is in teleop mode every ~10 ms after the scheduler has run.
  • autonomousInit: called when the control loop enters autonomous mode. Use to initialize your robot systems to autonomous mode.
  • autonomousPeriodic: called while the robot is in autonomous mode every ~10 ms after the scheduler has run.
  • testInit: called when the control loop enters test mode. Use to initialize your robot systems to test mode. A default empty implementation is provided for this method so implementing this method is a choice.
  • testPeriodic: called while the robot is in test mode every ~10 ms after the scheduler has run. A default empty implementation is provided for this method so implementing this method is a choice.

Each time the robot loop has switched control mode (disabled, autonomous, teleop, test), the scheduler removes all Actions currently executing. An important feature of IterativeFRCRobot is power tracking. While running, the robot loop tracks the power status in the PDP. If the voltage is too low, the current draw is too high or a brownout is detected, data will be logged into a power log allowing users to track power issues. It is possible to set the voltage and current draw thresholds in preInit. It is also possible to set whether or not to track power problems in in preInit.

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