|
20 | 20 | import com.ctre.phoenix6.swerve.SwerveRequest.ForwardPerspectiveValue; |
21 | 21 |
|
22 | 22 | import edu.wpi.first.math.MathUtil; |
| 23 | +import edu.wpi.first.math.Matrix; |
23 | 24 | import edu.wpi.first.math.VecBuilder; |
24 | 25 | import edu.wpi.first.math.geometry.Pose2d; |
25 | 26 | import edu.wpi.first.math.geometry.Rotation2d; |
26 | 27 | import edu.wpi.first.math.geometry.Transform2d; |
27 | 28 | import edu.wpi.first.math.geometry.Translation2d; |
28 | 29 | import edu.wpi.first.math.kinematics.ChassisSpeeds; |
| 30 | +import edu.wpi.first.math.numbers.N1; |
| 31 | +import edu.wpi.first.math.numbers.N3; |
29 | 32 | import edu.wpi.first.math.trajectory.TrapezoidProfile; |
30 | 33 | import edu.wpi.first.units.Units; |
31 | 34 | import edu.wpi.first.wpilibj.DriverStation; |
@@ -681,20 +684,47 @@ public void limeLightSetup() { |
681 | 684 | "limelight1", s_drivetrain.getState().Pose.getRotation().getDegrees(), 0, 0, 0, 0, 0); |
682 | 685 | } |
683 | 686 |
|
| 687 | + |
| 688 | + |
| 689 | + /** |
| 690 | + * Reset the pose of the Quest to the robot's position while disabled |
| 691 | + */ |
684 | 692 | public void questNavReset() { |
685 | 693 | Pose2d robotPose = getPose(); |
686 | 694 | Pose2d questPose = robotPose.transformBy(ROBOT_TO_QUEST); |
687 | 695 | m_quest.setPose(questPose); |
688 | 696 | } |
689 | 697 |
|
690 | | - public void getQuestNavPose() { |
| 698 | + /** |
| 699 | + * Get the pose of the robot through the Quest |
| 700 | + * @return Pose the Quest is reporting of the robot |
| 701 | + */ |
| 702 | + public Pose2d getQuestNavPose() { |
691 | 703 | if (m_quest.isConnected() && m_quest.isTracking()) { |
692 | 704 | Pose2d questPose = m_quest.getPose(); |
693 | 705 | Pose2d robotPose = questPose.transformBy(ROBOT_TO_QUEST.inverse()); |
694 | 706 | Logger.recordOutput(getName() + "Drive/actualQuestRobotPose", robotPose); |
| 707 | + return robotPose; |
| 708 | + } |
| 709 | + return null; |
| 710 | + } |
| 711 | + |
| 712 | + /** |
| 713 | + * Add the measurement of the quest's pose to the drivetrain's reported pose |
| 714 | + */ |
| 715 | + public void addQuestMeasurement() { |
| 716 | + //Trust QuestNav for 2 cm x and y, and 2 degrees rotational |
| 717 | + Matrix<N3, N1> QUESTNAV_STD_DEVS = VecBuilder.fill(0.02, 0.02, 0.035); |
| 718 | + |
| 719 | + if (m_quest.isConnected() && m_quest.isTracking()) { |
| 720 | + Pose2d quest_pose = getQuestNavPose(); |
| 721 | + double quest_timestamp = m_quest.getDataTimestamp(); |
| 722 | + s_drivetrain.addVisionMeasurement(quest_pose, quest_timestamp, QUESTNAV_STD_DEVS); |
695 | 723 | } |
696 | 724 | } |
697 | 725 |
|
| 726 | + |
| 727 | + |
698 | 728 | @Override |
699 | 729 | public void periodic() { |
700 | 730 |
|
@@ -761,6 +791,7 @@ public void periodic() { |
761 | 791 | s_drivetrain.getModule(i).getDriveMotor().getMotorVoltage().getValue()); |
762 | 792 | } |
763 | 793 | LoopTimer.addTimestamp(getName() + " End"); |
| 794 | + |
764 | 795 | } |
765 | 796 |
|
766 | 797 | @Override |
|
0 commit comments