Java 类edu.wpi.first.wpilibj.I2C 实例源码

项目:2016Robot    文件:AccelerometerSampling.java   
public void update(){

    // Shift all of the values to the left once
    for (int i = 0; i < numberOfSamples - 1; i++) {
        xValues[i] = xValues[i + 1];
        yValues[i] = yValues[i + 1];
        zValues[i] = zValues[i + 1];
    }

    // Update all of the values with accelerometer
    xValues[numberOfSamples - 1] = this.getX();
    yValues[numberOfSamples - 1] = this.getY();
    zValues[numberOfSamples - 1] = this.getZ();

    // If all of the latest values are 0, then the accelerometer crashed. DisablePID and stop the  shooter aim motor, then try to re-initialize it.
    if (xValues[numberOfSamples - 1] == 0 && yValues[numberOfSamples - 1] == 0 && zValues[numberOfSamples - 1] == 0) {

        Robot.shooterAim.disablePID();
        Robot.shooterAim.manualAim(0);

        accelerometer = new ADXL345_I2C(I2C.Port.kOnboard, Accelerometer.Range.k4G);

    }

}
项目:2015-frc-robot    文件:SensorInput.java   
/**
 * Instantiates the Sensor Input module to read all sensors connected to the roboRIO.
 */
private SensorInput() { 
    limit_left = new DigitalInput(ChiliConstants.left_limit);
    limit_right = new DigitalInput(ChiliConstants.right_limit);
    accel = new BuiltInAccelerometer(Accelerometer.Range.k2G);
    gyro = new Gyro(ChiliConstants.gyro_channel);
    pdp = new PowerDistributionPanel();
    left_encoder = new Encoder(ChiliConstants.left_encoder_channelA, ChiliConstants.left_encoder_channelB, false);
    right_encoder = new Encoder(ChiliConstants.right_encoder_channelA, ChiliConstants.right_encoder_channelB, true);
    gyro_i2c = new GyroITG3200(I2C.Port.kOnboard);

    gyro_i2c.initialize();
    gyro_i2c.reset();
    gyro.initGyro();

    left_encoder.setDistancePerPulse(ChiliConstants.kDistancePerPulse);
    right_encoder.setDistancePerPulse(ChiliConstants.kDistancePerPulse);
}
项目:robot2017    文件:Robot.java   
/**
 * Sends the current mode (auto, teleop, or disabled) over I2C.
 *
 * @param i2C  The I2C channel to send the data over.
 * @param mode The current mode, represented as a String.
 */
private void sendModeOverI2C(I2C i2C, String mode) {
    //If the I2C exists
    if (i2C != null) {
        //Turn the alliance and mode into a character array.
        char[] CharArray = (allianceString + "_" + mode).toCharArray();
        //Transfer the character array to a byte array.
        byte[] WriteData = new byte[CharArray.length];
        for (int i = 0; i < CharArray.length; i++) {
            WriteData[i] = (byte) CharArray[i];
        }
        //Send the byte array.
        i2C.transaction(WriteData, WriteData.length, null, 0);
    }
}
项目:R2017    文件:BNO055.java   
/**
 * Instantiates a new BNO055 class.
 *
 * @param port the physical port the sensor is plugged into on the roboRio
 * @param address the address the sensor is at (0x28 or 0x29)
 */
private BNO055(I2C.Port port, byte address) {
    imu = new I2C(port, address);

    executor = new java.util.Timer();
    executor.schedule(new BNO055UpdateTask(this), 0L, THREAD_PERIOD);
}
项目:R2017    文件:BNO055.java   
/**
 * Get an instance of the IMU object.
 * 
 * @param mode the operating mode to run the sensor in.
 * @param port the physical port the sensor is plugged into on the roboRio
 * @param address the address the sensor is at (0x28 or 0x29)
 * @return the instantiated BNO055 object
 */
public static BNO055 getInstance(opmode_t mode, vector_type_t vectorType,
        I2C.Port port, byte address) {
    if(instance == null) {
        instance = new BNO055(port, address);
    }
    requestedMode = mode;
    requestedVectorType = vectorType;
    return instance;
}
项目:CasseroleLib    文件:TCS34725ColorSensor.java   
/**
 * Constructor for TCS34725 Color Sensor from Adafruit. Initializes internal data structures and
 * opens I2C coms to the device.
 */
