Skip to content

Robot Development w FlashLib

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

This wiki page is still a work in progress

Do you need to create an amazing robot but want to do so quickly? Do you need a framework for you robot software so you won't have to create everything from scrach? Do you need your robot to do complicated tasks but don't know how?

If any of these are true (or any other reason...) you have come to the right place! FlashLib is not just a simle library, it provides a framework and a huge array of features and tools for any robot or just software in general.

To help you get start, we will be reviewing what you can do with FlashLib and how to use it to create your robot software. We assume that you do know a thing or two when jumping into this place, such as: what are motors, robots, sensors, etc.

Before we start, FRC programmers should refer to the FlashLib in FRC page to learn about using FlashLib with FRC robots because here we will be mostly discussing FlashLib for non-FRC robots.

FlashLib Features

FlashLib provides a lot of features for users, some can even be used for non-robot projects.

Robot Framework

The robot framework provides a base for running and controlling robots and managing operations on the robot with ease. In addition to that, users have access to control loops, algorithms and more, all of which is completely optional. So basically, it is possible to immediately jump into creating a software without worring about planning the robot control.

Robot Control

FlashLib uses a control loop for robot control. Users define control modes for their robot and the framework runs a continous loop which execute user code for the appropriate operation mode when necessary. Selecting operation modes depends on users, because there are many ways choose modes. So it is possible to set the mode from the robot, or an entirely different and remote software.

Task Scheduling

Most robots have multiple systems, each performing a different task at the same time, and controlling that from code can sometimes get messy. Because of that, FlashLib introduces a scheduling system which allows users to execute and schedule tasks for multiple robot systems quickly. Using the scheduling system allows for quick execution of a dozen different tasks, something that can be incredibly useful with autonomous robots.

Please refer to the Robot Scheduling System page for further information.

Human Interface Devices

Sometimes manual control is wanted for the robot, and this too, is already taken care of. FlashLib provides an HID package, filled with different types of controls and execution tasking. The actual retrival of HID data is abstracted, so users can read data from controllers however they like.

Actuators

There are tons of actuators available for robots, so FlashLib provides general implementations for controlling them. In addition, FlashLib provides an abstraction for actuator types, so it is very simple to integrate actuators into FlashLib systems.

Sensors

Like actuators, many sensors exist, so FlashLib integrates sensors using abstract control. That way, any sensor can be used alongside FlashLib. In addition, several sensors are already implemented in FlashLib.

Control Algorithms

FlashLib features several awesome control algorithms which provide control of popular drive systems, such as: tank drive, mecanum drive, etc; as well as autonomous motion algorthims for sensor-based operation.

PID

FlashLib provides a build-in PID controller, allowing users to control the robot's operation more relaibly. The controller itself is used in FlashLib's motion algorithms extensively.

Hardware Abstraction Layer

To allow users to code a robot once and use it on any platform, FlashLib introduces the Hardware Abstraction Layer. The HAL provides an abstract layer with changable implementations so that interacting with hardware and electronics would not require rewritting code. Note that because of the amount of platforms available, FlashLib cannot provide implementations for all of them, so users might have to implement their own hardware code.

You can read more about it in this wiki page.

Communications Library

Humans are considered social creatures and like them, robots need to communicate too. So when our robot software need to communicate with a remote software, we need to create something to send and receive data as well as manage the data accordingly. Instead of always needing to do so, FlashLib introduces the Communication Management System which allows users to communicate with remote softwares and easily manage incomming data on both sides.

Check out the systems wiki page for more information.

Vision Library

Image processing is awesome. It copies the power of the human eyesight and allows our robot to collect more data from its surroundings. But, for all its merits, it is extremely difficult to code. So FlashLib introduces the Dynamic Vision System which makes image processing a lot easier to execute and control.

You can read this wiki page for more information.

Flashboard

Manually controlling a robot can be difficult (from experience) and to perform certian tasks, operators need access to sensor information or visual data. So like car drivers, they need a dashboard. Flashboard is a smart dashboard software which provides that and more.

You can read all about it here.

Getting Started

Prepering the IDE

