Programmatically Determine Which Rio Code is on

Is there a way to determine in java which roboRio the code is runing on? We have several RR and want to run the same code on all of them with some differences determined at run time in the robot class constructor or init method. The robots carrying the RRs are very similar but not exactly the same.

Our solution to the close-but-not-identical-robot problem many years ago was to put a jumper on one of the DIO ports. One robot read the input as “true”, the other read “false”. I think the code picked a different set of PID constants and sensor calibration points for each robot.

If you have several robots, you can use multiple Digital Inputs. Or you might use a simple resistor divider circuit on an Analog Input, with each robot having a unique “ID voltage”.

Im sure there is probably some flag you could set that could then be read natively in your code, but something really simple might just be to put a text file on each roborio, each containing a unique identifier, like “Practice Setup” or “Competition Robot”. Simply read this file in your robot code and you’ll have which rio its running on.

This is what our implementation looks like. We’ve got several property files on the roboRio being read by the user code (written in Java) at startup defining the operator interface, the I/O wiring, and any parameters we want to tune. Then each roboRio (each robot or test bed) keeps its own property files depending on its own configuration.

We’ve done this with a ‘name’ field in a WPILIB Preferences object, we’ve done it with a jumper on the bot (like Alan), and we have worked off the network MAC address.

In our experience, Alan’s is the best/easiest way if you have the spare DIO (you don’t need a programmer around if you move roboRIO XXXX from the test chassis to the competition chassis). We made sure the competition robot required NO jumpers, we used jumpers to disable stuff on the test/practice robots. Murphy says you will lose the jumper if you need it at competition.

If you want to go from the MAC address (yes, there is a typo in one of the MACs):


public boolean havePneumatics = false;

    public void checkForPneumatics() {
        havePneumatics = false;
        try {
            for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
                NetworkInterface network = e.nextElement();
                System.out.println("network " + network);
                byte] mac = network.getHardwareAddress();
                if (mac != null) {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < mac.length; i++) {
                        sb.append(String.format("%02X%s", mac*, (i < mac.length - 1) ? "-" : ""));
                    }
    // Mule Board (wegscheid) MAC: "00-80-2F-17-EA-A4"
                    // MAC: "00-80-2F-17-EA-A5"
                    //Test bot (3630KOP) MAC: "00-80-2F-17-93-IE"
                    //Prototype (3620 Spare) MAC: "00-80-2F-17-EB-09"
                    // MAC: "00-80-2F-17-EB-08"
                    String macString = sb.toString();
                    System.out.println(" looking at MAC:" + macString);
                    if (macString.equals("00-80-2F-17-EB-09") || macString.equals("00-80-2F-17-EA-A4")) {
                        havePneumatics = true;
                        break;
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
        System.out.println ("We have " + (havePneumatics ? "" : "no ") + "pneumatics");
                
    }


Thanks for the replies, all good suggestions. I was trolling for an API that would return a serial number or some such built in identifier and the mac address would fill that bill. However, I am leaning toward the configuration file using a java properties object. That would offer the most flexibility and future expansion.

1 Like

as I recall, the serial number is accessible from LV, but it didn’t get exposed to the Java or C++ APIs.