Giter Club home page Giter Club logo

ftc-firebase-robotics's Introduction

ftc-firebase-robotics

Release

Receive real-time robotic telemetry data using Google Firebase pub/sub.

Gradle usage

Add a repository to your root build.gradle (The one called ftc-app):

allprojects {
    repositories {
        jcenter()
        flatDir {
            dirs 'out'
            mavenCentral()
            maven { url "https://jitpack.io" }
        }
    }
}

Add a dependency and exclude duplicate files to the FtcRobotController build.gradle file:

android {
    ...
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }
}

(At the bottom of the file)

dependencies {
    ...
    compile 'com.github.Jacobvs:ftc-firebase-robotics:1.0.1'
}

Code Example

For more detail check out the FirebaseExample.java file

import com.firebase.client.Firebase;
import org.athenian.ftc.ListenerAction;
import org.athenian.ftc.RobotValues;
import org.athenian.ftc.ValueListener;
import org.athenian.ftc.ValueSource;
import org.athenian.ftc.ValueWriter;

public class FirebaseTest extends OpMode {
 
    RobotValues robotValues = null;
 
    public FirebaseTest() {
    }
 
    @Override
    public void init() {
 
    firebaseInit();
    }
 
    @Override
    public void stop() {
    	// Stop 
        this.robotValues.stop();
    }
    
    public void firebaseInit(){
    final Firebase fb = new Firebase("https://9523-2015.firebaseio.com/");

        this.robotValues = new RobotValues(fb, 0.5);
        this.robotValues
            .add(new ValueWriter("motor.a",
                new ValueSource() {
                  @Override
                  public Object getValue() {
                    return motor.getCurrentPosition();
                  }}))
            .add(new ValueWriter("servo.a",
                new ValueSource() {
                  @Override
                  public Object getValue() {
                    return servo.getPosition();
                  }
                }))
            .add(new ValueWriter("sensor.distance.a",
                new ValueSource() {
                  @Override
                  public Object getValue() {
                    return distance.getLightDetected();
                  }}))
            .add(new ValueWriter("sensor.gyro.a",
                new ValueSource() {
                  @Override
                  public Object getValue() {
                    return String.format("The values are- Heading: %s, Rotation: %s, Raw x: %s, Raw y: %s, Raw z: %s",
                        gyro.getHeading(), gyro.getRotation(), gyro.rawX(), gyro.rawY(), gyro.rawZ());
                  }}))
            .add(new ValueWriter("sensor.color.a",
                new ValueSource() {
                  @Override
                  public Object getValue() {
                    return String.format("The values are- ARGB: %s, Alpha: %s, Red: %s, Green: %s, Blue: %s",
                        color.argb(), color.alpha(), color.red(), color.green(), color.blue());
                  }}))
            .add(new ValueListener("motor.a",
                new ListenerAction() {
                  @Override
                  public void onValueChanged(Object val) {
                    if (val != null) {
                      if (val instanceof Long) {
                        motor.setMode(DcMotorController.RunMode.RUN_TO_POSITION);
                        motor.setTargetPosition((Integer) val);
                        motor.setPower(0.5);
                        while(motor.isBusy()){
                        }
                        motor.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
                      } else {
                        telemetry.addData("IntegerException", val + " is not an Integer");
                      }
                    } else {
                      telemetry.addData("NullException", val + " is Null");
                    }
                  }
                }))
            .add(new ValueListener("servo.a",
                new ListenerAction() {
                  @Override
                  public void onValueChanged(Object val) {
                    if (val != null) {
                      if(val instanceof Long){
                        long lVal =  (Long) val;
                        if (lVal == 0 || lVal == 1 ){
                          servo.setPosition(lVal);
                        }
                      }
                      if(val instanceof Double){
                        double dVal = (Double) val;
                        if(dVal <= 0 && dVal >= 1){
                          servo.setPosition(dVal);
                        }
    
                      } else {
                        telemetry.addData("ValueException", val + " is not a Double or a Long");
                      }
                    } else {
                      telemetry.addData("NullException", val + " is Null");
                    }
                  }
                }))
        ;
    
        // Start
        this.robotValues.start();
    }
 }

ftc-firebase-robotics's People

Contributors

jacobvs avatar pambrose avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar Jackson avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.