AvalancheRobotics / Avalanche-X

Code for ?
0 stars 0 forks source link

Stories in Ready Codacy grade

Swerve Robotics FTC Library

Welcome to the Swerve Robotics library for the FTC robot controller runtime. The purpose of our library is to augment the robot controller runtime library from FTC HQ in order to simplify programming for FTC teams. The central aim here is not to change what's there, just to make it better. The library is a drop-in replacement: if your code works with the FTC HQ release, it will work with the Swerve library, but you can also take advantage of new things. Please consult the GitHub release notes for details regarding a given release. You might also want to check out our related project, the Swerve Robotics Tools Suite, also here on GitHub.

Notable features of the Swerve Robotics FTC Library include the following. Note: the 'Easy' controllers are now part of the core SDK. The functionality is as described here, but they are now always in use, irrespective of the flavor of opmode.

Easy Legacy Motor Controller

EasyLegacyMotorController is a replacement for the stock DCMotorController implementation used with legacy HiTechnic motor controllers. EasyLegacyMotorController does away with the need to manually switch motors from read mode to write mode and back again and the attendant complex delay management, loop counting, or waiting for hardware cycles that that requires. Just call setPower(), getPosition(), or whatever other motor methods you need to use, and the right things happen under the covers.

Easy Modern Motor & Servo Controller and Easy Legacy Servo Controller

In a conceptually similar way, alternate implementations for modern motor and servo controllers and for legacy servo controllers is also provided. The API simplifications for these controllers are less dramatic than for the easy legacy motor controller, but are worthwhile nevertheless. Most importantly, reads and writes to these device now happen (virtually) when you issue them, and reads or writes that follow a write are sequenced after that write so as to preserve causality. This simplifies programming. Change a motor mode? Fine, it's changed: anything else you do on that motor will be sure to have seen the effect of that change. You don't have to poll to see whether the mode change has taken effect. Reset the encoders and then immediately change to run with encoders? Perfectly fine. It just works. Additionally, a handful of bug fixes is included. For example, Servo.getPosition() is now functionally useful.

Alternate OpMode Registration

The library has an alternate OpMode registration mechanism (the old FtcOpModeRegister.register() still works too) that allows you to register your own OpModes simply by decorating them with @TeleOp or @Autonomous annotations. This helps promote clean living and easier integration of library updates over time by avoiding editing code that lives in libraries owned by others. To register OpModes that aren't your own, a related annotation, @OpModeRegistrar, can be placed on a method in your code which is to be called as part of the registration process. Take a look at the YourCodeHere module for an example of how this works. We'd like to thank dmssargent for illustrating how this all might be technically accomplished.

SynchronousOpMode

The library contains a SynchronousOpMode class that brings back the synchronous, linear programming style with which teams have been familiar with from previous seasons in RobotC, and which is more amenable to teaching to beginning programmers than the event-driven / loop() callback programming model native to the robot controller runtime. SynchronousOpMode is similar to LinearOpMode but contains several enhancements, improved robustness, and several fixes. All hardware objects visible in SynchronousOpModes are thread-safe, in that they can be manipulated concurrently by multiple threads without internally becoming confused. SynchronousOpMode also gives you precise control of when changes in gamepad state are made visible to your program, allowing you to safely reason about a given state across a possibly complicated chain of logic. Information on writing in or migrating to SynchronousOpMode is found just below.

Enhanced Telemetry

The library contains an enhanced form of telemetry containing a dashboard and a log. On the driver station display, the dashboard appears at the top, followed by as many of the recent log messages as will reasonably fit. The dashboard can be preconfigured just once with unevaluated computations to form the lines on the dashboard, and / or the lines can be created dynamically with addData() calls as in the robot controller runtime. You call telemetry.update() to compose the current dashboard and transmit to the driver station. Only a subset of update() calls actually transmit, saving bandwith on the network and data acquistion time on the controller. Log messages can be written to the log at any time, and these are sent to the driver station as soon as possible. The enhanced telemetry class can be used both by synchronous and non-synchronous opmodes, but is used automatically in SynchronousOpModes.

Easy I2C Programming

