Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DutyCycleEncoder.setDistance(distance) sets rotations rather than distance #5245

Closed
GLRoylance opened this issue Mar 28, 2023 · 1 comment
Closed

Comments

@GLRoylance
Copy link

Describe the bug
dutyCycleEncoderSim.setDistance(distance) does not set the distance but rather rotations.

To Reproduce
Steps to reproduce the behavior:
Here is a JUnit 5 unit test that fails

/**
 * Consolidated duty cycle encoder test.
 */
@Test
public void testDutyCycleEncoder() {
    int channel = 15;
    DutyCycleEncoder dceEncoder = new DutyCycleEncoder(channel);
    DutyCycleEncoderSim dceSim = new DutyCycleEncoderSim(dceEncoder);

    // "2023.4.2"
    System.out.println(WPILibVersion.Version);

    double gain = 3.0;
    dceEncoder.setDistancePerRotation(gain);

    double rotations = 1.0;

    System.out.println("dceSim.set() works");
    dceSim.set(rotations);
    // 1.0
    System.out.printf(" dceEncoder.get()         = %8f\n", dceEncoder.get());
    // 3.0
    System.out.printf(" dceEncoder.getDistance() = %8f\n", dceEncoder.getDistance());
    assertEquals(rotations, dceEncoder.get(), 0.001);
    assertEquals(rotations * gain, dceEncoder.getDistance(), 0.001);

    System.out.println("dceSim.setDistance() fails");
    dceSim.setDistance(rotations * gain);
    // 3.0
    System.out.printf(" dceEncoder.get()         = %8f\n", dceEncoder.get());
    // 9.0
    System.out.printf(" dceEncoder.getDistance() = %8f\n", dceEncoder.getDistance());
    assertEquals(rotations, dceEncoder.get(), 0.001);
    assertEquals(rotations * gain, dceEncoder.getDistance(), 0.001);

    dceEncoder.close();
}

Expected behavior
A clear and concise description of what you expected to happen.

If I set the distance with
dceEncoderSim.setDistance(3.0)

then I expect
dceEncoder.getDistance() to return 3; instead it returns 9.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • WPILib Version: [e.g. 2021.3.1] "2023.4.2"
  • OS: [e.g. Windows 11] Windows 11
  • Java version [e.g. 1.10.2] JavaVersion.VERSION_11 in build.gradle
  • C++ version [e.g. 17]

Additional context
Add any other context about the problem here.

@rzblue
Copy link
Member

rzblue commented Mar 28, 2023

This was fixed in #5147, will be included in the latest release soon.

@rzblue rzblue closed this as completed Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants