Skip to content

Commit 029f95d

Browse files
committed
make questnav added to the overall pose estimate
1 parent 810c4a3 commit 029f95d

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/main/java/frc/robot/subsystems/drivetrain/DriveSubsystem.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
import com.ctre.phoenix6.swerve.SwerveRequest.ForwardPerspectiveValue;
2121

2222
import edu.wpi.first.math.MathUtil;
23+
import edu.wpi.first.math.Matrix;
2324
import edu.wpi.first.math.VecBuilder;
2425
import edu.wpi.first.math.geometry.Pose2d;
2526
import edu.wpi.first.math.geometry.Rotation2d;
2627
import edu.wpi.first.math.geometry.Transform2d;
2728
import edu.wpi.first.math.geometry.Translation2d;
2829
import edu.wpi.first.math.kinematics.ChassisSpeeds;
30+
import edu.wpi.first.math.numbers.N1;
31+
import edu.wpi.first.math.numbers.N3;
2932
import edu.wpi.first.math.trajectory.TrapezoidProfile;
3033
import edu.wpi.first.units.Units;
3134
import edu.wpi.first.wpilibj.DriverStation;
@@ -681,20 +684,47 @@ public void limeLightSetup() {
681684
"limelight1", s_drivetrain.getState().Pose.getRotation().getDegrees(), 0, 0, 0, 0, 0);
682685
}
683686

687+
688+
689+
/**
690+
* Reset the pose of the Quest to the robot's position while disabled
691+
*/
684692
public void questNavReset() {
685693
Pose2d robotPose = getPose();
686694
Pose2d questPose = robotPose.transformBy(ROBOT_TO_QUEST);
687695
m_quest.setPose(questPose);
688696
}
689697

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() {
691703
if (m_quest.isConnected() && m_quest.isTracking()) {
692704
Pose2d questPose = m_quest.getPose();
693705
Pose2d robotPose = questPose.transformBy(ROBOT_TO_QUEST.inverse());
694706
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);
695723
}
696724
}
697725

726+
727+
698728
@Override
699729
public void periodic() {
700730

@@ -761,6 +791,7 @@ public void periodic() {
761791
s_drivetrain.getModule(i).getDriveMotor().getMotorVoltage().getValue());
762792
}
763793
LoopTimer.addTimestamp(getName() + " End");
794+
764795
}
765796

766797
@Override

0 commit comments

Comments
 (0)