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

项目:SwerveDrive    文件:AbsoluteAnalogEncoder.java   
public AbsoluteAnalogEncoder(int channel, double minVoltage, double maxVoltage, double offsetDegrees, int analogSampleRate, double analogTriggerThresholdDifference) { //TODO: Implement direction
    super(channel);
    _channel = channel;
    if (minVoltage >= maxVoltage) throw new IllegalArgumentException("Minimum voltage must be less than maximum voltage");
    if (offsetDegrees < 0 || offsetDegrees > 360) throw new IllegalArgumentException("Offset must be between 0 and 360 degrees");

    // Initialize analog trigger //
    _analogTrigger = new AnalogTrigger(channel);
    _analogTrigger.setFiltered(true);
    _analogTrigger.setLimitsVoltage(minVoltage + analogTriggerThresholdDifference, maxVoltage - analogTriggerThresholdDifference);
    AnalogTriggerOutput _analogTriggerFalling = new AnalogTriggerOutput(_analogTrigger, AnalogTriggerOutput.Type.kFallingPulse);
    AnalogTriggerOutput _analogTriggerRising = new AnalogTriggerOutput(_analogTrigger, AnalogTriggerOutput.Type.kRisingPulse);

    // Set analog module sampling rate //        
    AnalogModule module = (AnalogModule) Module.getModule(ModulePresence.ModuleType.kAnalog, DEFAULT_ANALOG_MODULE);
    module.setSampleRate(analogSampleRate);

    // Initialize turn counter //
    _turnCounter = new Counter();
    _turnCounter.setUpDownCounterMode();
    _turnCounter.setUpSource(_analogTriggerRising);
    _turnCounter.setDownSource(_analogTriggerFalling);
    _turnCounter.start();

    _minVoltage = minVoltage;
    _maxVoltage = maxVoltage;
    _offsetDegrees = offsetDegrees;
}
项目:wpilibj    文件:Module.java   
/**
   * Static module singleton factory.
   * 
   * @param moduleType The type of the module represented.
   * @param moduleNumber The module index within the module type.
   * @return the module
   */
  public static Module getModule(ModulePresence.ModuleType moduleType, int moduleNumber) {
      if(m_modules[toIndex(moduleType, moduleNumber)] == null) {
          if(moduleType.equals(ModulePresence.ModuleType.kAnalog)) {
              new AnalogModule(moduleNumber);
          } else if (moduleType.equals(ModulePresence.ModuleType.kDigital)) {
              new DigitalModule(moduleNumber);
/*        } else if (moduleType.equals(ModulePresence.ModuleType.kSolenoid)) {
              new Sol
 */      } else {
              throw new RuntimeException("A module of type "+moduleType+" with module index "+moduleNumber);
          }
      }
      return m_modules[toIndex(moduleType, moduleNumber)];
  }
项目:wpilibj    文件:AnalogModule.java   
/**
 * Create a new instance of an analog module.
 *
 * Create an instance of the analog module object. Initialize all the parameters
 * to reasonable values on start.
 * Setting a global value on an analog module can be done only once unless subsequent
 * values are set the previously set value.
 * Analog modules are a singleton, so the constructor is never called outside of this class.
 *
 * @param moduleNumber The index of the analog module to create (1 or 2).
 */
protected AnalogModule(final int moduleNumber) {
    super(ModulePresence.ModuleType.kAnalog, moduleNumber);

    m_module = new tAI(moduleNumber - 1);
    setNumChannelsToActivate(SensorBase.kAnalogChannels);
    setSampleRate(AnalogModule.kDefaultSampleRate);

    for (int i = 0; i < SensorBase.kAnalogChannels; i++) {
        m_module.writeScanList(i, i);
        setAverageBits(i + 1, kDefaultAverageBits);
        setOversampleBits(i + 1, kDefaultOversampleBits);
    }
}
项目:wpilibj    文件:DigitalModule.java   
/**
 * Create a new digital module
 * @param moduleNumber The number of the digital module to use (1 or 2)
 */
