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

ElevatorSim output is not initially valid (until update has been called) #7761

Open
chauser opened this issue Feb 3, 2025 · 1 comment
Open
Labels
component: wpilibc WPILib C++ component: wpilibj WPILib Java good first issue Good for newcomers. os: simulation type: bug Something isn't working.

Comments

@chauser
Copy link
Contributor

chauser commented Feb 3, 2025

Describe the bug
Immediately after creating an ElevatorSim with non-zero starting position, a call to getPositionInMeters returns 0. I have not investigated whether other mechanism Sim classes are also affected. The problem may be even more general in that ElevatorSim uses LinearSystemSim.setState to put the starting position into the state, but setState does not update the Y matrix (outputs) to correspond. It is unclear to me whether it would be desirable (or even possible) for it to do so.

To Reproduce


       LinearSystem<N2, N1, N2> elsys = LinearSystemId.createElevatorSystem(
            DCMotor.getFalcon500(2), 
            4.0, 
            0.02, 
            9.0);
            
        // the only thing here that is essential for illustrating the behavior is that the field containing -0.05 is non-zero.
        ElevatorSim m_elevatorSim = new ElevatorSim(
            elsys,
            DCMotor.getFalcon500(2),
            0.0,
            1.15,
            true,
            -0.05
        );

        double initialPos = m_elevatorSim.getPositionMeters();

Observe initialPos is 0.0 when it should be -0.05.

Expected behavior
Calling getPositionInMeters returns the correct position at all times after construction. If that is not possible then the behavior should be documented (though that is much less desirable in my opinion).

  • Project Information:
    WPILib Information:
    Project Version: 2025.2.1
    VS Code Version: 1.94.2
    WPILib Extension Version: 2025.2.1
    C++ Extension Version: 1.23.2
    Java Extension Version: 1.38.0
    Java Debug Extension Version: 0.58.2024090204
    Java Dependencies Extension Version 0.24.1
    Java Version: 17
    Java Location: /home/hauser/wpilib/2025/jdk
    Vendor Libraries:
    PathplannerLib (2025.2.1)
    CTRE-Phoenix (v5) (5.35.1)
    CTRE-Phoenix (v6) (25.2.1)
    REVLib (2025.0.2)
    ReduxLib (2025.0.1)
    Studica (2025.0.1)
    ThriftyLib (2025.0.1)
    WPILib-New-Commands (1.0.0)
    maplesim (0.3.1)
    photonlib (v2025.1.1)

Additional context
Workaround: call update on the ElevatorSim object immediately after construction.

@chauser chauser added the type: bug Something isn't working. label Feb 3, 2025
@chauser chauser changed the title ElevatorSim output state is not initially valid (until update has been called) ElevatorSim output is not initially valid (until update has been called) Feb 3, 2025
@calcmogul
Copy link
Member

calcmogul commented Feb 3, 2025

Yea, we could just call the measurement model in the constructor of all the sim physics classes. We may need to add that to setState() to maintain the invariant that the state and measurement match up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: wpilibc WPILib C++ component: wpilibj WPILib Java good first issue Good for newcomers. os: simulation type: bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

2 participants