frc2609 / Crescendo-2024

Robot code for Crescendo 2024.
Other
1 stars 0 forks source link

Resetting odometry angle breaks heading control. #17

Closed UserC2 closed 7 months ago

UserC2 commented 8 months ago

Bug Description Resetting odometry to any angle other than 0 causes heading to believe that angle is 0.

Steps to Reproduce

  1. Call RobotContainer.drive.drive.resetOdometry() with a Pose2D with a non-zero rotation (e.g. 90 degrees)
  2. Attempt to drive the robot with heading or flick stick control (e.g. command it to a heading of 0 degrees).
  3. Observe the robot will go to an offset angle (e.g. will go to 90 degrees).

Expected Behavior

newjanson commented 8 months ago

Does heading velocity control still work?

UserC2 commented 8 months ago

It should be unaffected, as it doesn't take the robot's current angle into account.

newjanson commented 8 months ago

We should perhaps not use resetOdometry(). For localizing with apriltags, we use RobotContainer.drive.drive.swerveDrivePoseEstimator.addVisionMeasurement().

UserC2 commented 8 months ago

We should perhaps not use resetOdometry(). For localizing with apriltags, we use RobotContainer.drive.drive.swerveDrivePoseEstimator.addVisionMeasurement().

Reset odometry is used for PathPlanner to reset the pose of the robot when autonomous starts, not for vision measurements.

newjanson commented 8 months ago

ah, i see

UserC2 commented 7 months ago

Ok, I've figured out why this happens:

UserC2 commented 7 months ago

We can fix this in two ways:

The second method is ideal, since it still works when the Limelight fails and still works in simulation.

In summary: The current code works as expected. Remember to setup the robot in the correct place during autonomous (especially in simulation or when the Limelight doesn't work).

UserC2 commented 7 months ago

In simulation, make sure to zero the gyro before running an autonomous path, or the heading will be offset incorrectly (these instructions have been added to README.md).

UserC2 commented 7 months ago

Nevermind!

We are using SwerveDrive::getYaw() to get the heading in most commands (except PathPlanner and AlignToAmp), which never applies the gyro offset.

I will be changing that soon.

UserC2 commented 7 months ago

See c98ddf5