[examples] Use ADXRS450_GyroSim class in simulation example (#2964)

This class did not exist when the original example was written. This
also changes the C++ example to use ADXRS450_Gyro for the sake of
consistency.
This commit is contained in:
Prateek Machiraju
2020-12-24 18:42:46 -05:00
committed by GitHub
parent 9962f6fd79
commit 4e34f05238
3 changed files with 11 additions and 17 deletions

View File

@@ -52,8 +52,7 @@ void DriveSubsystem::SimulationPeriodic() {
m_drivetrainSimulator.GetRightPosition().to<double>());
m_rightEncoderSim.SetRate(
m_drivetrainSimulator.GetRightVelocity().to<double>());
m_gyroAngleSim.SetAngle(
-m_drivetrainSimulator.GetHeading().Degrees().to<double>());
m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees());
}
units::ampere_t DriveSubsystem::GetCurrentDraw() const {

View File

@@ -7,14 +7,14 @@
#pragma once
#include <frc/AnalogGyro.h>
#include <frc/ADXRS450_Gyro.h>
#include <frc/Encoder.h>
#include <frc/PWMVictorSPX.h>
#include <frc/SpeedControllerGroup.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/geometry/Pose2d.h>
#include <frc/kinematics/DifferentialDriveOdometry.h>
#include <frc/simulation/AnalogGyroSim.h>
#include <frc/simulation/ADXRS450_GyroSim.h>
#include <frc/simulation/DifferentialDrivetrainSim.h>
#include <frc/simulation/EncoderSim.h>
#include <frc/smartdashboard/Field2d.h>
@@ -154,7 +154,7 @@ class DriveSubsystem : public frc2::SubsystemBase {
DriveConstants::kRightEncoderPorts[1]};
// The gyro sensor
frc::AnalogGyro m_gyro{0};
frc::ADXRS450_Gyro m_gyro;
// Odometry class for tracking robot pose
frc::DifferentialDriveOdometry m_odometry{m_gyro.GetRotation2d()};
@@ -170,7 +170,7 @@ class DriveSubsystem : public frc2::SubsystemBase {
frc::sim::EncoderSim m_leftEncoderSim{m_leftEncoder};
frc::sim::EncoderSim m_rightEncoderSim{m_rightEncoder};
frc::sim::AnalogGyroSim m_gyroAngleSim{m_gyro};
frc::sim::ADXRS450_GyroSim m_gyroSim{m_gyro};
// The Field2d class shows the field in the sim GUI.
frc::Field2d m_fieldSim;