Skip to content

FlashLib in FRC

Tom Tzook edited this page Sep 19, 2017 · 14 revisions

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.

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.

User wishing for a simpler base for a FRC robots, can extend the SimpleIterativeFRCRobot class instead. This base doesn't provide customized initialization or power logging like IterativeFRCRobot and has only a simple robot loop. FlashLib is initialized for basic FRC usage, meaning that Flashboard isn't initialized. Users can initialize it manually if they wish.