[examples] Update Field2d position in periodic() (#2928)

This ensures that the robot position will be updated in dashboards like Glass when running on real hardware.
This commit is contained in:
Prateek Machiraju
2020-12-10 23:36:20 -05:00
committed by GitHub
parent f78d1d4340
commit 65219f3093
7 changed files with 18 additions and 9 deletions

View File

@@ -22,6 +22,7 @@ DriveSubsystem::DriveSubsystem() {
m_rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
ResetEncoders();
frc::SmartDashboard::PutData("Field", &m_fieldSim);
}
void DriveSubsystem::Periodic() {
@@ -29,6 +30,7 @@ void DriveSubsystem::Periodic() {
m_odometry.Update(m_gyro.GetRotation2d(),
units::meter_t(m_leftEncoder.GetDistance()),
units::meter_t(m_rightEncoder.GetDistance()));
m_fieldSim.SetRobotPose(m_odometry.GetPose());
}
void DriveSubsystem::SimulationPeriodic() {
@@ -52,9 +54,6 @@ void DriveSubsystem::SimulationPeriodic() {
m_drivetrainSimulator.GetRightVelocity().to<double>());
m_gyroAngleSim.SetAngle(
-m_drivetrainSimulator.GetHeading().Degrees().to<double>());
m_fieldSim.SetRobotPose(m_odometry.GetPose());
frc::SmartDashboard::PutData("Field", &m_fieldSim);
}
units::ampere_t DriveSubsystem::GetCurrentDraw() const {