--- /dev/null
+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);
+ }
+}
* 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
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) {
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";
+}