Example #1
0
  /**
   * Set the PWM value based on a speed.
   *
   * <p>This is intended to be used by speed controllers.
   *
   * @pre SetMaxPositivePwm() called.
   * @pre SetMinPositivePwm() called.
   * @pre SetCenterPwm() called.
   * @pre SetMaxNegativePwm() called.
   * @pre SetMinNegativePwm() called.
   * @param speed The speed to set the speed controller between -1.0 and 1.0.
   */
  final void setSpeed(double speed) {
    // clamp speed to be in the range 1.0 >= speed >= -1.0
    if (speed < -1.0) {
      speed = -1.0;
    } else if (speed > 1.0) {
      speed = 1.0;
    }

    // // calculate the desired output pwm value by scaling the speed
    // appropriately
    // int rawValue;
    // if (speed == 0.0) {
    // rawValue = getCenterPwm();
    // } else if (speed > 0.0) {
    // rawValue =
    // (int) (speed * ((double) getPositiveScaleFactor()) + ((double)
    // getMinPositivePwm()) + 0.5);
    // } else {
    // rawValue =
    // (int) (speed * ((double) getNegativeScaleFactor()) + ((double)
    // getMaxNegativePwm()) + 0.5);
    // }
    //
    // // send the computed pwm value to the FPGA
    // setRaw(rawValue);

    // The above is too complicated to simulate, just fake it
    PWMJNI.__setPWM(m_port, speed);
  }