-
Notifications
You must be signed in to change notification settings - Fork 0
Velocity imu test -> master #262
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
base: master
Are you sure you want to change the base?
Changes from all commits
bee6eab
d3728c6
8e4127f
d9f021c
5507fee
d0fa855
355c52c
8ab2655
dfda236
493e27f
c1b7487
267a338
b2ae6bf
f17802e
4ea7c30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,18 +8,18 @@ | |
| import edu.wpi.first.math.geometry.Pose2d; | ||
| import edu.wpi.first.math.geometry.Twist2d; | ||
| import edu.wpi.first.math.interpolation.TimeInterpolatableBuffer; | ||
| import edu.wpi.first.math.kinematics.SwerveDriveKinematics; | ||
| import edu.wpi.first.math.kinematics.SwerveModulePosition; | ||
| import edu.wpi.first.math.kinematics.Odometry; | ||
| import edu.wpi.first.math.kinematics.SwerveModuleState; | ||
| import edu.wpi.first.math.kinematics.*; | ||
|
DanielShapir marked this conversation as resolved.
|
||
| import edu.wpi.first.math.numbers.N1; | ||
| import edu.wpi.first.math.numbers.N3; | ||
| import frc.robot.vision.RobotPoseObservation; | ||
| import frc.robot.poseestimator.IPoseEstimator; | ||
| import frc.robot.poseestimator.OdometryData; | ||
| import frc.utils.TimedValue; | ||
| import frc.utils.buffers.RingBuffer.RingBuffer; | ||
| import frc.utils.math.StatisticsMath; | ||
| import frc.utils.math.ToleranceMath; | ||
| import frc.utils.pose.PoseUtil; | ||
| import frc.utils.time.TimeUtil; | ||
| import org.littletonrobotics.junction.Logger; | ||
|
|
||
| import java.util.Optional; | ||
|
|
@@ -33,7 +33,9 @@ public class WPILibPoseEstimatorWrapper implements IPoseEstimator { | |
| private final RingBuffer<Rotation2d> poseToIMUYawDifferenceBuffer; | ||
| private final TimeInterpolatableBuffer<Rotation2d> imuYawBuffer; | ||
| private final TimeInterpolatableBuffer<Translation2d> imuXYAccelerationGBuffer; | ||
| private RobotPoseObservation lastVisionObservation; | ||
| private final TimedValue<Pose2d> lastEstimatedPose; | ||
| private final TimedValue<ChassisSpeeds> lastEstimatedVelocity; | ||
| private RobotPoseObservation lastVisionObservation; | ||
| private OdometryData lastOdometryData; | ||
| private boolean isIMUOffsetCalibrated; | ||
|
|
||
|
|
@@ -72,9 +74,10 @@ public WPILibPoseEstimatorWrapper( | |
| this.imuYawBuffer = TimeInterpolatableBuffer.createBuffer(WPILibPoseEstimatorConstants.IMU_YAW_BUFFER_SIZE_SECONDS); | ||
| this.imuXYAccelerationGBuffer = TimeInterpolatableBuffer | ||
| .createBuffer(WPILibPoseEstimatorConstants.IMU_XY_ACCELERATION_G_BUFFER_SIZE_SECONDS); | ||
| this.lastEstimatedPose = new TimedValue<>(new Pose2d(), initialTimestampSeconds); | ||
| this.lastEstimatedVelocity = new TimedValue<>(new ChassisSpeeds(), initialTimestampSeconds); | ||
| } | ||
|
|
||
|
DanielShapir marked this conversation as resolved.
|
||
|
|
||
| @Override | ||
| public Pose2d getEstimatedPose() { | ||
| return poseEstimator.getEstimatedPosition(); | ||
|
|
@@ -131,6 +134,38 @@ public void updateVision(RobotPoseObservation... visionRobotPoseObservations) { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void updateLastEstimatedPose() { | ||
| double timestamp = TimeUtil.getCurrentTimeSeconds(); | ||
| double deltaTime = timestamp - lastEstimatedVelocity.getTimestamp(); | ||
| if (deltaTime > 0) { | ||
| Pose2d currentPose = getEstimatedPose(); | ||
| ChassisSpeeds rawVelocity = new ChassisSpeeds( | ||
| (currentPose.getX() - lastEstimatedPose.getValue().getX()) / deltaTime, | ||
| (currentPose.getY() - lastEstimatedPose.getValue().getY()) / deltaTime, | ||
| (currentPose.getRotation().getRadians() - lastEstimatedPose.getValue().getRotation().getRadians()) / deltaTime | ||
| ); | ||
|
|
||
| if (ToleranceMath.isNear(new ChassisSpeeds(), rawVelocity, WPILibPoseEstimatorConstants.ESTIMATED_VELOCITY_TOLERANCE)) { | ||
| lastEstimatedVelocity.setValue(new ChassisSpeeds()); | ||
|
Comment on lines
+149
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0.5 m/s is a very high deadband for this
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but its the deadband for skid detection There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do want to have an accurate velocity either way. You have the check of wether to use it in another function |
||
| } else if ( | ||
| ToleranceMath.isNear(lastEstimatedVelocity.getValue(), rawVelocity, WPILibPoseEstimatorConstants.ESTIMATED_VELOCITY_TOLERANCE) | ||
| ) { | ||
| lastEstimatedVelocity.setValue( | ||
| new ChassisSpeeds( | ||
| (rawVelocity.vxMetersPerSecond + lastEstimatedVelocity.getValue().vxMetersPerSecond) / 2.0, | ||
| (rawVelocity.vyMetersPerSecond + lastEstimatedVelocity.getValue().vyMetersPerSecond) / 2.0, | ||
| (rawVelocity.omegaRadiansPerSecond + lastEstimatedVelocity.getValue().omegaRadiansPerSecond) / 2.0 | ||
| ) | ||
| ); | ||
| } | ||
|
Comment on lines
+151
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why avarege the velocities if they're close? |
||
| // If neither condition is met, it is a massive vision spike. We do NOT update the value, preserving the safe velocity. | ||
| lastEstimatedVelocity.setTimestamp(timestamp); | ||
|
Comment on lines
+162
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you're filtering spikes you should do it by acceleration and not by velocity |
||
| } | ||
| lastEstimatedPose.setTimestamp(timestamp); | ||
| lastEstimatedPose.setValue(getEstimatedPose()); | ||
| } | ||
|
|
||
| @Override | ||
| public void resetPose(OdometryData odometryData, Pose2d poseMeters) { | ||
| Logger.recordOutput(logPath + "/lastPoseResetTo", poseMeters); | ||
|
|
@@ -226,6 +261,10 @@ private void updateVision(RobotPoseObservation visionRobotPoseObservation) { | |
| }); | ||
| } | ||
|
|
||
| public ChassisSpeeds getLastEstimatedVelocity() { | ||
| return lastEstimatedVelocity.getValue(); | ||
| } | ||
|
|
||
| private void addVisionMeasurement(RobotPoseObservation visionObservation) { | ||
| poseEstimator.addVisionMeasurement( | ||
| visionObservation.robotPose(), | ||
|
|
@@ -262,4 +301,16 @@ private Optional<Rotation2d> getEstimatedPoseToIMUYawDifference(Optional<Rotatio | |
| .flatMap(estimatedPose -> gyroYaw.map(yaw -> estimatedPose.getRotation().minus(yaw))); | ||
| } | ||
|
|
||
| @Override | ||
| public ChassisSpeeds getFieldRelativeEstimatedVelocity(ChassisSpeeds swerveVelocity) { | ||
| if (useEstimatedVelocity(swerveVelocity, lastEstimatedVelocity.getValue())) { | ||
| return lastEstimatedVelocity.getValue(); | ||
| } | ||
| return swerveVelocity; | ||
| } | ||
|
Comment on lines
+305
to
+310
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ternary |
||
|
|
||
| private boolean useEstimatedVelocity(ChassisSpeeds swerveVelocity, ChassisSpeeds estimatedVelocity) { | ||
| return !ToleranceMath.isNear(swerveVelocity, estimatedVelocity, WPILibPoseEstimatorConstants.ESTIMATED_VELOCITY_TOLERANCE); | ||
| } | ||
|
Comment on lines
+305
to
+314
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to separate to two functions |
||
|
|
||
|
DanielShapir marked this conversation as resolved.
|
||
| } | ||
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.
add logs