Java 类edu.wpi.first.wpilibj.communication.UsageReporting 实例源码

项目:Frc2016FirstStronghold    文件:SerialPort.java   
/**
 * Create an instance of a Serial Port class.
 *
 * @param baudRate The baud rate to configure the serial port.
 * @param port The Serial port to use
 * @param dataBits The number of data bits per transfer. Valid values are
 *        between 5 and 8 bits.
 * @param parity Select the type of parity checking to use.
 * @param stopBits The number of stop bits to use as defined by the enum
 *        StopBits.
 */
public SerialPort(final int baudRate, Port port, final int dataBits, Parity parity,
    StopBits stopBits) {
  m_port = (byte) port.getValue();

  SerialPortJNI.serialInitializePort(m_port);
  SerialPortJNI.serialSetBaudRate(m_port, baudRate);
  SerialPortJNI.serialSetDataBits(m_port, (byte) dataBits);
  SerialPortJNI.serialSetParity(m_port, (byte) parity.value);
  SerialPortJNI.serialSetStopBits(m_port, (byte) stopBits.value);

  // Set the default read buffer size to 1 to return bytes immediately
  setReadBufferSize(1);

  // Set the default timeout to 5 seconds.
  setTimeout(5.0f);

  // Don't wait until the buffer is full to transmit.
  setWriteBufferMode(WriteBufferMode.kFlushOnAccess);

  disableTermination();

  UsageReporting.report(tResourceType.kResourceType_SerialPort, 0);
}
项目:Frc2016FirstStronghold    文件:Counter.java   
private void initCounter(final Mode mode) {
  ByteBuffer index = ByteBuffer.allocateDirect(4);
  // set the byte order
  index.order(ByteOrder.LITTLE_ENDIAN);
  m_counter = CounterJNI.initializeCounter(mode.value, index.asIntBuffer());
  m_index = index.asIntBuffer().get(0);

  m_allocatedUpSource = false;
  m_allocatedDownSource = false;
  m_upSource = null;
  m_downSource = null;

  setMaxPeriod(.5);

  UsageReporting.report(tResourceType.kResourceType_Counter, m_index, mode.value);
}
项目:Frc2016FirstStronghold    文件:Jaguar.java   
/**
 * Common initialization code called by all constructors.
 */
private void initJaguar() {
  /*
   * Input profile defined by Luminary Micro.
   *$
   * Full reverse ranges from 0.671325ms to 0.6972211ms Proportional reverse
   * ranges from 0.6972211ms to 1.4482078ms Neutral ranges from 1.4482078ms to
   * 1.5517922ms Proportional forward ranges from 1.5517922ms to 2.3027789ms
   * Full forward ranges from 2.3027789ms to 2.328675ms
   */
  setBounds(2.31, 1.55, 1.507, 1.454, .697);
  setPeriodMultiplier(PeriodMultiplier.k1X);
  setRaw(m_centerPwm);
  setZeroLatch();

  UsageReporting.report(tResourceType.kResourceType_Jaguar, getChannel());
  LiveWindow.addActuator("Jaguar", getChannel(), this);
}
项目:Frc2016FirstStronghold    文件:ADXRS450_Gyro.java   
/**
 * Constructor.
 *
 * @param port The SPI port that the gyro is connected to
 */
public ADXRS450_Gyro(SPI.Port port) {
  m_spi = new SPI(port);
  m_spi.setClockRate(3000000);
  m_spi.setMSBFirst();
  m_spi.setSampleDataOnRising();
  m_spi.setClockActiveHigh();
  m_spi.setChipSelectActiveLow();

  // Validate the part ID
  if ((readRegister(kPIDRegister) & 0xff00) != 0x5200) {
    m_spi.free();
    m_spi = null;
    DriverStation.reportError("could not find ADXRS450 gyro on SPI port " + port.getValue(), false);
    return;
  }

  m_spi.initAccumulator(kSamplePeriod, 0x20000000, 4, 0x0c000000, 0x04000000,
      10, 16, true, true);

  calibrate();

  UsageReporting.report(tResourceType.kResourceType_ADXRS450, port.getValue());
  LiveWindow.addSensor("ADXRS450_Gyro", port.getValue(), this);
}
项目:Frc2016FirstStronghold    文件:AnalogOutput.java   
/**
 * Construct an analog output on a specified MXP channel.
 *
 * @param channel The channel number to represent.
 */
