-
Notifications
You must be signed in to change notification settings - Fork 1
Jk collision detection - improving poseEstimation #285
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
Open
Mobby42
wants to merge
3
commits into
main
Choose a base branch
from
JK_collision_detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/frc/robot/commands/collision/CheckCollision.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package frc.robot.commands.collision; | ||
|
|
||
| import edu.wpi.first.math.MathUtil; | ||
| import frc.robot.constants.Constants; | ||
| import frc.robot.subsystems.gyro.ThreadedGyro; | ||
| import frc.robot.subsystems.swervev3.SwerveDrivetrain; | ||
| import frc.robot.utils.logging.commands.LoggableCommand; | ||
| import java.util.function.DoubleSupplier; | ||
|
|
||
| public class CheckCollision extends LoggableCommand { | ||
| private SwerveDrivetrain drivetrain; | ||
| private DoubleSupplier horizSupplier; | ||
| private final DoubleSupplier vertSupplier; | ||
| private ThreadedGyro accelerometer; | ||
| private double currentVelValue; | ||
| private double predictedVelValue; | ||
| private boolean trustOdometry; | ||
|
|
||
| public CheckCollision( | ||
| ThreadedGyro accelerometer, | ||
| SwerveDrivetrain drivetrain, | ||
| DoubleSupplier horizSupplier, | ||
| DoubleSupplier vertSupplier) { | ||
| this.drivetrain = drivetrain; | ||
| this.horizSupplier = horizSupplier; | ||
| this.vertSupplier = vertSupplier; | ||
| this.accelerometer = accelerometer; | ||
| trustOdometry = true; | ||
| addRequirements(drivetrain); | ||
| } | ||
|
|
||
| @Override | ||
| public void initialize() {} | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| double horizVal = -horizSupplier.getAsDouble(); | ||
| double vertVal = -vertSupplier.getAsDouble(); | ||
| double y = MathUtil.applyDeadband(horizVal, 0.05) * Constants.MAX_VELOCITY / 10; | ||
| double x = MathUtil.applyDeadband(vertVal, 0.05) * Constants.MAX_VELOCITY / 10; | ||
| currentVelValue = accelerometer.getVelocityValue(); | ||
| predictedVelValue = Math.sqrt(Math.pow(y, 2) + Math.pow(x, 2)); | ||
| if (Math.abs(currentVelValue - predictedVelValue) > Constants.COLLISION_VALUE) { | ||
| trustOdometry = false; | ||
| } | ||
| } | ||
|
|
||
| public boolean getTrustOdometry() { | ||
| return trustOdometry; | ||
| } | ||
|
|
||
| @Override | ||
| public void end(boolean interrupted) {} | ||
|
|
||
| @Override | ||
| public boolean isFinished() { | ||
| return false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 current math just checks the magnitude of the velocities; it would be interesting if we could instead use vectors, and after subtracting the two vectors, we could do the vector.norm method to find the magnitude of the vector and then see if that's greater than the collision value squared. Now that I am also obsessed with optimization, this can be improved even further if we change the constant to constants. Collision_Value_squared and do Vector.dot(Vector), which is more efficient as the square root is computationally expensive. Alternatively, we can also do the two velocity vectors (gyro and odometry) and also dot them together, which will scale with both of their magnitudes and the angle between them.
Uh oh!
There was an error while loading. Please reload this page.
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.
Should this apply deadband and have Max_Velocity as its third parameter instead? Also, why are we multiplying by Max_velocity /10? (This one i dont really know.)
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.
also branch needs to be tested.