FRCTEAM1474 / 2024RobotCode

Apache License 2.0
0 stars 1 forks source link

Enhancement: Share common code on multiple robots #7

Open berkakinci opened 4 months ago

berkakinci commented 4 months ago

Reason: We have two swerve robots. It may be helpful to have them share same code. Otherwise, the non-production robot loses a lot of its usefulness going forward.

Possible approach: The WPILib already gives us ability to identify the RoboRIO serial number. Subsystems that don't exist on a robot can be stubbed or not instantiated. Also, deploy/*/.json files seem to be read at runtime. Different deploy config can be read at init time. E.g. by adding a serial-number folder into the deploy directory. Note: I don't like duplication of deploy config. I would prefer to make all of these files be symlinks unless a change is necessary. In this case, though, I'd bite the bullet and copy whole folders because I'm not sure if the Windows/VSCode combination will botch symlinks. Yes NTFS and Git both fully support symlinks, but most Windows applications are oblivious.

berkakinci commented 4 months ago

Here's some Java code example for getting RoboRIO serial number. It's just the tip of the iceberg for making two robots share code. At minimum, we'll have to instantiate SwerveSubsystem and climberSubsystem selectively. Those may need to be moved into the RobotContainer constructor.

diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java
index b136e03..1a001b4 100644
--- a/src/main/java/frc/robot/RobotContainer.java
+++ b/src/main/java/frc/robot/RobotContainer.java
@@ -7,6 +7,7 @@ package frc.robot;
 import edu.wpi.first.math.MathUtil;
 import edu.wpi.first.wpilibj.Filesystem;
 import edu.wpi.first.wpilibj.RobotBase;
+import edu.wpi.first.wpilibj.RobotController;
 import edu.wpi.first.wpilibj.XboxController;
 import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
 import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
@@ -93,6 +94,13 @@ public class RobotContainer
     autoChooser = AutoBuilder.buildAutoChooser(); //default auto will be "Commands.non()"
     SmartDashboard.putData("Auto Chooser", autoChooser);

+    String serial_number;
+    if( RobotBase.isReal() ) {
+      serial_number = RobotController.getSerialNumber();
+    } else {
+      serial_number = "simulation";
+    }
+    System.out.println("Serial Number: " + serial_number);
   }