public AnalogOutput(final int channel) {
  m_channel = channel;

  if (!AnalogJNI.checkAnalogOutputChannel(channel)) {
    throw new AllocationException("Analog output channel " + m_channel
        + " cannot be allocated. Channel is not present.");
  }
  try {
    channels.allocate(channel);
  } catch (CheckedAllocationException e) {
    throw new AllocationException("Analog output channel " + m_channel + " is already allocated");
  }

  long port_pointer = AnalogJNI.getPort((byte) channel);
  m_port = AnalogJNI.initializeAnalogOutputPort(port_pointer);

  LiveWindow.addSensor("AnalogOutput", channel, this);
  UsageReporting.report(tResourceType.kResourceType_AnalogOutput, channel);
}
项目:Frc2016FirstStronghold    文件:Ultrasonic.java   
/**
 * Initialize the Ultrasonic Sensor. This is the common code that initializes
 * the ultrasonic sensor given that there are two digital I/O channels
 * allocated. If the system was running in automatic mode (round robin) when
 * the new sensor is added, it is stopped, the sensor is added, then automatic
 * mode is restored.
 */
private synchronized void initialize() {
  if (m_task == null) {
    m_task = new UltrasonicChecker();
  }
  boolean originalMode = m_automaticEnabled;
  setAutomaticMode(false); // kill task when adding a new sensor
  m_nextSensor = m_firstSensor;
  m_firstSensor = this;

  m_counter = new Counter(m_echoChannel); // set up counter for this
  // sensor
  m_counter.setMaxPeriod(1.0);
  m_counter.setSemiPeriodMode(true);
  m_counter.reset();
  m_enabled = true; // make it available for round robin scheduling
  setAutomaticMode(originalMode);

  m_instances++;
  UsageReporting.report(tResourceType.kResourceType_Ultrasonic, m_instances);
  LiveWindow.addSensor("Ultrasonic", m_echoChannel.getChannel(), this);
}
项目:Frc2016FirstStronghold    文件:AnalogGyro.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);
}
项目:Frc2016FirstStronghold    文件:PWM.java   
/**
 * Initialize PWMs given a channel.
 *
 * This method is private and is the common path for all the constructors for
 * creating PWM instances. Checks channel value ranges and allocates the
 * appropriate channel. The allocation is only done to help users ensure that
 * they don't double assign channels.
 *$
 * @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the
 *        MXP port
 */
private void initPWM(final int channel) {
  checkPWMChannel(channel);
  m_channel = channel;

  m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel));

  if (!PWMJNI.allocatePWMChannel(m_port)) {
    throw new AllocationException("PWM channel " + channel + " is already allocated");
  }

  PWMJNI.setPWM(m_port, (short) 0);

  m_eliminateDeadband = false;

  UsageReporting.report(tResourceType.kResourceType_PWM, channel);
}
项目:Frc2016FirstStronghold    文件:Solenoid.java   
/**
 * Common function to implement constructor behavior.
 */
private synchronized void initSolenoid() {
  checkSolenoidModule(m_moduleNumber);
  checkSolenoidChannel(m_channel);

  try {
    m_allocated.allocate(m_moduleNumber * kSolenoidChannels + m_channel);
  } catch (CheckedAllocationException e) {
    throw new AllocationException("Solenoid channel " + m_channel + " on module "
      + m_moduleNumber + " is already allocated");
  }

  long port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
  m_solenoid_port = SolenoidJNI.initializeSolenoidPort(port);

  LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
  UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber);
}
项目:Frc2016FirstStronghold    文件:ADXL345_SPI.java   
/**
 * Set SPI bus parameters, bring device out of sleep and set format
 *
 * @param range The range (+ or -) that the accelerometer will measure.
 */
private void init(Range range) {
  m_spi.setClockRate(500000);
  m_spi.setMSBFirst();
  m_spi.setSampleDataOnFalling();
  m_spi.setClockActiveLow();
  m_spi.setChipSelectActiveHigh();

  // Turn on the measurements
  byte[] commands = new byte[2];
  commands[0] = kPowerCtlRegister;
  commands[1] = kPowerCtl_Measure;
  m_spi.write(commands, 2);

  setRange(range);

  UsageReporting.report(tResourceType.kResourceType_ADXL345, tInstances.kADXL345_SPI);
}
项目:Frc2016FirstStronghold    文件:Relay.java   
/**
 * Common relay initialization method. This code is common to all Relay
 * constructors and initializes the relay and reserves all resources that need
 * to be locked. Initially the relay is set to both lines at 0v.
 */
