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

项目:FRCStronghold2016    文件:CustomGyro.java   
/**
 * Initialize the gyro. Calibration is handled by calibrate().
 */
public void initGyro() {
  result = new AccumulatorResult();

  m_voltsPerDegreePerSecond = kDefaultVoltsPerDegreePerSecond;
  m_analog.setAverageBits(kAverageBits);
  m_analog.setOversampleBits(kOversampleBits);
  double sampleRate = kSamplesPerSecond * (1 << (kAverageBits + kOversampleBits));
  AnalogInput.setGlobalSampleRate(sampleRate);
  Timer.delay(0.1);

  setDeadband(0.0);

  setPIDSourceType(PIDSourceType.kDisplacement);

  UsageReporting.report(tResourceType.kResourceType_Gyro, m_analog.getChannel());
  LiveWindow.addSensor("AnalogGyro", m_analog.getChannel(), this);
}
项目:CMonster2015    文件:AnalogGyro.java   
/**
 * Gyro constructor with a precreated analog channel object. Use this
 * constructor when the analog channel needs to be shared.
 *
 * @param channel The AnalogInput object that the gyro is connected to.
 *            Analog gyros can only be used on on-board channels 0-1.
 */
public AnalogGyro(AnalogInput channel) {
    analogInput = channel;
    if (analogInput == null) {
        throw new NullPointerException("AnalogInput supplied to AnalogGyro constructor is null");
    }
    result = new AccumulatorResult();

    analogInput.setAverageBits(DEFAULT_AVERAGE_BITS);
    analogInput.setOversampleBits(DEFAULT_OVERSAMPLE_BITS);
    updateSampleRate();

    analogInput.initAccumulator();

    UsageReporting.report(tResourceType.kResourceType_Gyro, analogInput.getChannel(), 0,
            "Custom more flexible implementation");
    LiveWindow.addSensor("Analog Gyro", analogInput.getChannel(), this);

    calibrate(DEFAULT_CALIBRATION_TIME);
}
项目:2014_Main_Robot    文件:FalconGyro.java   
/**
 * Initialize the gyro. Calibrate the gyro by running for a number of
 * samples and computing the center value for this part. Then use the center
 * value as the Accumulator center value for subsequent measurements. It's
 * important to make sure that the robot is not moving while the centering
 * calculations are in progress, this is typically done when the robot is
 * first turned on while it's sitting at rest before the competition starts.
 */
private void initGyro() {
    result = new AccumulatorResult();
    if (m_analog == null) {
        System.out.println("Null m_analog");
    }
    m_voltsPerDegreePerSecond = kDefaultVoltsPerDegreePerSecond;
    m_analog.setAverageBits(kAverageBits);
    m_analog.setOversampleBits(kOversampleBits);
    double sampleRate = kSamplesPerSecond
            * (1 << (kAverageBits + kOversampleBits));
    m_analog.getModule().setSampleRate(sampleRate);

    Timer.delay(1.0);

    reInitGyro();

    setPIDSourceParameter(PIDSourceParameter.kAngle);

    UsageReporting.report(UsageReporting.kResourceType_Gyro,
            m_analog.getChannel(), m_analog.getModuleNumber() - 1);
    LiveWindow.addSensor("Gyro", m_analog.getModuleNumber(),
            m_analog.getChannel(), this);
}
项目:HolonomicDrive    文件:HVAGyro.java   
/**
 * Initialize the gyro. Calibrate the gyro by running for a number of
 * samples and computing the center value. Then use the center value as the
 * Accumulator center value for subsequent measurements. It's important to
 * make sure that the robot is not moving while the centering calculations
 * are in progress, this is typically done when the robot is first turned on
 * while it's sitting at rest before the competition starts.
 */