Before we can start creating our software, we need to add FlashLib to the development environment we are using. Start by downloading the latest FlashLib release binaries. You will find 3 files of interest:

  • flashlib.jar: The flashlib library. This JAR archive is the necessary file for using the library.
  • flashlib-sources.jar: The sources archive. Contains FlashLib source files and not necessary for using FlashLib, just recommanded.
  • flashlib-javadoc.jar: The Javadoc archive. Contains FlashLib Javadoc files and not necessary for using FlashLib, just recommanded.

We recommend creating a specific folder where FlashLib files will be placed, just for organization.

We now need to create a User Library in our IDE for FlashLib. This will allow us to easily use FlashLib in multiple projects. Depending on your IDE, this step will differ.

Eclipse

Intellij IDEA

NetBeans

Creating a Project

Now we can create a project for our robot. We can use a simple Java project, all we need is to import our FlashLib user library and create a main robot file.

Eclipse

Intellij IDEA

NetBeans

Creating the Main Robot Class

The project is ready for use, so now we need to create the main robot class. This class will be the center of our robot, here we will integrate all the robot systems and run everything. Create a package for the main class file, the name does not affect the robot, so choose an appropriate name. Then create a class file in the package (not with the main method), we recommend calling it Robot.

Eclipse

Intellij IDEA

NetBeans

Choosing a Robot Base

With the main robot class ready, all that we need to do is choose a base for our class which the main class will extend. A robot base contains the main method and is responsible for initialization of background operations and the robot operation loop.

RobotBase

RobotBase is the most basic base for robots. All other robots bases should extend this base. Here initialization and shutdown of the robot is handled. This class contains the robot's main method which should be called when starting the robot software. When the robot is started, the user implementation of this class is initialized, robot and FlashLib systems are initialized and user robot code is then started by calling robotMain(). When the JVM enters shutdown, this class uses a shutdown hook to perform ordered robot shutdown and will allow custom user shutdown by calling robotShutdown().

RobotBase has initialization parameters. To allow user customization, it is possible to override configInit(RobotInitializer) and customize initialization parameters. This method receives a RobotIntializer object which holds different variables, each affects initialization. This method has a default implementation that does nothing, so implement it only when custom initialization is wanted.

Using RobotBase is not recommended because it is very basic and doesn't provide a robot control loop. Instead, extend one of the following bases, each an extension of `RobotBase:

SimpleRobot

A simple robot base, provides a control loop which calls a method when entering an operation mode.

The control loop tracks operation mode data and calls user methods accordingly. When in disabled mode, disabled() is called and allows user operations in disabled mode. When in any other mode, onMode(int) is called and the current mode value is passed, allowing user operations for that mode. Those methods are called only once when in the operation mode. So if they finish execution before the mode is finished, not further user code will be executed for that mode. If mode was changed and user code did not finished and the methods did not return, this will disrupt robot operations.

This class provides extended custom initialization. When the robot is initializing, preInit(SimpleRobotInitializer) is called for custom initialization. The passed object, SimpleRobotInitializer is an extension of RobotInitializer which adds additional initialization options.

Before the control loop starts, robotInit() is called. In here initialization of robot systems should be done. When the robot enters shutdown mode robotFree() is called to allow user shutdown operations.

IterativeRobot

An extended robot base, provides a complex control loop with easier control over operations.

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 the robot enters disabled mode, disabledInit() is called at the beginning and them every ~10ms or so disabledPeriodic() is called. When in any other mode modeInit(int) is called and the mode value is passed and then every ~10ms or so modePeriodic(int) is called and the mode value is passed.

This class provides extended custom initialization. When the robot is initializing, preInit(IterativeRobotInitializer) is called for custom initialization. The passed object, IterativeRobotInitializer is an extension of RobotInitializer which adds additional initialization options.

Before the control loop starts, robotInit() is called. In here initialization of robot systems should be done. When the robot enters shutdown mode robotFree() is called to allow user shutdown operations.

While the control loop is running, FlashLib's scheduling system is active allowing usage of it. When in disabled the Scheduler runs only Runnable objects and when in other modes both Runnable and Action objects are executed. When the robot switches operation modes, all Action objects are interrupted and stop running.

In addition, the control loop uses the motor safety feature of FlashLib to insure correct motor operations.

Creating the Robot Code

After choosing the robot base, extend the class with you main robot class and implement all necessary methods. Now we can start working on the robot software.