private void initRelay() {
  SensorBase.checkRelayChannel(m_channel);
  try {
    if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
      relayChannels.allocate(m_channel * 2);
      UsageReporting.report(tResourceType.kResourceType_Relay, m_channel);
    }
    if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
      relayChannels.allocate(m_channel * 2 + 1);
      UsageReporting.report(tResourceType.kResourceType_Relay, m_channel + 128);
    }
  } catch (CheckedAllocationException e) {
    throw new AllocationException("Relay channel " + m_channel + " is already allocated");
  }

  m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel));

  m_safetyHelper = new MotorSafetyHelper(this);
  m_safetyHelper.setSafetyEnabled(false);

  LiveWindow.addActuator("Relay", m_channel, this);
}
项目:Frc2016FirstStronghold    文件:AnalogInput.java   
/**
 * Construct an analog channel.
 *
 * @param channel The channel number to represent. 0-3 are on-board 4-7 are on
 *        the MXP port.
 */
public AnalogInput(final int channel) {
  m_channel = channel;

  if (!AnalogJNI.checkAnalogInputChannel(channel)) {
    throw new AllocationException("Analog input channel " + m_channel
        + " cannot be allocated. Channel is not present.");
  }
  try {
    channels.allocate(channel);
  } catch (CheckedAllocationException e) {
    throw new AllocationException("Analog input channel " + m_channel + " is already allocated");
  }

  long port_pointer = AnalogJNI.getPort((byte) channel);
  m_port = AnalogJNI.initializeAnalogInputPort(port_pointer);

  LiveWindow.addSensor("AnalogInput", channel, this);
  UsageReporting.report(tResourceType.kResourceType_AnalogChannel, channel);
}
项目: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);
}
项目:wpilibj    文件:RobotDrive.java   
/**
 * Provide tank steering using the stored robot configuration.
 * This function lets you directly provide joystick values from any source.
 * @param leftValue The value of the left stick.
 * @param rightValue The value of the right stick.
 * @param squaredInputs Setting this parameter to true decreases the sensitivity at lower speeds
 */
public void tankDrive(double leftValue, double rightValue, boolean squaredInputs) {

    if(!kTank_Reported){
        UsageReporting.report(UsageReporting.kResourceType_RobotDrive, getNumMotors(), UsageReporting.kRobotDrive_Tank);
        kTank_Reported = true;
    }

    // square the inputs (while preserving the sign) to increase fine control while permitting full power
    leftValue = limit(leftValue);
    rightValue = limit(rightValue);
    if(squaredInputs) {
        if (leftValue >= 0.0) {
            leftValue = (leftValue * leftValue);
        } else {
            leftValue = -(leftValue * leftValue);
        }
        if (rightValue >= 0.0) {
            rightValue = (rightValue * rightValue);
        } else {
            rightValue = -(rightValue * rightValue);
        }
    }
    setLeftRightMotorOutputs(leftValue, rightValue);
}
项目:wpilibj    文件:AnalogChannel.java   
/**
 * Construct an analog channel on a specified module.
 *
 * @param moduleNumber The digital module to use (1 or 2).
 * @param channel The channel number to represent.
 */
public AnalogChannel(final int moduleNumber, final int channel) {
    m_shouldUseVoltageForPID = false;
    checkAnalogModule(moduleNumber);
    checkAnalogChannel(channel);
    m_channel = channel;
    m_moduleNumber = moduleNumber;
    m_module = AnalogModule.getInstance(moduleNumber);
    try {
        channels.allocate((moduleNumber - 1) * kAnalogChannels + m_channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "Analog channel " + m_channel + " on module " + m_moduleNumber + " is already allocated");
    }
    if (channel == 1 || channel == 2) {
        m_accumulator = new tAccumulator((byte) (channel - 1));
        m_accumulatorOffset = 0;
    } else {
        m_accumulator = null;
    }

    LiveWindow.addSensor("Analog", moduleNumber, channel, this);
    UsageReporting.report(UsageReporting.kResourceType_AnalogChannel, channel, m_moduleNumber-1);
}
项目:wpilibj    文件:Counter.java   
private void initCounter(final Mode mode) {
    m_allocatedUpSource = false;
    m_allocatedDownSource = false;

    try {
        m_index = counters.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No counters left to be allocated");
    }

    m_counter = new tCounter(m_index);
    m_counter.writeConfig_Mode(mode.value);
    m_upSource = null;
    m_downSource = null;
    m_counter.writeTimerConfig_AverageSize(1);

   UsageReporting.report(UsageReporting.kResourceType_Counter, m_index, mode.value);
}
项目:wpilibj    文件:Jaguar.java   
/**
 * Common initialization code called by all constructors.
 */