TCS34725ColorSensor() {
    color_sen = new I2C(Port.kOnboard, I2C_constants.TCS34725_I2C_ADDR);
    sensor_initalized = false;
    good_data_read = false;

}
项目:2016-Stronghold    文件:BNO055.java   
/**
 * Instantiates a new BNO055 class.
 *
 * @param port the physical port the sensor is plugged into on the roboRio
 * @param address the address the sensor is at (0x28 or 0x29)
 */
private BNO055(I2C.Port port, byte address) {
    imu = new I2C(port, address);
    this.initialized = false;
    this.state = 0;
    executor = new java.util.Timer();
    executor.schedule(new BNO055UpdateTask(this), 0L, THREAD_PERIOD);
}
项目:2016-Stronghold    文件:BNO055.java   
/**
 * Get an instance of the IMU object.
 *
 * @param mode the operating mode to run the sensor in.
 * @param port the physical port the sensor is plugged into on the roboRio
 * @param address the address the sensor is at (0x28 or 0x29)
 * @return the instantiated BNO055 object
 */
public static BNO055 getInstance(opmode_t mode, vector_type_t vectorType,
        I2C.Port port, byte address) {
    if (instance == null) {
        instance = new BNO055(port, address);
    }
    requestedMode = mode;
    return instance;
}
项目:FRC-2017    文件:RioDuinoAssembly.java   
public static void initialize() {
    if (!initialized)
    {
        i2cBus = new I2C(I2C.Port.kMXP, 4); 
        initialized = true;

        setTeamColor();
    }
}
项目:FRC-2017    文件:RioDuinoAssembly.java   
public static void initialize() {
    if (!initialized)
    {
        i2cBus = new I2C(I2C.Port.kMXP, 4); 
        initialized = true;

        setTeamColor();
    }
}
项目:FRC-2017    文件:RioDuinoAssembly.java   
public static void initialize() {
    if (!initialized)
    {
        i2cBus = new I2C(I2C.Port.kMXP, 4); 
        initialized = true;

        setTeamColor();
    }
}
项目:FRC-2017    文件:RioDuinoAssembly.java   
public static void initialize() {
    if (!initialized)
    {
        i2cBus = new I2C(I2C.Port.kMXP, 4); 
        initialized = true;

        setTeamColor();
    }
}
项目:FRC2017    文件:CompassReader.java   
public CompassReader(VariableStore variables)
{
    m_i2c = new I2C(I2C.Port.kOnboard, deviceAddress);
    m_i2c.write(2, 0);
    m_variables = variables;
    alpha = variables.GetDouble(compassAlphaVariableName, alphaOrig);
    beta = variables.GetDouble(compassBetaVariableName, betaOrig);
}
项目:FRCStronghold2016    文件:SparkfunGyro.java   
public SparkfunGyro() {
    mag = new I2C(I2C.Port.kOnboard, MAG_ADDR);
    gyro = new I2C(I2C.Port.kOnboard, AG_ADDR);

    buffer8[0] = 0;

    initGyro();

    //Bad startup values
    //readCount(20);

    //Calculate bias
    bias = readCount(30);
    bias /= 30;
}
项目:Frc2017FirstSteamWorks    文件:PixyVision.java   
public PixyVision(
    final String instanceName, Robot robot, int signature, int brightness, Orientation orientation,
    I2C.Port port, int i2cAddress)
{
    pixyCamera = new FrcPixyCam(instanceName, port, i2cAddress);
    commonInit(robot, signature, brightness, orientation);
}
项目:Frc2017FirstSteamWorks    文件:FrcPixyCam.java   
/**
 * Constructor: Create an instance of the object.
 *
 * @param instanceName specifies the instance name.
 * @param port specifies the I2C port on the RoboRIO.
 * @param devAddress specifies the I2C address of the device.
 */
public FrcPixyCam(final String instanceName, I2C.Port port, int devAddress)
{
    super(instanceName);

    if (debugEnabled)
    {
        dbgTrace = new TrcDbgTrace(moduleName + "." + instanceName, tracingEnabled, traceLevel, msgLevel);
    }

    pixyCam = new FrcI2cDevice(instanceName, port, devAddress);
    start();
}
项目:Frc2017FirstSteamWorks    文件:FrcI2cDevice.java   
/**
 * Constructor: Creates an instance of the object.
 *
 * @param instanceName specifies the instance name.
 * @param port specifies the I2C port the device is connected to.
 * @param devAddress specifies the address of the device on the I2C bus.
 */
