4343import frc .robot .RobotContainer ;
4444import frc .robot .Telemetry ;
4545import frc .robot .generated .TunerConstants ;
46+ import gg .questnav .questnav .PoseFrame ;
4647import gg .questnav .questnav .QuestNav ;
4748
4849public class DriveSubsystem extends StateMachine implements AutoCloseable {
@@ -387,20 +388,7 @@ public void end(boolean interrupted) {
387388
388389 //Camera variables
389390 private static boolean s_leftCameraSeesTag = false ;
390- private static boolean s_rightCameraSeesTag = false ;
391-
392-
393- private static SwerveModulePosition [] imposterPositions = {null , null , null , null };
394- private static Matrix <N3 , N1 > imposter_drive_std_devs = VecBuilder .fill (1000000.0 , 1000000.0 , 100000.0 );
395- private static Matrix <N3 , N1 > imposter_vision_std_devs = VecBuilder .fill (0.01 , 0.01 , 0.01 );
396-
397- private static SwerveDrivePoseEstimator s_impostor = new SwerveDrivePoseEstimator (
398- s_drivetrain .getKinematics (),
399- s_drivetrain .getPigeon2 ().getRotation2d (),
400- imposterPositions ,
401- new Pose2d (0.0 ,0.0 , new Rotation2d (0.0 )),
402- imposter_drive_std_devs ,
403- imposter_vision_std_devs );
391+ private static boolean s_rightCameraSeesTag = false ;;
404392
405393
406394 protected final Thread m_limelight_thread ;
@@ -512,8 +500,6 @@ public void limelight_thread_func() {
512500 pose_estimate .pose , Utils .fpgaToCurrentTime (pose_estimate .timestampSeconds ));
513501 // Logger.recordOutput(getName() + "/" + limelight + "/botpose_orb", pose_estimate.pose);
514502
515- s_impostor .addVisionMeasurement (
516- pose_estimate .pose , Utils .fpgaToCurrentTime (pose_estimate .timestampSeconds ));
517503 }
518504 if (limelight == "limelight-left" ) {
519505 s_leftCameraSeesTag = !doRejectUpdate ;
@@ -718,11 +704,18 @@ public void questNavReset() {
718704 */
719705 public Pose2d getQuestNavPose () {
720706 if (m_quest .isConnected () && m_quest .isTracking ()) {
721- Pose2d questPose = m_quest .getPose ();
722- Pose2d robotPose = questPose .transformBy (ROBOT_TO_QUEST .inverse ());
707+ PoseFrame [] poseFrames = m_quest .getAllUnreadPoseFrames ();
708+ if (poseFrames .length > 0 ) {
709+ // Get the most recent Quest pose
710+ Pose2d questPose = poseFrames [poseFrames .length - 1 ].questPose ();
711+
712+ //Transform by the mount pose to get your robot pose
713+ Pose2d robotPose = questPose .transformBy (ROBOT_TO_QUEST .inverse ());
714+
723715 Logger .recordOutput (getName () + "Quest/actualQuestRobotPose" , robotPose );
724- Logger .recordOutput (getName () + "Quest/questBattery" , m_quest .getBatteryPercent ());
716+ Logger .recordOutput (getName () + "Quest/questBattery" , m_quest .getBatteryPercent (). getAsInt () );
725717 return robotPose ;
718+ }
726719 }
727720 return null ;
728721 }
@@ -731,14 +724,32 @@ public Pose2d getQuestNavPose() {
731724 * Add the measurement of the quest's pose to the drivetrain's reported pose
732725 */
733726 public void addQuestMeasurement () {
734- //Trust QuestNav for 2 cm x and y, and 2 degrees rotational
735- Matrix <N3 , N1 > QUESTNAV_STD_DEVS = VecBuilder .fill (0.00000000000000000000000000000000000000001 , 0.0000000000000000000000000000001 , 0.035 );
736-
737- if (m_quest .isConnected () && m_quest .isTracking () && DriverStation .isEnabled ()) {
738- Pose2d quest_pose = getQuestNavPose ();
739- double quest_timestamp = m_quest .getDataTimestamp ();
740- s_drivetrain .addVisionMeasurement (quest_pose , quest_timestamp , QUESTNAV_STD_DEVS );
741- s_impostor .addVisionMeasurement (quest_pose , quest_timestamp , QUESTNAV_STD_DEVS );
727+ Matrix <N3 , N1 > QUESTNAV_STD_DEVS =
728+ VecBuilder .fill (
729+ 0.02 , // Trust down to 2cm in X direction
730+ 0.02 , // Trust down to 2cm in Y direction
731+ 0.035 // Trust down to 2 degrees rotational
732+ );
733+
734+ if (m_quest .isTracking ()) {
735+ // Get the latest pose data frames from the Quest
736+ PoseFrame [] questFrames = m_quest .getAllUnreadPoseFrames ();
737+
738+ // Loop over the pose data frames and send them to the pose estimator
739+ for (PoseFrame questFrame : questFrames ) {
740+ // Get the pose of the Quest
741+ Pose2d questPose = questFrame .questPose ();
742+ // Get timestamp for when the data was sent
743+ double timestamp = questFrame .dataTimestamp ();
744+
745+ // Transform by the mount pose to get your robot pose
746+ Pose2d robotPose = questPose .transformBy (ROBOT_TO_QUEST .inverse ());
747+
748+ // You can put some sort of filtering here if you would like!
749+
750+ // Add the measurement to our estimator
751+ s_drivetrain .addVisionMeasurement (robotPose , timestamp , QUESTNAV_STD_DEVS );
752+ }
742753 };
743754 }
744755
@@ -778,7 +789,6 @@ public void periodic() {
778789
779790 m_quest .commandPeriodic ();
780791 getQuestNavPose ();
781- Logger .recordOutput (getName () + "Quest/ImpostorDrivePose" , s_impostor .getEstimatedPosition ());
782792
783793
784794
0 commit comments