private void initJaguar() {
    /*
     * Input profile defined by Luminary Micro.
     *
     * Full reverse ranges from 0.671325ms to 0.6972211ms
     * Proportional reverse ranges from 0.6972211ms to 1.4482078ms
     * Neutral ranges from 1.4482078ms to 1.5517922ms
     * Proportional forward ranges from 1.5517922ms to 2.3027789ms
     * Full forward ranges from 2.3027789ms to 2.328675ms
     */
    setBounds(2.31, 1.55, 1.507, 1.454, .697);
    setPeriodMultiplier(PeriodMultiplier.k1X);
    setRaw(m_centerPwm);

    UsageReporting.report(UsageReporting.kResourceType_Jaguar, getChannel(), getModuleNumber()-1);
    LiveWindow.addActuator("Jaguar", getModuleNumber(), getChannel(), this);
}
项目:wpilibj    文件:HiTechnicColorSensor.java   
/**
 * Constructor.
 *
 * @param slot The slot of the digital module that the sensor is plugged into.
 */
public HiTechnicColorSensor(int slot) {
    DigitalModule module = DigitalModule.getInstance(slot);
    m_i2c = module.getI2C(kAddress);

    // Verify Sensor
    final byte[] kExpectedManufacturer = "HiTechnc".getBytes();
    final byte[] kExpectedSensorType = "ColorPD ".getBytes();
    if (!m_i2c.verifySensor(kManufacturerBaseRegister, kManufacturerSize, kExpectedManufacturer)) {
        throw new ColorSensorException("Invalid Color Sensor Manufacturer");
    }
    if (!m_i2c.verifySensor(kSensorTypeBaseRegister, kSensorTypeSize, kExpectedSensorType)) {
        throw new ColorSensorException("Invalid Sensor type");
    }

    LiveWindow.addSensor("HiTechnicColorSensor", slot, 0, this);
    UsageReporting.report(UsageReporting.kResourceType_HiTechnicColorSensor, module.getModuleNumber()-1);
}
项目:wpilibj    文件:Ultrasonic.java   
/**
 * Initialize the Ultrasonic Sensor.
 * This is the common code that initializes the ultrasonic sensor given that there
 * are two digital I/O channels allocated. If the system was running in automatic mode (round robin)
 * when the new sensor is added, it is stopped, the sensor is added, then automatic mode is
 * restored.
 */
private synchronized void initialize() {
    if (m_task == null) {
        m_task = new UltrasonicChecker();
    }
    boolean originalMode = m_automaticEnabled;
    setAutomaticMode(false); // kill task when adding a new sensor
    m_nextSensor = m_firstSensor;
    m_firstSensor = this;

    m_counter = new Counter(m_echoChannel); // set up counter for this sensor
    m_counter.setMaxPeriod(1.0);
    m_counter.setSemiPeriodMode(true);
    m_counter.reset();
    m_counter.start();
    m_enabled = true; // make it available for round robin scheduling
    setAutomaticMode(originalMode);

    m_instances++;
    UsageReporting.report(UsageReporting.kResourceType_Ultrasonic, m_instances);
    LiveWindow.addSensor("Ultrasonic", m_echoChannel.getModuleForRouting(), m_echoChannel.getChannel(), this);
}
项目:wpilibj    文件:RobotBase.java   
/**
 * Starting point for the applications. Starts the OtaServer and then runs
 * the robot.
 *
 * @throws javax.microedition.midlet.MIDletStateChangeException
 */
protected final void startApp() throws MIDletStateChangeException {
    boolean errorOnExit = false;

    Watchdog.getInstance().setExpiration(0.1);
    Watchdog.getInstance().setEnabled(false);
    FRCControl.observeUserProgramStarting();
    UsageReporting.report(UsageReporting.kResourceType_Language, UsageReporting.kLanguage_Java);

    writeVersionString();

    try {
        this.startCompetition();
    } catch (Throwable t) {
        t.printStackTrace();
        errorOnExit = true;
    } finally {
        // startCompetition never returns unless exception occurs....
        System.err.println("WARNING: Robots don't quit!");
        if (errorOnExit) {
            System.err.println("---> The startCompetition() method (or methods called by it) should have handled the exception above.");
        } else {
            System.err.println("---> Unexpected return from startCompetition() method.");
        }
    }
}
项目:wpilibj    文件:PWM.java   
/**
 * Initialize PWMs given an module and channel.
 *
 * This method is private and is the common path for all the constructors for creating PWM
 * instances. Checks module and channel value ranges and allocates the appropriate channel.
 * The allocation is only done to help users ensure that they don't double assign channels.
 */
