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

[wpimath] ExponentialProfile doesn't enter the correct limit cycle for nonzero velocity goals #7760

Open
jwbonner opened this issue Feb 3, 2025 · 8 comments
Labels
component: wpimath Math library type: bug Something isn't working.

Comments

@jwbonner
Copy link
Member

jwbonner commented Feb 3, 2025

Under certain conditions, an exponential profile with a constant goal can produce oscillations that prevent it from finishing the profile. The graph below shows the position setpoint for one such profile.

Image

This behavior appears to be extremely sensitive to the initial inputs. The example below produces the issue consistently, but changing the goal velocity to 2.99999 or 3.00001 fixes the issue. It's not clear whether this might be related to using a nonzero goal velocity given how sensitive it is to the exact values.

ExponentialProfile profile = new ExponentialProfile(
    ExponentialProfile.Constraints.fromStateSpace(206.18996798292426, -4.0508214770151705, 0.07795421563066239));
ExponentialProfile.State state = new ExponentialProfile.State(0.1, 0.0);
ExponentialProfile.State goal = new ExponentialProfile.State(1.75, 3);

@Override
public void robotPeriodic() {
  SmartDashboard.putNumber("Position", state.position);
  SmartDashboard.putNumber("Velocity", state.velocity);
}

@Override
public void teleopPeriodic() {
  state = profile.calculate(0.02, state, goal);
}

This log includes the positions and velocities of the setpoints for the example above: exponentialprofilebug.wpilog.zip

Desktop (please complete the following information):

  • OS: macOS 15.2
  • Project Information:
WPILib Information:
Project Version: 2025.2.1
VS Code Version: 1.96.4
WPILib Extension Version: 2025.2.1
C++ Extension Version: 1.23.2
Java Extension Version: 1.38.0
Java Debug Extension Version: 0.58.1
Java Dependencies Extension Version 0.24.1
Java Version: 17
Java Location: /Users/jonah/wpilib/2025/jdk
Vendor Libraries:
@jwbonner jwbonner added the type: bug Something isn't working. label Feb 3, 2025
@calcmogul
Copy link
Member

calcmogul commented Feb 3, 2025

This is intended behavior. If you provide a constant goal with a nonzero velocity, the system will enter a limit cycle in phase space to hit the goal repeatedly. If you want the profile to reach steady-state, you should pass a zero velocity.

@calcmogul calcmogul closed this as not planned Won't fix, can't repro, duplicate, stale Feb 3, 2025
@jwbonner
Copy link
Member Author

jwbonner commented Feb 3, 2025

Why is the behavior entirely different with a velocity of 2.99999 and 3.00000 in that case? It seems like the resulting profile should be nearly identical in those cases.

@jwbonner
Copy link
Member Author

jwbonner commented Feb 3, 2025

After the initial movement, the profile also fails to reach the goal again afterwards (and doesn’t follow a normal cycle). If it cycles to hit the goal repeatedly, I would have expected both of those to be true.

@calcmogul
Copy link
Member

Could you be more specific about the behavior you saw instead of a limit cycle?

@calcmogul
Copy link
Member

A position vs velocity plot would be much more informative than a time domain plot.

@jwbonner
Copy link
Member Author

jwbonner commented Feb 3, 2025

This is with a setpoint of 2.99999:

Image

And with a setpoint of 3.00000:

Image

I marked the goal with a red X on both plots.

@jwbonner
Copy link
Member Author

jwbonner commented Feb 3, 2025

(The first example is stable after it reaches the goal)

@calcmogul calcmogul reopened this Feb 3, 2025
@calcmogul calcmogul changed the title [wpimath] ExponentialProfile can produce oscillating setpoints [wpimath] ExponentialProfile doesn't enter the correct limit cycle for nonzero velocity goals Feb 3, 2025
@calcmogul
Copy link
Member

calcmogul commented Feb 3, 2025

It shouldn't be stable tho, because it's not physically possible to stay at a given position-velocity pair in steady-state when that velocity is nonzero; the nonzero velocity necessarily makes the position diverge.

@calcmogul calcmogul added the component: wpimath Math library label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: wpimath Math library type: bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

2 participants