The library (indeed, now the core SDK) contains an I2cDeviceSynch class that wraps I2cDevice instances and makes them easy to use by handling read-vs-write mode switches and attendant waits automatically and transparently. Just call read8() or write8() (and friends) to read and write device registers and the rest is taken care of. With the I2C register map you get from the sensor manufacturer in hand, it's now just dead easy to write your own code to talk to new I2C devices. I2cDeviceSynch can be used from any flavor of OpMode.

AdaFruit IMU Support

The library contains a class that is built on I2cDeviceSynch that provides a semantic interface to the Bosch BNO055 absolute position sensor, allowing teams to make easy use of the AdaFruit inertial motion unit (IMU) which incorporates that sensor module. Features of this sensor include a gyro that does rate integration in hardware to provide robust and accurate angular position indications, and a separation of the output of the accelerometer into gravity and linear-motion-induced components. The class builds on the latter to provide linear velocity and position measurements using integration in software. That said, the built-in accelerometer integration algorithm is quite naive. For a real robot, you'll want to do some investigation and reading and provide a better one, which you can specify in the initialization parameters for the IMU. Also, while the out-of-box sensor works remarkably well, Bosch describes a one-time calibration process (see Section 3.11) that will make it even better.

Enhanced Color Sensor

The library contains a alternate implemenation of HiTechnic and ModernRobotics color sensors that robustly implements the color sensor semeantics. In particular, the LED works reliably.

How To Use

The fifteen second summary of how to use SynchronousOpMode is as follows:

That's it! Autonomous OpModes are even simpler: just write what you want the robot to do after waitForStart().

Migrating from LinearOpMode to SyncronousOpMode is easy, usually simply involving

The Swerve Library now appears to be quite stable and functional. Our own teams are actively developing their competition code using it. It currently is synchronized to the beta release from FTC HQ that was published in March, 2016 (version 1.7).

Please be sure to update your driver station app to the latest-available version by side-loading the .APK from the doc\apk directory. Side loading can be accomplished by any of several means. See the ADB command 'install' command, for example (ADB is found in the Android SDK). Alternately, any of several PC applications (such as http://apkinstaller.com/) and Android APK Installer apps (found in the Play Store) can be used. The thread here (http://ftcforum.usfirst.org/showthread.php?6101-FTC-Beta-Branch&p=24750#post24750) might also be helpful.

Installing the Library

To use the library, we recommend forking or cloning our repository and working off of the 'master' branch. The Swerve Library repository includes the robot controller runtime repository from FTC HQ; you don't need both. While we do tag major milestones in the library and 'release' them, we try to keep the master branch always stable and fully functional, so you could reasonably sync to the latest available if you wished. Alternately, instead of forking or cloning, you can download a full copy of the source in .zip form from one of our releases. If you have previously forked the FTC HQ tree from https://github.com/ftctechnh/ftc_app and you are moderately git-savvy, you can easily upgrade to the Swerve Library by adding a new remote of https://github.com/SwerveRobotics/ftc_app to your git tree and initiating a pull from that remote. If that's greek to you, give us a ring, and we'll help you through it.

Documentation is available in the SwerveRoboticsLibrary/doc/javadoc directory. There are also several examples of using the library to be found in the 'examples' package.

We'd love to hear what you think about the library. Thanks!

Robert Atkinson,
bob@theatkinsons.org,
Mentor, Swerve Robotics,
Woodinville, Washington

(The remainder of this file is as published by FTC headquarters.)

ftc_app

FTC Android Studio project to create FTC Robot Controller app.

This is the FTC SDK that can be used to create an FTC Robot Controller app, with custom op modes. The FTC Robot Controller app is designed to work in conjunction with the FTC Driver Station app. The FTC Driver Station app is available through Google Play.

To use this SDK, download/clone the entire project to your local computer. Use Android Studio to import the folder ("Import project (Eclipse ADT, Gradle, etc.)").

Documentation for the FTC SDK are included with this repository. There is a subfolder called "doc" which contains several subfolders:

For technical questions regarding the SDK, please visit the FTC Technology forum:

http://ftcforum.usfirst.org/forumdisplay.php?156-FTC-Technology


Release 16.01.04


Release 15.11.04.001

T. Eng November 5, 2015


Release 15.10.06.002

T. Eng October 6, 2015


In this latest version of the FTC SDK (20150803_001) the following changes should be noted:

T. Eng August 3, 2015