private void initPWM(final int moduleNumber, final int channel) {
    checkPWMModule(moduleNumber);
    checkPWMChannel(channel);
    try {
        allocated.allocate((moduleNumber - 1) * kPwmChannels + channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "PWM channel " + channel + " on module " + moduleNumber + " is already allocated");
    }
    m_channel = channel;
    m_module = DigitalModule.getInstance(moduleNumber);
    m_module.setPWM(m_channel, kPwmDisabled);
    m_eliminateDeadband = false;

    UsageReporting.report(UsageReporting.kResourceType_PWM, channel, moduleNumber-1);
}
项目:wpilibj    文件:Relay.java   
/**
 * Common relay initialization method.
 * This code is common to all Relay constructors and initializes the relay and reserves
 * all resources that need to be locked. Initially the relay is set to both lines at 0v.
 * @param moduleNumber The number of the digital module to use.
 */
private void initRelay(final int moduleNumber) {
    SensorBase.checkRelayModule(moduleNumber);
    SensorBase.checkRelayChannel(m_channel);
    try {
        if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
            relayChannels.allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2);
            UsageReporting.report(UsageReporting.kResourceType_Relay, m_channel, moduleNumber-1);
        }
        if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
            relayChannels.allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2 + 1);
            UsageReporting.report(UsageReporting.kResourceType_Relay, m_channel+128, moduleNumber-1);
        }
    } catch (CheckedAllocationException e) {
        throw new AllocationException("Relay channel " + m_channel + " on module " + moduleNumber + " is already allocated");
    }
    m_module = DigitalModule.getInstance(moduleNumber);
    m_module.setRelayForward(m_channel, false);
    m_module.setRelayReverse(m_channel, false);
    LiveWindow.addActuator("Relay", moduleNumber, m_channel, this);
}
项目:wpilibj    文件:Preferences.java   
/**
 * Creates a preference class that will automatically read the file in a
 * different thread. Any call to its methods will be blocked until the
 * thread is finished reading.
 */
private Preferences() {
    values = new Hashtable();
    keys = new Vector();

    // We synchronized on fileLock and then wait 
    // for it to know that the reading thread has started
    synchronized (fileLock) {
        new Thread() {
            public void run() {
                read();
            }
        }.start();
        try {
            fileLock.wait();
        } catch (InterruptedException ex) {
        }
    }

    UsageReporting.report(UsageReporting.kResourceType_Preferences, 0);
}
项目:wpilibj    文件:HiTechnicCompass.java   
/**
 * Constructor.
 *
 * @param slot The slot of the digital module that the sensor is plugged into.
 */
public HiTechnicCompass(int slot) {
    DigitalModule module = DigitalModule.getInstance(slot);
    m_i2c = module.getI2C(kAddress);

    // Verify Sensor
    final byte[] kExpectedManufacturer = "HiTechnc".getBytes();
    final byte[] kExpectedSensorType = "Compass ".getBytes();
    if (!m_i2c.verifySensor(kManufacturerBaseRegister, kManufacturerSize, kExpectedManufacturer)) {
        throw new CompassException("Invalid Compass Manufacturer");
    }
    if (!m_i2c.verifySensor(kSensorTypeBaseRegister, kSensorTypeSize, kExpectedSensorType)) {
        throw new CompassException("Invalid Sensor type");
    }

    UsageReporting.report(UsageReporting.kResourceType_HiTechnicCompass, module.getModuleNumber()-1);
    LiveWindow.addSensor("HiTechnicCompass", slot, 0, this);
}
项目:aeronautical-facilitation    文件:RobotDrive6.java   
/**
 * Provide tank steering using the stored robot configuration. This function
 * lets you directly provide joystick values from any source.
 *
 * @param leftValue The value of the left stick.
 * @param rightValue The value of the right stick.
 * @param squaredInputs Setting this parameter to true decreases the
 * sensitivity at lower speeds
 */
public void tankDrive(double leftValue, double rightValue, boolean squaredInputs) {

    if (!kTank_Reported) {
        UsageReporting.report(UsageReporting.kResourceType_RobotDrive, getNumMotors(), UsageReporting.kRobotDrive_Tank);
        kTank_Reported = true;
    }

    // square the inputs (while preserving the sign) to increase fine control while permitting full power
    leftValue = limit(leftValue);
    rightValue = limit(rightValue);
    if (squaredInputs) {
        if (leftValue >= 0.0) {
            leftValue = (leftValue * leftValue);
        } else {
            leftValue = -(leftValue * leftValue);
        }
        if (rightValue >= 0.0) {
            rightValue = (rightValue * rightValue);
        } else {
            rightValue = -(rightValue * rightValue);
        }
    }
    setLeftRightMotorOutputs(leftValue, rightValue);
}
项目:Felix-2014    文件:RobotDriveSteering.java   
/**
 * Provide tank steering using the stored robot configuration. This function
 * lets you directly provide joystick values from any source.
 *
 * @param leftValue The value of the left stick.
 * @param rightValue The value of the right stick.
 * @param squaredInputs Setting this parameter to true decreases the
 * sensitivity at lower speeds
 */