public FrcI2cDevice(final String instanceName, Port port, int devAddress)
{
    super(instanceName);

    if (debugEnabled)
    {
        dbgTrace = new TrcDbgTrace(moduleName + "." + instanceName, tracingEnabled, traceLevel, msgLevel);
    }

    device = new I2C(port, devAddress);
}
项目:SparkFun6Dof    文件:ADXL345_I2C_SparkFun.java   
/**
 * Constructor.
 * @param port The I2C port the accelerometer is attached to
 * @param range The range (+ or -) that the accelerometer will measure.
 */
public ADXL345_I2C_SparkFun(I2C.Port port, Range range) {
    m_i2c = new I2C(port, kAddress);

    // Turn on the measurements
    m_i2c.write(kPowerCtlRegister, kPowerCtl_Measure);

    setRange(range);

    UsageReporting.report(tResourceType.kResourceType_ADXL345, tInstances.kADXL345_I2C);
    LiveWindow.addSensor("ADXL345_I2C", port.getValue(), this);
}
项目:SparkFun6Dof    文件:GyroITG3200.java   
/** Default constructor, uses default I2C address.
 * @see ITG3200_DEFAULT_ADDRESS
 */
public GyroITG3200( I2C.Port port )
{
    devAddr = ITG3200_DEFAULT_ADDRESS;

    m_i2c = new I2C(port, devAddr);

    // TODO: This report is incorrect.  Need to create instance for I2C ITG3200 Gyro
    //UsageReporting.report( tResourceType.kResourceType_I2C, tInstances.?? );
    LiveWindow.addSensor( "ITG3200_Gyro_I2C", port.getValue(), this );
}
项目:SparkFun6Dof    文件:GyroITG3200.java   
/** Specific address constructor.
 * @param address I2C address
 * @see ITG3200_DEFAULT_ADDRESS
 * @see ITG3200_ADDRESS_AD0_LOW
 * @see ITG3200_ADDRESS_AD0_HIGH
 */
public GyroITG3200( I2C.Port port, byte address )
{
    devAddr = address;

    m_i2c = new I2C( port, address );

    // TODO: This report is incorrect.  Need to create instance for I2C ITG3200 Gyro
    //UsageReporting.report( tResourceType.kResourceType_I2C, tInstances.?? );
    LiveWindow.addSensor( "ITG3200_Gyro_I2C", port.getValue(), this );
}
项目:BNO055_FRC    文件:BNO055.java   
/**
 * Instantiates a new BNO055 class.
 *
 * @param port the physical port the sensor is plugged into on the roboRio
 * @param address the address the sensor is at (0x28 or 0x29)
 */
private BNO055(I2C.Port port, byte address) {
    imu = new I2C(port, address);

    executor = new java.util.Timer();
    executor.schedule(new BNO055UpdateTask(this), 0L, THREAD_PERIOD);
}
项目:BNO055_FRC    文件:BNO055.java   
/**
 * Get an instance of the IMU object.
 * 
 * @param mode the operating mode to run the sensor in.
 * @param port the physical port the sensor is plugged into on the roboRio
 * @param address the address the sensor is at (0x28 or 0x29)
 * @return the instantiated BNO055 object
 */
public static BNO055 getInstance(opmode_t mode, vector_type_t vectorType,
        I2C.Port port, byte address) {
    if(instance == null) {
        instance = new BNO055(port, address);
    }
    requestedMode = mode;
    requestedVectorType = vectorType;
    return instance;
}
项目:turtleshell    文件:Robot.java   
private void setupSensors() {
    navX = new TurtleNavX(I2C.Port.kOnboard);
    try {
        lidar = new LIDARLite(I2C.Port.kMXP);
        // new LIDARSerial(SerialPort.Port.kUSB1);
    } catch (Exception e) {
        e.printStackTrace();
        lidar = new TurtleFakeDistanceEncoder();
    }

    pdp = new PowerDistributionPanel();
}
项目:turtleshell    文件:TurtleXtrinsicMagnetometer.java   
public TurtleXtrinsicMagnetometer(I2C.Port port, TurtleXtrinsicMagnetometerCalibration calib) {
    updateTimer = new java.util.Timer(true);
    i2c = new I2C(port, address);
    if (i2c == null) {
        System.err.println("Null m_i2c");
    }

    // check to see if the I2C connection is working correctly
    i2c.read(0x07, 1, buffer);
    System.out.println("WHO_AM_I: " + buffer[0]);
    if ((Byte.toUnsignedInt(buffer[0])) != 0xc4) {
        System.out.println("Something has gone terribly wrong.");

    } else {
        System.out.println("Found WHO_AM_I");
    }

    // settings for rate and measuring data
    i2c.write(0x10, 0b00011001);
    i2c.write(0x11, 0b10000000);

    // calibration (done in code, so set to 0)
    i2c.write(0x09, 0b00000000);
    i2c.write(0x0a, 0b00000000);
    i2c.write(0x0b, 0b00000000);
    i2c.write(0x0c, 0b00000000);
    i2c.write(0x0d, 0b00000000);
    i2c.write(0x0e, 0b00000000);

    this.setCalibration(calib);
    // initial update
    rateTimer.start();
    update();

    // Schedule the java.util.Timer to repeatedly update this sensor
    updateTimer.schedule(new TurtleXtrinsicMagnetometerUpdater(), UPDATETIME, UPDATETIME);
}
项目:turtleshell    文件:LIDARLite.java   
/**
 * Instantiates LIDARLite with given port and update speed
 * 
 * @param port
 * @param updateMillis
 */
