88import edu .wpi .first .epilogue .Logged ;
99import edu .wpi .first .math .geometry .Pose2d ;
1010import edu .wpi .first .networktables .NetworkTableInstance ;
11- import edu .wpi .first .networktables .StructArrayPublisher ;
1211import edu .wpi .first .networktables .StructPublisher ;
1312import edu .wpi .first .wpilibj .DataLogManager ;
1413import edu .wpi .first .wpilibj .DriverStation ;
1514import edu .wpi .first .wpilibj .TimedRobot ;
16- import edu .wpi .first .wpilibj .Timer ;
1715import edu .wpi .first .wpilibj .smartdashboard .SmartDashboard ;
1816import edu .wpi .first .wpilibj2 .command .Command ;
1917import edu .wpi .first .wpilibj2 .command .CommandScheduler ;
2725@ Logged
2826public class Robot extends TimedRobot {
2927 private Command m_autonomousCommand ;
30- // last time we injected a synthetic vision measurement (seconds, FPGA time)
31- private double m_lastSimVisionTime = 0.0 ;
32- // whether we've injected a one-time offset vision measurement for testing
33- private boolean m_injectedOffset = false ;
3428 private Pose2d robotPose = new Pose2d ();
3529 private final RobotContainer m_robotContainer ;
3630 private final CommandSwerveDrivetrain drivetrain ;
3731 StructPublisher <Pose2d > publisher =
3832 NetworkTableInstance .getDefault ().getStructTopic ("Robot Pose" , Pose2d .struct ).publish ();
39- StructArrayPublisher <Pose2d > arrayPublisher =
40- NetworkTableInstance .getDefault ().getStructArrayTopic ("MyPoseArray" , Pose2d .struct ).publish ();
4133
4234 public Robot () {
4335 m_robotContainer = new RobotContainer ();
@@ -59,17 +51,8 @@ public void robotPeriodic() {
5951 "Flywheel On" ,
6052 !(FlywheelCommand .flywheelState .equals ("none" )
6153 || FlywheelCommand .flywheelState .equals ("Stopped" )));
62- try {
63- var pose = drivetrain .getState ().Pose ;
64- SmartDashboard .putNumber ("OdometryX" , pose .getX ());
65- SmartDashboard .putNumber ("OdometryY" , pose .getY ());
66- SmartDashboard .putNumber ("OdometryRotDeg" , pose .getRotation ().getDegrees ());
67- SmartDashboard .putNumber ("SimVisionLastInject" , m_lastSimVisionTime );
68- } catch (Exception ignored ) {
69- }
7054 robotPose = drivetrain .getState ().Pose ;
7155 publisher .set (robotPose );
72- arrayPublisher .set (new Pose2d [] {robotPose });
7356 }
7457
7558 @ Override
@@ -124,24 +107,5 @@ public void testExit() {}
124107 public void simulationInit () {}
125108
126109 @ Override
127- public void simulationPeriodic () {
128- double now = Timer .getFPGATimestamp ();
129- if (now - m_lastSimVisionTime >= 0.1 ) {
130- m_lastSimVisionTime = now ;
131- try {
132- var truePose = drivetrain .getState ().Pose ;
133- // After 3 seconds, inject a single offset measurement (+1m X) to observe correction
134- if (!m_injectedOffset && now > 3.0 ) {
135- Pose2d offsetPose =
136- new Pose2d (truePose .getX () + 1.0 , truePose .getY (), truePose .getRotation ());
137- drivetrain .addVisionMeasurement (offsetPose , now );
138- m_injectedOffset = true ;
139- } else {
140- drivetrain .addVisionMeasurement (truePose , now );
141- }
142- } catch (Exception e ) {
143- DriverStation .reportError ("Sim vision injection failed: " + e .getMessage (), false );
144- }
145- }
146- }
110+ public void simulationPeriodic () {}
147111}
0 commit comments