public void tankDrive(double leftValue, double rightValue, boolean squaredInputs) {

    if (!kTank_Reported) {
        UsageReporting.report(UsageReporting.kResourceType_RobotDrive, getNumMotors(), UsageReporting.kRobotDrive_Tank);
        kTank_Reported = true;
    }

    // square the inputs (while preserving the sign) to increase fine control while permitting full power
    leftValue = limit(leftValue);
    rightValue = limit(rightValue);
    if (squaredInputs) {
        if (leftValue >= 0.0) {
            leftValue = (leftValue * leftValue);
        } else {
            leftValue = -(leftValue * leftValue);
        }
        if (rightValue >= 0.0) {
            rightValue = (rightValue * rightValue);
        } else {
            rightValue = -(rightValue * rightValue);
        }
    }
    setLeftRightMotorOutputs(leftValue, rightValue);
}
项目:Robot-Java-2014    文件:RobotDrive.java   
/**
 * Provide tank steering using the stored robot configuration.
 * This function lets you directly provide joystick values from any source.
 * @param leftValue The value of the left stick.
 * @param rightValue The value of the right stick.
 * @param squaredInputs Setting this parameter to true decreases the sensitivity at lower speeds
 */
public void tankDrive(double leftValue, double rightValue, boolean squaredInputs) {

    if(!kTank_Reported){
        UsageReporting.report(UsageReporting.kResourceType_RobotDrive, getNumMotors(), UsageReporting.kRobotDrive_Tank);
        kTank_Reported = true;
    }

    // square the inputs (while preserving the sign) to increase fine control while permitting full power
    leftValue = limit(leftValue);
    rightValue = limit(rightValue);
    if(squaredInputs) {
        if (leftValue >= 0.0) {
            leftValue = (leftValue * leftValue);
        } else {
            leftValue = -(leftValue * leftValue);
        }
        if (rightValue >= 0.0) {
            rightValue = (rightValue * rightValue);
        } else {
            rightValue = -(rightValue * rightValue);
        }
    }
    setLeftRightMotorOutputs(leftValue, rightValue);
}
项目: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);
}
项目:wpilib-java    文件:RobotDrive.java   
/**
 * Provide tank steering using the stored robot configuration.
 * This function lets you directly provide joystick values from any source.
 * @param leftValue The value of the left stick.
 * @param rightValue The value of the right stick.
 * @param squaredInputs Setting this parameter to true decreases the sensitivity at lower speeds
 */
public void tankDrive(double leftValue, double rightValue, boolean squaredInputs) {

    if(!kTank_Reported){
        UsageReporting.report(UsageReporting.kResourceType_RobotDrive, getNumMotors(), UsageReporting.kRobotDrive_Tank);
        kTank_Reported = true;
    }

    // square the inputs (while preserving the sign) to increase fine control while permitting full power
    leftValue = limit(leftValue);
    rightValue = limit(rightValue);
    if(squaredInputs) {
        if (leftValue >= 0.0) {
            leftValue = (leftValue * leftValue);
        } else {
            leftValue = -(leftValue * leftValue);
        }
        if (rightValue >= 0.0) {
            rightValue = (rightValue * rightValue);
        } else {
            rightValue = -(rightValue * rightValue);
        }
    }
    setLeftRightMotorOutputs(leftValue, rightValue);
}
项目:wpilib-java    文件:AnalogChannel.java   
/**
 * Construct an analog channel on a specified module.
 *
 * @param moduleNumber The digital module to use (1 or 2).
 * @param channel The channel number to represent.
 */