protected DigitalModule(final int moduleNumber) {
    super(ModulePresence.ModuleType.kDigital, moduleNumber);

    DO_PWMGenerators[m_moduleNumber - 1] = new Resource(tDIO.kDO_PWMDutyCycle_NumElements);
    m_fpgaDIO = new tDIO(m_moduleNumber - 1);

    while (tDIO.readLoopTiming() == 0) {
        Timer.delay(.001);
    }

    if (tDIO.readLoopTiming() != kExpectedLoopTiming) {
        System.out.print("DIO LoopTiming: ");
        System.out.print(tDIO.readLoopTiming());
        System.out.print(", expecting: ");
        System.out.println(kExpectedLoopTiming);
    }

    //Calculate the length, in ms, of one DIO loop
    double loopTime = tDIO.readLoopTiming()/(kSystemClockTicksPerMicrosecond*1e3);

    tDIO.writePWMConfig_Period((short) (PWM.kDefaultPwmPeriod/loopTime + .5));

    //Calculate the minimum time for the PWM signal to be high by using the number of steps down from center
    tDIO.writePWMConfig_MinHigh((short) ((PWM.kDefaultPwmCenter-PWM.kDefaultPwmStepsDown*loopTime)/loopTime + .5));


    // Ensure that PWM output values are set to OFF
    for (int pwm_index = 1; pwm_index <= kPwmChannels; pwm_index++) {
        setPWM(pwm_index, PWM.kPwmDisabled);
        setPWMPeriodScale(pwm_index, PWM.PeriodMultiplier.k4X_val); // Set all to 4x by default.
    }

    // Turn off all relay outputs.
    m_fpgaDIO.writeSlowValue_RelayFwd(0);
    m_fpgaDIO.writeSlowValue_RelayRev(0);
}
项目:RobotCode2014    文件:BlackBoxUpdater.java   
private void addSolenoidPackets(BlackBoxPacket packet) {
    for (int i = 0; ; i++) {
        if (!ModulePresence.getModulePresence(ModuleType.kSolenoid, i+1)) break;
        BlackBoxSubPacketType packetType = new BlackBoxSubPacketType(0);
        packetType.addType(BlackBoxSubPacketType.DATA_UPDATE);
        packetType.addType(BlackBoxSubPacketType.MODULE_SOLENOID);
        packet.addPacket(BlackBoxSubPacket.getInstance(packetType.getType(), i+1));
    }
}
项目:RobotCode2013    文件:BlackBoxUpdater.java   
private void addSolenoidPackets(BlackBoxPacket packet) {
    for (int i = 0; ; i++) {
        if (!ModulePresence.getModulePresence(ModuleType.kSolenoid, i+1)) break;
        BlackBoxSubPacketType packetType = new BlackBoxSubPacketType(0);
        packetType.addType(BlackBoxSubPacketType.DATA_UPDATE);
        packetType.addType(BlackBoxSubPacketType.MODULE_SOLENOID);
        packet.addPacket(BlackBoxSubPacket.getInstance(packetType.getType(), i+1));
    }
}
项目:wpilib-java    文件:Module.java   
/**
   * Static module singleton factory.
   * 
   * @param moduleType The type of the module represented.
   * @param moduleNumber The module index within the module type.
   * @return the module
   */
  public static Module getModule(ModulePresence.ModuleType moduleType, int moduleNumber) {
      if(m_modules[toIndex(moduleType, moduleNumber)] == null) {
          if(moduleType.equals(ModulePresence.ModuleType.kAnalog)) {
              new AnalogModule(moduleNumber);
          } else if (moduleType.equals(ModulePresence.ModuleType.kDigital)) {
              new DigitalModule(moduleNumber);
/*        } else if (moduleType.equals(ModulePresence.ModuleType.kSolenoid)) {
              new Sol
 */      } else {
              throw new RuntimeException("A module of type "+moduleType+" with module index "+moduleNumber);
          }
      }
      return m_modules[toIndex(moduleType, moduleNumber)];
  }
项目:wpilib-java    文件:AnalogModule.java   
/**
 * Create a new instance of an analog module.
 *
 * Create an instance of the analog module object. Initialize all the parameters
 * to reasonable values on start.
 * Setting a global value on an analog module can be done only once unless subsequent
 * values are set the previously set value.
 * Analog modules are a singleton, so the constructor is never called outside of this class.
 *
 * @param moduleNumber The index of the analog module to create (1 or 2).
 */
protected AnalogModule(final int moduleNumber) {
    super(ModulePresence.ModuleType.kAnalog, moduleNumber);

    m_module = new tAI(moduleNumber - 1);
    setNumChannelsToActivate(SensorBase.kAnalogChannels);
    setSampleRate(AnalogModule.kDefaultSampleRate);

    for (int i = 0; i < SensorBase.kAnalogChannels; i++) {
        m_module.writeScanList(i, i);
        setAverageBits(i + 1, kDefaultAverageBits);
        setOversampleBits(i + 1, kDefaultOversampleBits);
    }
}
项目:wpilib-java    文件:DigitalModule.java   
/**
 * Create a new digital module
 * @param moduleNumber The number of the digital module to use (1 or 2)
 */
