Skip to content

Conversation

@calcmogul
Copy link
Member

@calcmogul calcmogul commented Dec 14, 2025

I left "free speed" alone since that's the technical term for it. In general, velocity is a vector quantity, and speed is a magnitude (i.e., a strictly positive value).

This PR also replaces the speed verbiage in MotorController with duty cycle.

Fixes #8423.

I left "free speed" alone since that's the technical term for it.

Fixes wpilibsuite#8423.
@calcmogul calcmogul requested review from a team as code owners December 14, 2025 07:29
@github-actions github-actions bot added component: wpilibj WPILib Java component: wpilibc WPILib C++ component: hal Hardware Abstraction Layer component: wpimath Math library component: glass Glass app and backend component: wpinet Networking library component: examples component: wpiunits Java units library 2027 2027 target labels Dec 14, 2025
@rzblue
Copy link
Member

rzblue commented Dec 14, 2025

I think the instances that refer to PWM output should be changed to something else- speed doesn't make sense, but velocity doesn't either.

@calcmogul
Copy link
Member Author

calcmogul commented Dec 14, 2025

This function in PWMMotorController seems to say it's a pulse time in microseconds whose range is normalized to [-1, 1].

  /**
   * Takes a speed from -1 to 1, and outputs it in the microsecond format.
   *
   * @param speed the speed to output
   */
  protected final void setSpeed(double speed) {
    if (Double.isFinite(speed)) {
      speed = Math.clamp(speed, -1.0, 1.0);
    } else {
      speed = 0.0;
    }

    if (m_simSpeed != null) {
      m_simSpeed.set(speed);
    }

    int rawValue;
    if (speed == 0.0) {
      rawValue = m_centerPwm;
    } else if (speed > 0.0) {
      rawValue = (int) Math.round(speed * getPositiveScaleFactor()) + getMinPositivePwm();
    } else {
      rawValue = (int) Math.round(speed * getNegativeScaleFactor()) + getMaxNegativePwm();
    }

    m_pwm.setPulseTimeMicroseconds(rawValue);
  }

Should it be time-related? I thought of duty cycle, but that doesn't quite make sense because it can be negative.

EDIT: I went with "duty cycle between -1 and 1 (sign indicates direction)".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2027 2027 target component: examples component: glass Glass app and backend component: hal Hardware Abstraction Layer component: wpilibc WPILib C++ component: wpilibj WPILib Java component: wpimath Math library component: wpinet Networking library component: wpiunits Java units library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants