mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[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:
committed by
GitHub
parent
f78d1d4340
commit
65219f3093
@@ -60,6 +60,9 @@ void Drivetrain::SimulationPeriodic() {
|
||||
m_drivetrainSimulator.GetRightVelocity().to<double>());
|
||||
m_gyroSim.SetAngle(
|
||||
-m_drivetrainSimulator.GetHeading().Degrees().to<double>());
|
||||
}
|
||||
|
||||
void Drivetrain::Periodic() {
|
||||
UpdateOdometry();
|
||||
m_fieldSim.SetRobotPose(m_odometry.GetPose());
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ class Robot : public frc::TimedRobot {
|
||||
frc::TrajectoryConfig(2_mps, 2_mps_sq));
|
||||
}
|
||||
|
||||
void RobotPeriodic() override { m_drive.Periodic(); }
|
||||
|
||||
void AutonomousInit() override {
|
||||
m_timer.Reset();
|
||||
m_timer.Start();
|
||||
@@ -33,8 +35,6 @@ class Robot : public frc::TimedRobot {
|
||||
auto reference = m_trajectory.Sample(elapsed);
|
||||
auto speeds = m_ramsete.Calculate(m_drive.GetPose(), reference);
|
||||
m_drive.Drive(speeds.vx, speeds.omega);
|
||||
|
||||
m_drive.UpdateOdometry();
|
||||
}
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
|
||||
@@ -64,6 +64,7 @@ class Drivetrain {
|
||||
frc::Pose2d GetPose() const { return m_odometry.GetPose(); }
|
||||
|
||||
void SimulationPeriodic();
|
||||
void Periodic();
|
||||
|
||||
private:
|
||||
static constexpr units::meter_t kTrackWidth = 0.381_m * 2;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user