protected DigitalModule(final int moduleNumber) {
    super(ModulePresence.ModuleType.kDigital, moduleNumber);

    DO_PWMGenerators[m_moduleNumber - 1] = new Resource(tDIO.kDO_PWMDutyCycle_NumElements);
    m_fpgaDIO = new tDIO(m_moduleNumber - 1);

    while (tDIO.readLoopTiming() == 0) {
        Timer.delay(.001);
    }

    if (tDIO.readLoopTiming() != kExpectedLoopTiming) {
        System.out.print("DIO LoopTiming: ");
        System.out.print(tDIO.readLoopTiming());
        System.out.print(", expecting: ");
        System.out.println(kExpectedLoopTiming);
    }

    tDIO.writePWMConfig_Period((short) PWM.kDefaultPwmPeriod);
    tDIO.writePWMConfig_MinHigh((short) PWM.kDefaultMinPwmHigh);

    // Ensure that PWM output values are set to OFF
    for (int pwm_index = 1; pwm_index <= kPwmChannels; pwm_index++) {
        setPWM(pwm_index, PWM.kPwmDisabled);
        setPWMPeriodScale(pwm_index, PWM.PeriodMultiplier.k4X_val); // Set all to 4x by default.
    }

    // Turn off all relay outputs.
    m_fpgaDIO.writeSlowValue_RelayFwd(0);
    m_fpgaDIO.writeSlowValue_RelayRev(0);
}
项目:RobotCode2014    文件:BlackBoxUpdater.java   
private boolean hasAnalogModule(int moduleNum) {
    return ModulePresence.getModulePresence(ModuleType.kDigital, moduleNum);
}
项目:RobotCode2014    文件:BlackBoxUpdater.java   
private boolean hasDigitalModule(int moduleNum) {
    return ModulePresence.getModulePresence(ModuleType.kDigital, moduleNum);
}
项目:RobotCode2013    文件:BlackBoxUpdater.java   
private boolean hasAnalogModule(int moduleNum) {
    return ModulePresence.getModulePresence(ModuleType.kDigital, moduleNum);
}
项目:RobotCode2013    文件:BlackBoxUpdater.java   
private boolean hasDigitalModule(int moduleNum) {
    return ModulePresence.getModulePresence(ModuleType.kDigital, moduleNum);
}
项目:wpilibj    文件:SensorBase.java   
/**
 * Check that the digital module number is valid.
 * Module numbers are 1 or 2 (they are no longer real cRIO slots).
 *
 * @param moduleNumber The digital module module number to check.
 */
protected static void checkDigitalModule(final int moduleNumber) {
    if(!ModulePresence.getModulePresence(ModulePresence.ModuleType.kDigital, moduleNumber - 1))
        System.err.println("Digital module " + moduleNumber + " is not present.");
}
项目:wpilibj    文件:SensorBase.java   
/**
 * Check that the analog module number is valid.
 * Module numbers are 1 or 2 (they are no longer real cRIO slots).
 *
 * @param moduleNumber The analog module module number to check.
 */
protected static void checkAnalogModule(final int moduleNumber) {
    if(!ModulePresence.getModulePresence(ModulePresence.ModuleType.kAnalog, moduleNumber - 1)) {
        System.err.println("Analog module " + moduleNumber + " is not present.");
    }
}
项目:wpilibj    文件:SensorBase.java   
/**
 * Verify that the solenoid module is correct.
 * Module numbers are 1 or 2 (they are no longer real cRIO slots).
 *
 * @param moduleNumber The solenoid module module number to check.
 */
protected static void checkSolenoidModule(final int moduleNumber) {
    if(!ModulePresence.getModulePresence(ModulePresence.ModuleType.kSolenoid, moduleNumber - 1)) {
        System.err.println("Solenoid module " + moduleNumber + " is not present.");
    }
}
项目:wpilibj    文件:Module.java   
/**
 * Constructor.
 *
 * @param moduleNumber The number of this module (1 or 2).
 */
protected Module(ModulePresence.ModuleType moduleType, final int moduleNumber) {
    m_modules[toIndex(moduleType, moduleNumber)] = this;
    m_moduleNumber = moduleNumber;
}
项目:wpilibj    文件:Module.java   
/**
 * Gets the module type associated with a module.
 *
 * @return The module's type.
 */
public ModulePresence.ModuleType getModuleType() {
    return m_moduleType;
}
项目:wpilibj    文件:Module.java   
/**
 * Create an index into m_modules based on type and number
 *
 * @param moduleType The type of the module represented.
 * @param moduleNumber The module index within the module type.
 * @return The index into m_modules.
 */
private static int toIndex(ModulePresence.ModuleType moduleType, int moduleNumber) {
    if(moduleNumber == 0 || moduleNumber > ModulePresence.kMaxModuleNumber)
        return 0;
    return moduleType.getValue() * ModulePresence.kMaxModuleNumber + (moduleNumber - 1);
}
项目:wpilibj    文件:AnalogModule.java   
/**
 * Get an instance of an Analog Module.
 *
 * Singleton analog module creation where a module is allocated on the first use
 * and the same module is returned on subsequent uses.
 *
 * @param moduleNumber The index of the analog module to get (1 or 2).
 * @return The AnalogModule.
 */