public AnalogChannel(final int moduleNumber, final int channel) {
    checkAnalogModule(moduleNumber);
    checkAnalogChannel(channel);
    m_channel = channel;
    m_moduleNumber = moduleNumber;
    m_module = AnalogModule.getInstance(moduleNumber);
    try {
        channels.allocate((moduleNumber - 1) * kAnalogChannels + m_channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "Analog channel " + m_channel + " on module " + m_moduleNumber + " is already allocated");
    }
    if (channel == 1 || channel == 2) {
        m_accumulator = new tAccumulator((byte) (channel - 1));
        m_accumulatorOffset = 0;
    } else {
        m_accumulator = null;
    }

    LiveWindow.addSensor("Analog", moduleNumber, channel, this);
    UsageReporting.report(UsageReporting.kResourceType_AnalogChannel, channel, m_moduleNumber-1);
}
项目:wpilib-java    文件:Counter.java   
private void initCounter(final Mode mode) {
    m_allocatedUpSource = false;
    m_allocatedDownSource = false;

    try {
        m_index = counters.allocate();
    } catch (CheckedAllocationException e) {
        throw new AllocationException("No counters left to be allocated");
    }

    m_counter = new tCounter(m_index);
    m_counter.writeConfig_Mode(mode.value);
    m_upSource = null;
    m_downSource = null;
    m_counter.writeTimerConfig_AverageSize(1);

   UsageReporting.report(UsageReporting.kResourceType_Counter, m_index, mode.value);
}
项目:wpilib-java    文件:Jaguar.java   
/**
 * Common initialization code called by all constructors.
 */
private void initJaguar() {
    /*
     * Input profile defined by Luminary Micro.
     *
     * Full reverse ranges from 0.671325ms to 0.6972211ms
     * Proportional reverse ranges from 0.6972211ms to 1.4482078ms
     * Neutral ranges from 1.4482078ms to 1.5517922ms
     * Proportional forward ranges from 1.5517922ms to 2.3027789ms
     * Full forward ranges from 2.3027789ms to 2.328675ms
     */
    setBounds(251, 135, 128, 120, 4);
    setPeriodMultiplier(PeriodMultiplier.k1X);
    setRaw(m_centerPwm);

    UsageReporting.report(UsageReporting.kResourceType_Jaguar, getChannel(), getModuleNumber()-1);
    LiveWindow.addActuator("Jaguar", getModuleNumber(), getChannel(), this);
}
项目:wpilib-java    文件:HiTechnicColorSensor.java   
/**
 * Constructor.
 *
 * @param slot The slot of the digital module that the sensor is plugged into.
 */
public HiTechnicColorSensor(int slot) {
    DigitalModule module = DigitalModule.getInstance(slot);
    m_i2c = module.getI2C(kAddress);

    // Verify Sensor
    final byte[] kExpectedManufacturer = "HiTechnc".getBytes();
    final byte[] kExpectedSensorType = "ColorPD ".getBytes();
    if (!m_i2c.verifySensor(kManufacturerBaseRegister, kManufacturerSize, kExpectedManufacturer)) {
        throw new ColorSensorException("Invalid Color Sensor Manufacturer");
    }
    if (!m_i2c.verifySensor(kSensorTypeBaseRegister, kSensorTypeSize, kExpectedSensorType)) {
        throw new ColorSensorException("Invalid Sensor type");
    }

    LiveWindow.addSensor("HiTechnicColorSensor", slot, 0, this);
    UsageReporting.report(UsageReporting.kResourceType_HiTechnicColorSensor, module.getModuleNumber()-1);
}
项目:wpilib-java    文件:Ultrasonic.java   
/**
 * Initialize the Ultrasonic Sensor.
 * This is the common code that initializes the ultrasonic sensor given that there
 * are two digital I/O channels allocated. If the system was running in automatic mode (round robin)
 * when the new sensor is added, it is stopped, the sensor is added, then automatic mode is
 * restored.
 */
private synchronized void initialize() {
    if (m_task == null) {
        m_task = new UltrasonicChecker();
    }
    boolean originalMode = m_automaticEnabled;
    setAutomaticMode(false); // kill task when adding a new sensor
    m_nextSensor = m_firstSensor;
    m_firstSensor = this;

    m_counter = new Counter(m_echoChannel); // set up counter for this sensor
    m_counter.setMaxPeriod(1.0);
    m_counter.setSemiPeriodMode(true);
    m_counter.reset();
    m_counter.start();
    m_enabled = true; // make it available for round robin scheduling
    setAutomaticMode(originalMode);

    m_instances++;
    UsageReporting.report(UsageReporting.kResourceType_Ultrasonic, m_instances);
    LiveWindow.addSensor("Ultrasonic", m_echoChannel.getModuleForRouting(), m_echoChannel.getChannel(), this);
}
项目:wpilib-java    文件:RobotBase.java   
/**
 * Starting point for the applications. Starts the OtaServer and then runs
 * the robot.
 * @throws javax.microedition.midlet.MIDletStateChangeException
 */