public LIDARLite(I2C.Port port, long updateMillis) {
    sensor = new I2C(port, 0x62);

    Timer.delay(1.5);

    // sensor

    SmartDashboard.putBoolean("SensorAddress - false is success", sensor.addressOnly());

    // Configure Sensor. See
    // http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf

    sensor.write(0x02, 0x80); // Maximum number of acquisitions during
                                // measurement
    sensor.write(0x04, 0x08); // Acquisition mode control
    sensor.write(0x1c, 0x00); // Peak detection threshold bypass

    reset();

    new java.util.Timer().schedule(new TimerTask() {
        @Override
        public void run() {
            distance = measureDistance();
            velocity = measureVelocity();
            // System.out.println(distance.getInches()+"
            // "+velocity.getValue());
        }
    }, updateMillis, updateMillis);
}
项目:turtleshell    文件:LIDARSerial.java   
/**
 * Instantiates LIDARLite with given port and update speed
 * 
 * @param port
 * @param updateMillis
 */
public LIDARSerial(I2C.Port port, long updateMillis) {
    sensor = new I2C(port, 0x62);

    Timer.delay(1.5);

    // sensor

    SmartDashboard.putBoolean("SensorAddress", sensor.addressOnly());

    // Configure Sensor. See
    // http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf

    sensor.write(0x02, 0x80); // Maximum number of acquisitions during
                                // measurement
    sensor.write(0x04, 0x08); // Acquisition mode control
    sensor.write(0x1c, 0x00); // Peak detection threshold bypass

    reset();

    t = new java.util.Timer();
    t.schedule(new TimerTask() {
        @Override
        public void run() {
            distance = measureDistance();
            velocity = measureVelocity();
            // System.out.println(distance.getInches()+" "+velocity.getValue());
        }
    }, updateMillis, updateMillis);
}
项目:turtleshell    文件:TurtleXtrinsicMagnetometer.java   
/**
 * Magnetometer constructor, address is precoded. MAKE SURE TO CALIBRATE
 * BEFORE USING
 */
public TurtleXtrinsicMagnetometer(I2C.Port port) {
    i2c = new I2C(port, address);
    if (i2c == null) {
        System.out.println("Null m_i2c");
    }

    // check to see if the I2C connection is working correctly
    i2c.read(0x07, 1, buffer);
    System.out.println("WHO_AM_I: " + buffer[0]);
    if ((Byte.toUnsignedInt(buffer[0])) != 0xc4) {
        System.out.println("Something has gone terribly wrong.");

    } else {
        System.out.println("Found WHO_AM_I");
    }

    // settings for rate and measuring data
    i2c.write(0x10, 0b00011001);
    i2c.write(0x11, 0b10000000);

    // calibration (done in code, so set to 0)
    i2c.write(0x09, 0b00000000);
    i2c.write(0x0a, 0b00000000);
    i2c.write(0x0b, 0b00000000);
    i2c.write(0x0c, 0b00000000);
    i2c.write(0x0d, 0b00000000);
    i2c.write(0x0e, 0b00000000);

    this.setCalibration(this.generateCalibration());
    // initial update
    update();
    prevAngle = angle = 0;
    rateTimer.start();
}
项目:aerbot-champs    文件:AccelerometerSystem.java   
public void init(Environment environment) {
  accel = new ADXL345_I2C(RobotMap.ACCELEROMETER_PORT, ADXL345_I2C.DataFormat_Range.k4G);
  i2c = new I2C(DigitalModule.getInstance(1), DEVICE_ADDRESS);
  i2c.setCompatabilityMode(true);
  timer = new Timer();
  timer.start();
}
项目:Robotics2014    文件:GY85_I2C.java   
public void setupCompass() {
    if(clear){
        clear = false;
        cwrite = new I2C(DigitalModule.getInstance(1), 0x3C);
        cread = new I2C(DigitalModule.getInstance(1), 0x3D);

        cwrite.write(0, 88);
        cwrite.write(1, 64);
        cwrite.write(2, 0);
    }
    clear = true;
}
项目:Robotics2014    文件:GY85_I2C.java   
public void setupGyro() {
    if(clear){
        clear = false;
        gwrite = new I2C(DigitalModule.getInstance(1), 0xD1);
        gread = new I2C(DigitalModule.getInstance(1), 0xD0);

        gwrite.write(21, Wiring.SAMPLE_RATE);
        gwrite.write(22, 0x1A);
    }
    clear = true;
}
项目:Robotics2014    文件:GY85_I2C.java   
public void setupAccel() {
    if(clear){
        clear = false;
        awrite = new I2C(DigitalModule.getInstance(1), 0xA6);
        aread = new I2C(DigitalModule.getInstance(1), 0xA7);

        awrite.write(44, 0x0A);
        awrite.write(45, 0x08);
        awrite.write(49, 0x08);
    }
    clear = true;
}
项目:2015-frc-robot    文件:ADXL345_I2C_SparkFun.java   
/**
 * Constructor.
 * @param port The I2C port the accelerometer is attached to
 * @param range The range (+ or -) that the accelerometer will measure.
 */
