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

LinearSystemSim Constructor and method cleanup #6502

Merged
merged 16 commits into from May 15, 2024

Conversation

narmstro2020
Copy link
Contributor

@narmstro2020 narmstro2020 commented Apr 5, 2024

Modified Java constructors to take a variable number of measurement std devs argument with checks in place to make sure the right amount (or none) are passed into the constructor. All changes passed down to classes utilizing LinearSystemSim.
Removed excess constructors

Removed Java and C++ CurrentDrawAmps method as it doesn't belong in a generic (non electrical) linear system. Kept a non override version in all derived electrical classes.

EDIT: Also LinearSystemSim has now been made agnostic to electrical systems. Inputs don't have to be voltage. BatteryVoltage clamp function has been pushed down to electrical subclasses.

@narmstro2020 narmstro2020 requested review from a team as code owners April 5, 2024 15:12
Copy link
Contributor

@spacey-sooty spacey-sooty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can run /format to fix the formatting if you want

@narmstro2020
Copy link
Contributor Author

/format

@spacey-sooty
Copy link
Contributor

Your build seems to be failing because the exponential elevator sim example is broken

@narmstro2020
Copy link
Contributor Author

That's weird because I didn't modify any of the exponential elevator sim example code

@spacey-sooty
Copy link
Contributor

That's weird because I didn't modify any of the exponential elevator sim example code

It'll just be because you modified constructors or methods it used prolly

@narmstro2020
Copy link
Contributor Author

So I replaced in the C++ version GetBatteryVoltage with a hardcoded 12.0 and that made the linux and macos builds complete

Copy link
Contributor

@spacey-sooty spacey-sooty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this 12 being passed into a lot of the constructors, should that be made some kind of constant? Why is that number chosen?

wpilibc/src/main/native/cpp/simulation/DCMotorSim.cpp Outdated Show resolved Hide resolved
wpilibc/src/main/native/cpp/simulation/ElevatorSim.cpp Outdated Show resolved Hide resolved
wpilibc/src/main/native/cpp/simulation/FlywheelSim.cpp Outdated Show resolved Hide resolved
wpilibc/src/main/native/cpp/simulation/DCMotorSim.cpp Outdated Show resolved Hide resolved
@narmstro2020
Copy link
Contributor Author

/format

2 similar comments
@narmstro2020
Copy link
Contributor Author

/format

@narmstro2020
Copy link
Contributor Author

/format

@calcmogul
Copy link
Member

/format

@narmstro2020
Copy link
Contributor Author

narmstro2020 commented Apr 8, 2024

@calcmogul
I'm sorry I think I missed something between comment discussion threads that didn't make it
into the last update. Do you know what I missed?

EDIT: I found my mistake.

I ran a local build with 6_V and the test still failed and on Windows this time

@narmstro2020
Copy link
Contributor Author

/format

@calcmogul
Copy link
Member

calcmogul commented Apr 9, 2024

We can either use a 1% tolerance, disable current draw to get exact numbers, or figure out how to properly compensate the sim. I'd prefer the third, but idk how to do it.

@narmstro2020
Copy link
Contributor Author

narmstro2020 commented Apr 9, 2024

What about this at line 44
EXPECT_NEAR((gearbox.Kv * sim.GetInput()[0]).value(), encoder.GetRate(), 0.1);

EDIT: The test passes, but does this solution stay true to the purpose of the test

@narmstro2020
Copy link
Contributor Author

/format

@narmstro2020
Copy link
Contributor Author

What's failing on the CMake Mac OS build

@narmstro2020
Copy link
Contributor Author

/format

@narmstro2020
Copy link
Contributor Author

Okay. So I reverted DCMotorSimTest.cpp to its original state.
The ClampInput function is inside of LinearSystemSim, but called inside the subclasses.
This seems to have removed the issues with the test failing... somehow

@calcmogul calcmogul added the breaking Introduces a breaking change. label Apr 10, 2024
@calcmogul calcmogul changed the base branch from main to development April 10, 2024 00:16
Copy link
Member

@calcmogul calcmogul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the target branch to development since there's API breaking changes in this PR. Please rebase against development (e.g., git rebase -i development).

wpilibc/src/main/native/cpp/simulation/DCMotorSim.cpp Outdated Show resolved Hide resolved
@narmstro2020
Copy link
Contributor Author

/format

Copy link
Member

@calcmogul calcmogul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the clamping was moved out of LinearSystemSim because the input isn't necessarily voltage.

@narmstro2020
Copy link
Contributor Author

I think I've got everything back and in good shape w.r.t. the branch rebase and overall state.

@narmstro2020
Copy link
Contributor Author

Looks like the clamping was moved out of LinearSystemSim because the input isn't necessarily voltage.

I'm sorry I didn't answer this sooner. That is the basic idea. getCurrentDraw was also moved for similar reasons.

@narmstro2020
Copy link
Contributor Author

Should I merge current state of main into this or are there other concerns in this PR since it's been marked breaking?

@calcmogul
Copy link
Member

calcmogul commented May 12, 2024

The breaking label means there's breaking changes to either the API or user-visible behavior. We use that label to track what to add to the next release's breaking changes list.

calcmogul
calcmogul previously approved these changes May 12, 2024
Copy link
Member

@calcmogul calcmogul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The breaking changes are:

  1. The measurement standard deviations vector constructor argument was replaced with varargs in Java for improved ergonomics and performance. C++ is unchanged.
  2. LinearSystemSim's input clamping was moved to the derived class since the base class doesn't know the input limits; it just assumed 12.

@narmstro2020
Copy link
Contributor Author

Ah okay. I'm sorry to pester. This had just been sitting for a week and if there were any changes to be made I wanted to make them when I had the free time.

Thank you

@PeterJohnson
Copy link
Member

Some merge conflicts to fix up.

@narmstro2020
Copy link
Contributor Author

narmstro2020 commented May 15, 2024

All Merge conflicts merged
EDIT: Sorry now they are merged.

narmstro2020 and others added 3 commits May 15, 2024 11:25
…rSimTest.java

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
…rmsimulation/subsystems/Arm.java

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
@narmstro2020
Copy link
Contributor Author

/format

…rSimTest.java

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
@PeterJohnson PeterJohnson merged commit ab315e2 into wpilibsuite:main May 15, 2024
25 checks passed
@narmstro2020 narmstro2020 deleted the FurtherLinearSystemSimSimp branch May 16, 2024 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Introduces a breaking change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants