]> git.taranathan.com Git - FRC2026.git/commitdiff
Support multiple OrangePis to shutdown.
authorArnav495 <arnieincyberland@gmail.com>
Tue, 16 Sep 2025 16:28:49 +0000 (09:28 -0700)
committerArnav495 <arnieincyberland@gmail.com>
Tue, 16 Sep 2025 16:28:49 +0000 (09:28 -0700)
src/main/java/frc/robot/commands/vision/ShutdownAllPis.java [new file with mode: 0644]
src/main/java/frc/robot/commands/vision/ShutdownOrangePi.java
src/main/java/frc/robot/constants/VisionConstants.java

diff --git a/src/main/java/frc/robot/commands/vision/ShutdownAllPis.java b/src/main/java/frc/robot/commands/vision/ShutdownAllPis.java
new file mode 100644 (file)
index 0000000..a6d7360
--- /dev/null
@@ -0,0 +1,20 @@
+package frc.robot.commands.vision;
+
+import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
+import frc.robot.constants.VisionConstants;
+
+/**
+ * Shutdown all Orange Pis listed by hostname in
+ * {@link frc.robot.constants.VisionConstants}
+ */
+public class ShutdownAllPis extends ParallelCommandGroup {
+       public ShutdownAllPis() {
+               ShutdownOrangePi[] commands =
+                       new ShutdownOrangePi[VisionConstants.ORANGEPI_HOSTNAMES.length];
+               for (int i = 0; i < commands.length; i++) {
+                       commands[i] = new ShutdownOrangePi(VisionConstants.ORANGEPI_HOSTNAMES[i]);
+               }
+
+               addCommands(commands);
+       }
+}
index b2c0de1bbc51b708ce9218225c37528915b99aed..c9078ca453ad43c3f34005249ef206c6af5974df 100644 (file)
@@ -13,12 +13,18 @@ import frc.robot.constants.VisionConstants;
  * Uses the username and password set in {@link frc.robot.constantsVisionConstants}.
  */
 public class ShutdownOrangePi extends Command {
+       private String hostname;
        private Process process;
        private boolean passwordTyped;
        private Pattern promptMatcher;
 
-       public ShutdownOrangePi() {
+       /**
+        * @param hostname The hostname or IP of the orangepi to shut down.
+        */
+       public ShutdownOrangePi(String hostname) {
                promptMatcher = Pattern.compile("password: ?$");
+               assert hostname != null;
+               this.hostname = hostname;
        }
 
        @Override
@@ -31,14 +37,15 @@ public class ShutdownOrangePi extends Command {
                passwordTyped = false;
                if (Robot.isSimulation()) {
                        // this will probably break on Windows systems so...
-                       System.out.println("What OrangePi? This is simulation!");
+                       System.out.println("Would shut down OrangePi at " + hostname + " if this was real.");
                        return;
+               }
 
                try {
                        String[] commandString = new String[] { "ssh",
                                        "-o", "UserKnownHostsFile /dev/null",
                                        "-o", "StrictHostKeyChecking no",
-                                       VisionConstants.ORANGEPI_USERNAME + "@" + VisionConstants.ORANGEPI_IP,
+                                       VisionConstants.ORANGEPI_USERNAME + "@" + hostname,
                                        "sudo", "shutdown", "now" };
                        this.process = Runtime.getRuntime().exec(commandString);
                } catch (Exception e) {
index 4d61900c31137e0460e6d59e0e79488c59c35369..1e268b4041ebf52bc36fff1df0a0a71ecfc45957 100644 (file)
@@ -174,4 +174,9 @@ public class VisionConstants {
             new Transform3d(
                     new Translation3d(Units.inchesToMeters(10), 0, Units.inchesToMeters(24)),
                     new Rotation3d(0, Units.degreesToRadians(20), 0))));
-}
\ No newline at end of file
+
+       // used to cleanly shutdown the OrangePi
+       public static final String[] ORANGEPI_HOSTNAMES = {"photonfront.local", "photonback.local"};
+       public static final String ORANGEPI_USERNAME = "pi";
+       public static final String ORANGEPI_PASSWORD = "raspberry";
+}