Skip to content

Programming

Driver Installation

You can find the Java driver for the SRSHub on our GitHub repository. Simply copy the file into your teamcode package, and you’re ready to use the SRS Hub in your codebase!

HardwareMap Configuration

Once you have added the java file to your teamcode package:

  • Upload your code to the REV Hub, in whatever way you typically do that (ADB, USB, etc.), so that the HardwareMap device options are updated to include the SRSHub.
  • Configure your HardwareMap: navigate to the control hub’s I2C device list in the HardwareMap configuration menu, and add the SRSHub to the correct port on the Control Hub, making sure to select SRSHub as the device type.

REV Hub Reading Configuration

To get the most performance, you should disable bulk reads on both the Control Hub and Expansion Hub using the below code:

List<LynxModule> hubs = hardwareMap.getAll(LynxModule.class);
LynxModule controlHub;
for (LynxModule hub : hubs) {
hub.setBulkCachingMode(LynxModule.BulkCachingMode.MANUAL);
if (hub.isParent() && LynxConstants.isEmbeddedSerialNumber(hub.getSerialNumber())) {
controlHub = hub;
}
}

The SRSHub should have enough ports for most teams, but if you find youself needing to read the control hub, you can run the below code at the end of the main loop:

controlHub.clearBulkCache();

Example Usage

Below is a sample OpMode that uses the SRSHub to read a variety of sensors:

HubExample.java
package org.firstinspires.ftc.teamcode.test;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import org.firstinspires.ftc.teamcode.devices.SRSHub;
@TeleOp(name = "HubExample")
public class HubExample extends LinearOpMode {
public void runOpMode() throws InterruptedException {
// All pins are configured to "None" by default
SRSHub.Config config = new SRSHub.Config();
config.setAnalogDigitalDevice(1, SRSHub.AnalogDigitalDevice.ANALOG);
config.setAnalogDigitalDevice(2, SRSHub.AnalogDigitalDevice.ANALOG);
config.setAnalogDigitalDevice(3, SRSHub.AnalogDigitalDevice.DIGITAL);
config.setEncoder(1, SRSHub.Encoder.PWM);
config.setEncoder(2, SRSHub.Encoder.QUADRATURE);
config.setEncoder(3, SRSHub.Encoder.QUADRATURE);
config.setEncoder(4, SRSHub.Encoder.PWM);
config.addI2CDevice(1, new SRSHub.VL53L5CX());
config.addI2CDevice(2, new SRSHub.APDS9151());
SRSHub hub = hardwareMap.get(SRSHub.class, "srshub");
// Runs I2C reads in a separate thread; threadUpdates defaults to false: hub.init(config) will not thread updates
hub.init(config, true);
waitForStart();
while (opModeIsActive() && !isStopRequested()) {
// if you are not theading updates, you must call hub.update() before reading
telemetry.addData("analog, a/d port 1", hub.readAnalogDigitalDevice(1));
telemetry.addData("analog, a/d port 2", hub.readAnalogDigitalDevice(2));
telemetry.addData("digital, a/d port 3", hub.readAnalogDigitalDevice(3));
telemetry.addData("pwm, encoder port 1", hub.readAnalogDigitalDevice(1));
telemetry.addData("quadrature, encoder port 2", hub.readAnalogDigitalDevice(2));
telemetry.addData("quadrature, encoder port 3", hub.readAnalogDigitalDevice(3));
telemetry.addData("pwm, encoder port 4", hub.readAnalogDigitalDevice(4));
// I2C reads are returned as a map because each sensor returns different data
for (String key : hub.readI2CDevice(1, SRSHub.VL53L5CX.class).keySet()) {
telemetry.addData("vl53l5cx, i2c bus 1, " + key, hub.readI2CDevice(1, SRSHub.VL53L5CX.class).get(key));
}
for (String key : hub.readI2CDevice(2, SRSHub.APDS9151.class).keySet()) {
telemetry.addData("apds9151, i2c bus 2, " + key, hub.readI2CDevice(2, SRSHub.APDS9151.class).get(key));
}
}
}
}