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

项目:thirdcoast    文件:TalonConfiguration.java   
/**
 * Configure a Talon with stored parameters.
 *
 * @param talon the Talon to registerWith
 */
public void configure(@NotNull CANTalon talon) {
  talon.setSafetyEnabled(false);
  talon.setProfile(0);
  talon.setExpiration(MotorSafety.DEFAULT_SAFETY_EXPIRATION);
  Encoder enc = encoder != null ? encoder : Encoder.DEFAULT;
  enc.configure(talon);

  talon.enableBrakeMode(brakeInNeutral != null ? brakeInNeutral : true);
  talon.reverseOutput(outputReversed != null ? outputReversed : false);

  if (velocityMeasurementPeriod != null) {
    talon.SetVelocityMeasurementPeriod(velocityMeasurementPeriod);
  } else {
    talon.SetVelocityMeasurementPeriod(VelocityMeasurementPeriod.Period_100Ms);
  }

  if (velocityMeasurementWindow != null) {
    talon.SetVelocityMeasurementWindow(velocityMeasurementWindow);
  } else {
    talon.SetVelocityMeasurementWindow(64);
  }

  LimitSwitch fls = forwardLimitSwitch != null ? forwardLimitSwitch : LimitSwitch.DEFAULT;
  LimitSwitch rls = reverseLimitSwitch != null ? reverseLimitSwitch : LimitSwitch.DEFAULT;
  talon.enableLimitSwitch(fls.isEnabled(), rls.isEnabled());
  if (fls.isEnabled()) {
    talon.ConfigFwdLimitSwitchNormallyOpen(fls.isNormallyOpen());
  }
  if (rls.isEnabled()) {
    talon.ConfigRevLimitSwitchNormallyOpen(rls.isNormallyOpen());
  }

  SoftLimit sl = forwardSoftLimit != null ? forwardSoftLimit : SoftLimit.DEFAULT;
  talon.enableForwardSoftLimit(sl.isEnabled());
  if (sl.isEnabled()) {
    talon.setForwardSoftLimit(sl.getPosition());
  }
  sl = reverseSoftLimit != null ? reverseSoftLimit : SoftLimit.DEFAULT;
  talon.enableReverseSoftLimit(sl.isEnabled());
  if (sl.isEnabled()) {
    talon.setReverseSoftLimit(sl.getPosition());
  }
  if (currentLimit != null && currentLimit > 0) {
    talon.setCurrentLimit(currentLimit);
    talon.EnableCurrentLimit(true);
  } else {
    talon.EnableCurrentLimit(false);
  }
  talon.setVoltageRampRate(voltageRampRate != null ? voltageRampRate : 0);
  addTalonId(talon.getDeviceID());
}