FTC Programming Quick Start
Basic FTC Example: FTC Sample
In FTC, you can use Android Studio, OnBot Java, and Blockly to interact with your Limelight.
Most applications require less than 10 lines of code. Here's a quick overview of the process.
Basic Usage
- Initialize your Limelight3A using the same name that you used during the Control Hub Setup step.
- Call pipelineSwitch() to select one of the 10 pipelines you configured using the web interface
- Call start() to start background results polling at 100 polls per second.
public class Teleop extends LinearOpMode {
private Limelight3A limelight;
@Override
public void runOpMode() throws InterruptedException
{
limelight = hardwareMap.get(Limelight3A.class, "limelight");
telemetry.setMsTransmissionInterval(11);
limelight.pipelineSwitch(0);
/*
* Starts polling for data.
*/
limelight.start();
.
.
- Call getLatestResult() in your autonomous and teleop loops to get the latest LLResult object
- Utilize LLResult's getTx(), getTy(), and getBotpose() to guide your robot.
while (opModeIsActive()) {
LLResult result = limelight.getLatestResult();
if (result != null) {
if (result.isValid()) {
Pose3D botpose = result.getBotpose();
telemetry.addData("tx", result.getTx());
telemetry.addData("ty", result.getTy());
telemetry.addData("Botpose", botpose.toString());
.
.
Advanced Usage
- Advanced use-cases may call for the use of LLResult's getColorResults(), getFiducialResults(), etc.
// print some data for each detected target
if (result.isValid()) {
// Access fiducial results
List<LLResultTypes.FiducialResult> fiducialResults = result.getFiducialResults();
for (LLResultTypes.FiducialResult fr : fiducialResults) {
telemetry.addData("Fiducial", "ID: %d, Family: %s, X: %.2f, Y: %.2f", fr.getFiducialId(), fr.getFamily(),fr.getTargetXDegrees(), fr.getTargetYDegrees());
}
// Access color results
List<LLResultTypes.ColorResult> colorResults = result.getColorResults();
for (LLResultTypes.ColorResult cr : colorResults) {
telemetry.addData("Color", "X: %.2f, Y: %.2f", cr.getTargetXDegrees(), cr.getTargetYDegrees());
}
}
- For maximum 3D localization accuracy, call updateRobotOrientation() and use getBotPose_MT2(). MegaTag2 is an IMU-Fused robot localizer that utilizes the imu to solve the ambiguity problem which is fundamental to all planar targets such as AprilTags.
while (opModeIsActive()) {
YawPitchRollAngles orientation = imu.getRobotYawPitchRollAngles();
telemetry.addData("Yaw (Z)", "%.2f Deg. (Heading)", orientation.getYaw(AngleUnit.DEGREES));
limelight.updateRobotOrientation(orientation.getYaw(AngleUnit.DEGREES));
LLResult result = limelight.getLatestResult();
if (result != null) {
if (result.isValid()) {
Pose3D botpose = result.getBotpose_MT2();
.
.
For more information, see the FTC Programming page