public ADXL345_I2C_SparkFun(I2C.Port port, Range range) {
    m_i2c = new I2C(port, kAddress);

    // Turn on the measurements
    m_i2c.write(kPowerCtlRegister, kPowerCtl_Measure);

    setRange(range);

    UsageReporting.report(tResourceType.kResourceType_ADXL345, tInstances.kADXL345_I2C);
    LiveWindow.addSensor("ADXL345_I2C", port.getValue(), this);
}
项目:2015-frc-robot    文件:GyroITG3200.java   
/** Default constructor, uses default I2C address.
 * @see ITG3200_DEFAULT_ADDRESS
 */
public GyroITG3200( I2C.Port port )
{
    devAddr = ITG3200_DEFAULT_ADDRESS;

    m_i2c = new I2C(port, devAddr);

    // TODO: This report is incorrect.  Need to create instance for I2C ITG3200 Gyro
    //UsageReporting.report( tResourceType.kResourceType_I2C, tInstances.?? );
    LiveWindow.addSensor( "ITG3200_Gyro_I2C", port.getValue(), this );
}
项目:2015-frc-robot    文件:GyroITG3200.java   
/** Specific address constructor.
 * @param address I2C address
 * @see ITG3200_DEFAULT_ADDRESS
 * @see ITG3200_ADDRESS_AD0_LOW
 * @see ITG3200_ADDRESS_AD0_HIGH
 */
public GyroITG3200( I2C.Port port, byte address )
{
    devAddr = address;

    m_i2c = new I2C( port, address );

    // TODO: This report is incorrect.  Need to create instance for I2C ITG3200 Gyro
    //UsageReporting.report( tResourceType.kResourceType_I2C, tInstances.?? );
    LiveWindow.addSensor( "ITG3200_Gyro_I2C", port.getValue(), this );
}
项目:Robot_2017    文件:PixyI2C.java   
public PixyI2C() {
    pixy = new I2C(port, 0x54);//TODO: check number
    packets = new PixyPacket[7];
    pExc = new PixyException(print);
    values = new PixyPacket();
}
项目:MinuteMan    文件:S_Arduino.java   
private S_Arduino(){
    wire = new I2C(CoprocessorMap.ARDUINO_PORT, CoprocessorMap.ARDUINO_ADDRESS);
    verificationKey = "IronPatriots4135".getBytes();
}
项目:2017SteamBot2    文件:Arduino.java   
public Arduino(){
    i2c = new I2C(I2C.Port.kOnboard, 84);
    commands = new ArrayList<byte[]>();
}
项目:CasseroleLib    文件:pulsedLightLIDAR.java   
public pulsedLightLIDAR() {
    i2c = new I2C(Port.kMXP, LIDAR_ADDR);
    distance = new byte[2];
    updater = new java.util.Timer();
}
项目:Stronghold2016    文件:RegisterIO_I2C.java   
public RegisterIO_I2C( I2C i2c_port ) {
    port = i2c_port;
}
项目:FRC2017    文件:GyroReader.java   
public GyroReader()
{
    m_i2c = new I2C(I2C.Port.kOnboard, deviceAddress);
}