-
Notifications
You must be signed in to change notification settings - Fork 613
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
Make SimpleMotorFeedforward only support discrete feedforward #6647
Make SimpleMotorFeedforward only support discrete feedforward #6647
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring fields in the constructor that some use cases may never use is a code smell. RobotDrive used to be like that; it didn't know what kind of drivetrain it wanted to be, so it took all motors and figured out validation at runtime.
In this case, the class doesn't know whether it wants to be continuous or discrete. At least the API on main doesn't ask for stuff it doesn't use. This PR's refactor would really make more sense as two separate classes, tho I don't like that either; everything teams do is discrete, not continuous.
@calcmogul So is there any value in leaving the continuous overload in the class at all? EDIT: I can put the equation in as a comment if it isn't there already just for reference. |
Something more like this? |
Just wanted to check up on this PR. Haven't received any other feedback in awhile. Should I close it or make modifications? |
wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java
Outdated
Show resolved
Hide resolved
/format |
wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java
Outdated
Show resolved
Hide resolved
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ExponentialProfileTest { | ||
private static final double kDt = 0.01; | ||
private static final SimpleMotorFeedforward feedforward = | ||
new SimpleMotorFeedforward(0, 2.5629, 0.43277); | ||
new SimpleMotorFeedforward(0, 2.5629, 0.43277, 0.01); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the kDt constant instead of hardcoding it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oof
So I believe I have a first draft of the C++ SimpleMotorFeedforward. I've yet to change the tests and other dependent classes. I also removed the field for the Java class for plant as it wasn't necessary to keep. Will work on tomorrow and add any feedback from here as well. |
/format |
/format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a bunch of places where the "current velocity" of the feedforward is set to a measurement instead of the current or previous setpoint. For cases where the setpoint is constant, you can just use the same value for both the "current velocity" and "next velocity".
wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp
Outdated
Show resolved
Hide resolved
/format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't all of them, but you get the idea. Look for instances of "Setpoint" and "Encoder" in the same line.
wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/SysId/cpp/subsystems/Shooter.cpp
Outdated
Show resolved
Hide resolved
.../src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java
Outdated
Show resolved
Hide resolved
...ain/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/subsystems/DriveSubsystem.java
Outdated
Show resolved
Hide resolved
@calcmogul Other than that I've fixed all of the examples and tests that you've indicated and I double checked the list myself. |
/format |
@calcmogul |
That seems reasonable. The API doc for that overload can mention that it's for when the reference doesn't change continuously. |
@calcmogul |
You could remove the default argument and provide two separate overloads: a non-deprecated one-arg (velocity) version and a deprecated two-arg (velocity, acceleration) version. |
@calcmogul |
This PR sets period as a constructor argument along with adding another constructor overload to accomodate.
The constructor now creates the feedforward, plant, r and nextR variables used by the calculate(current, next, dtSeconds) overload.
The calculate(current, next, dtSeconds) overload is now calculateDiscrete(current, next).
The calculate(velocity, acceleration) overload is not calculateContinuous(velocity, acceleration).
The calculate(velocity) overload is unchanged.
I'm not married to these name changes.
I will eventually move on to Elevator and Arm and C++ for all 3 based on the feedback I receive.