public static synchronized AnalogModule getInstance(final int moduleNumber) {
    checkAnalogModule(moduleNumber);
    return (AnalogModule) getModule(ModulePresence.ModuleType.kAnalog, moduleNumber);
}
项目:wpilibj    文件:DigitalModule.java   
/**
 * Get an instance of an Digital Module.
 * Singleton digital module creation where a module is allocated on the first use
 * and the same module is returned on subsequent uses.
 *
 * @param moduleNumber The number of the digital module to access.
 * @return The digital module of the specified number.
 */
public static synchronized DigitalModule getInstance(final int moduleNumber) {
    SensorBase.checkDigitalModule(moduleNumber);
    return (DigitalModule) getModule(ModulePresence.ModuleType.kDigital, moduleNumber);
}
项目:wpilib-java    文件:SensorBase.java   
/**
 * Check that the digital module number is valid.
 * Module numbers are 1 or 2 (they are no longer real cRIO slots).
 *
 * @param moduleNumber The digital module module number to check.
 */
protected static void checkDigitalModule(final int moduleNumber) {
    if(!ModulePresence.getModulePresence(ModulePresence.ModuleType.kDigital, moduleNumber - 1))
        System.err.println("Digital module " + moduleNumber + " is not present.");
}
项目:wpilib-java    文件:SensorBase.java   
/**
 * Check that the analog module number is valid.
 * Module numbers are 1 or 2 (they are no longer real cRIO slots).
 *
 * @param moduleNumber The analog module module number to check.
 */
protected static void checkAnalogModule(final int moduleNumber) {
    if(!ModulePresence.getModulePresence(ModulePresence.ModuleType.kAnalog, moduleNumber - 1)) {
        System.err.println("Analog module " + moduleNumber + " is not present.");
    }
}
项目:wpilib-java    文件:SensorBase.java   
/**
 * Verify that the solenoid module is correct.
 * Module numbers are 1 or 2 (they are no longer real cRIO slots).
 *
 * @param moduleNumber The solenoid module module number to check.
 */
protected static void checkSolenoidModule(final int moduleNumber) {
    if(!ModulePresence.getModulePresence(ModulePresence.ModuleType.kSolenoid, moduleNumber - 1)) {
        System.err.println("Solenoid module " + moduleNumber + " is not present.");
    }
}
项目:wpilib-java    文件:Module.java   
/**
 * Constructor.
 *
 * @param moduleNumber The number of this module (1 or 2).
 */
protected Module(ModulePresence.ModuleType moduleType, final int moduleNumber) {
    m_modules[toIndex(moduleType, moduleNumber)] = this;
    m_moduleNumber = moduleNumber;
}
项目:wpilib-java    文件:Module.java   
/**
 * Gets the module type associated with a module.
 *
 * @return The module's type.
 */
public ModulePresence.ModuleType getModuleType() {
    return m_moduleType;
}
项目:wpilib-java    文件:Module.java   
/**
 * Create an index into m_modules based on type and number
 *
 * @param moduleType The type of the module represented.
 * @param moduleNumber The module index within the module type.
 * @return The index into m_modules.
 */
private static int toIndex(ModulePresence.ModuleType moduleType, int moduleNumber) {
    if(moduleNumber == 0 || moduleNumber > ModulePresence.kMaxModuleNumber)
        return 0;
    return moduleType.getValue() * ModulePresence.kMaxModuleNumber + (moduleNumber - 1);
}
项目:wpilib-java    文件:AnalogModule.java   
/**
 * Get an instance of an Analog Module.
 *
 * Singleton analog module creation where a module is allocated on the first use
 * and the same module is returned on subsequent uses.
 *
 * @param moduleNumber The index of the analog module to get (1 or 2).
 * @return The AnalogModule.
 */
public static synchronized AnalogModule getInstance(final int moduleNumber) {
    checkAnalogModule(moduleNumber);
    return (AnalogModule) getModule(ModulePresence.ModuleType.kAnalog, moduleNumber);
}
项目:wpilib-java    文件:DigitalModule.java   
/**
 * Get an instance of an Digital Module.
 * Singleton digital module creation where a module is allocated on the first use
 * and the same module is returned on subsequent uses.
 *
 * @param moduleNumber The number of the digital module to access.
 * @return The digital module of the specified number.
 */
public static synchronized DigitalModule getInstance(final int moduleNumber) {
    SensorBase.checkDigitalModule(moduleNumber);
    return (DigitalModule) getModule(ModulePresence.ModuleType.kDigital, moduleNumber);
}