protected final void startApp() throws MIDletStateChangeException {
    boolean errorOnExit = false;

    Watchdog.getInstance().setExpiration(0.1);
    Watchdog.getInstance().setEnabled(false);
    FRCControl.observeUserProgramStarting();
    UsageReporting.report(UsageReporting.kResourceType_Language, UsageReporting.kLanguage_Java);

    try {
        this.startCompetition();
    } catch (Throwable t) {
        t.printStackTrace();
        errorOnExit = true;
    } finally {
        // startCompetition never returns unless exception occurs....
        System.err.println("WARNING: Robots don't quit!");
        if (errorOnExit) {
            System.err.println("---> The startCompetition() method (or methods called by it) should have handled the exception above.");
        } else {
            System.err.println("---> Unexpected return from startCompetition() method.");
        }
    }
}
项目:wpilib-java    文件:PWM.java   
/**
 * Initialize PWMs given an module and channel.
 *
 * This method is private and is the common path for all the constructors for creating PWM
 * instances. Checks module and channel value ranges and allocates the appropriate channel.
 * The allocation is only done to help users ensure that they don't double assign channels.
 */
private void initPWM(final int moduleNumber, final int channel) {
    checkPWMModule(moduleNumber);
    checkPWMChannel(channel);
    try {
        allocated.allocate((moduleNumber - 1) * kPwmChannels + channel - 1);
    } catch (CheckedAllocationException e) {
        throw new AllocationException(
                "PWM channel " + channel + " on module " + moduleNumber + " is already allocated");
    }
    m_channel = channel;
    m_module = DigitalModule.getInstance(moduleNumber);
    m_module.setPWM(m_channel, kPwmDisabled);
    m_eliminateDeadband = false;

    UsageReporting.report(UsageReporting.kResourceType_PWM, channel, moduleNumber-1);
}
项目:wpilib-java    文件:Relay.java   
/**
 * Common relay initialization method.
 * This code is common to all Relay constructors and initializes the relay and reserves
 * all resources that need to be locked. Initially the relay is set to both lines at 0v.
 * @param moduleNumber The number of the digital module to use.
 */
private void initRelay(final int moduleNumber) {
    SensorBase.checkRelayModule(moduleNumber);
    SensorBase.checkRelayChannel(m_channel);
    try {
        if (m_direction == Direction.kBoth || m_direction == Direction.kForward) {
            relayChannels.allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2);
            UsageReporting.report(UsageReporting.kResourceType_Relay, m_channel, moduleNumber-1);
        }
        if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) {
            relayChannels.allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2 + 1);
            UsageReporting.report(UsageReporting.kResourceType_Relay, m_channel+128, moduleNumber-1);
        }
    } catch (CheckedAllocationException e) {
        throw new AllocationException("Relay channel " + m_channel + " on module " + moduleNumber + " is already allocated");
    }
    m_module = DigitalModule.getInstance(moduleNumber);
    m_module.setRelayForward(m_channel, false);
    m_module.setRelayReverse(m_channel, false);
    LiveWindow.addActuator("Relay", moduleNumber, m_channel, this);
}
项目:wpilib-java    文件:HiTechnicCompass.java   
/**
 * Constructor.
 *
 * @param slot The slot of the digital module that the sensor is plugged into.
 */
public HiTechnicCompass(int slot) {
    DigitalModule module = DigitalModule.getInstance(slot);
    m_i2c = module.getI2C(kAddress);

    // Verify Sensor
    final byte[] kExpectedManufacturer = "HiTechnc".getBytes();
    final byte[] kExpectedSensorType = "Compass ".getBytes();
    if (!m_i2c.verifySensor(kManufacturerBaseRegister, kManufacturerSize, kExpectedManufacturer)) {
        throw new CompassException("Invalid Compass Manufacturer");
    }
    if (!m_i2c.verifySensor(kSensorTypeBaseRegister, kSensorTypeSize, kExpectedSensorType)) {
        throw new CompassException("Invalid Sensor type");
    }

    UsageReporting.report(UsageReporting.kResourceType_HiTechnicCompass, module.getModuleNumber()-1);
    LiveWindow.addSensor("HiTechnicCompass", slot, 0, this);
}
项目:Frc2016FirstStronghold    文件:BuiltInAccelerometer.java   
/**
 * Constructor.
 *$
 * @param range The range the accelerometer will measure
 */
public BuiltInAccelerometer(Range range) {
  setRange(range);
  UsageReporting
      .report(tResourceType.kResourceType_Accelerometer, 0, 0, "Built-in accelerometer");
  LiveWindow.addSensor("BuiltInAccel", 0, this);
}