public void initGyro()
{
    result = new AccumulatorResult();

    if (m_analog == null)
    {
        System.out.println("Null m_analog");
    }

    m_voltsPerDegreePerSecond = kDefaultVoltsPerDegreePerSecond;
    m_analog.setAverageBits(kAverageBits);
    m_analog.setOversampleBits(kOversampleBits);

    double sampleRate = kSamplesPerSecond * (1 << (kAverageBits + kOversampleBits));

    AnalogInput.setGlobalSampleRate(sampleRate);
    Timer.delay(1.0);

    m_analog.initAccumulator();
    m_analog.resetAccumulator();

    // allow time for the Gyro run through the calibration
    Timer.delay(kCalibrationSampleTime);

    // read the accumulated value and the number of samples
    m_analog.getAccumulatorOutput(result);

    // the gyro center is the average of the accumulated counts, while if offset
    // is the fraction from the center (decimal)
    m_center = (int) ((double) result.value / (double) result.count + 0.5);
    m_offset =       ((double) result.value / (double) result.count) - m_center;

    m_center = Constants.GYRO_CENTER;
    m_offset = 0.0;

    // set the gyro center (integer) for the integration
    m_analog.setAccumulatorCenter(m_center);
    m_analog.resetAccumulator();

    // dead band will decrease drift at the cost of decreasing accuracy
    setDeadband(0.0);

    // set the PID source
    setPIDSourceParameter(PIDSourceParameter.kAngle);

    UsageReporting.report(tResourceType.kResourceType_Gyro, m_analog.getChannel());

    LiveWindow.addSensor("HVAGyro", m_analog.getChannel(), this);
    SmartDashboard.putNumber("m_center", m_center);
}
项目:frc-2013-offseason    文件:SuperGyro.java   
/**
 * Initialize the gyro.
 * Calibrate the gyro by running for a number of samples and computing the center value for this
 * part. Then use the center value as the Accumulator center value for subsequent measurements.
 * It's important to make sure that the robot is not moving while the centering calculations are
 * in progress, this is typically done when the robot is first turned on while it's sitting at
 * rest before the competition starts.
 */
private void initGyro() {
    result = new AccumulatorResult();

    channel.setAverageBits(kAverageBits);
    channel.setOversampleBits(kOversampleBits);
    double sampleRate = kSamplesPerSecond * (1 << (kAverageBits + kOversampleBits));
    channel.getModule().setSampleRate(sampleRate);

    Timer.delay(1.0);
    channel.initAccumulator();

    Timer.delay(kCalibrationSampleTime);

    channel.getAccumulatorOutput(result);

    int center = (int) ((double)result.value / (double)result.count + .5);

    voltageOffset = ((double)result.value / (double)result.count) - (double)center;

    channel.setAccumulatorCenter(center);

    channel.setAccumulatorDeadband(0); ///< TODO: compute / parameterize this
    channel.resetAccumulator();
}
项目:FRC2013    文件:SuperGyro.java   
/**
 * Initialize the gyro.
 * Calibrate the gyro by running for a number of samples and computing the center value for this
 * part. Then use the center value as the Accumulator center value for subsequent measurements.
 * It's important to make sure that the robot is not moving while the centering calculations are
 * in progress, this is typically done when the robot is first turned on while it's sitting at
 * rest before the competition starts.
 */
private void initGyro() {
    result = new AccumulatorResult();

    channel.setAverageBits(kAverageBits);
    channel.setOversampleBits(kOversampleBits);
    double sampleRate = kSamplesPerSecond * (1 << (kAverageBits + kOversampleBits));
    channel.getModule().setSampleRate(sampleRate);

    Timer.delay(1.0);
    channel.initAccumulator();

    Timer.delay(kCalibrationSampleTime);

    channel.getAccumulatorOutput(result);

    int center = (int) ((double)result.value / (double)result.count + .5);

    voltageOffset = ((double)result.value / (double)result.count) - (double)center;

    channel.setAccumulatorCenter(center);

    channel.setAccumulatorDeadband(0); ///< TODO: compute / parameterize this
    channel.resetAccumulator();
}