Starting Position from the DriverStation class

The folowing line should give you the robot starting location:

DriverStation ds; // define the drivers station object
int position = ds.getLocation(); // get the starting position

But I can not find what values to expect to be returned.

In test situations it returns -48. I would expect something like 1, 2, or 3 for left, center or right.

From this I hope to automatically determine which position the bot is in to let the autonomous adjust accordingly.

Does anyone know what this does?

Daniel

That value will not be useful for returning the starting position of the robot in competition matches. That value is based on which of the three driver stations your team is in which is not necessarily tied to where you place your robot. Where you place your robot should be determined through a discussion with your alliance partners before the match.

we use the driver station digital inputs we will probably use two of them to determine the location

Replies from FIRST:

If you check for the position in the constructor for the main SimpleRobot or IterativeRobot class, no driver station data has passed between the field and the robot yet and you get a bogus value. If you either delay for a few seconds in the constructor, or do the check during the autonomous or operatorControl methods it correctly returns 1, 2, or 3.

The reason for the –48 for the value is that the passed value is a position as a character: ‘0’, ‘1’, or ‘2’. To make the character value into a number the code subtracts ‘0’ which happens to be 48. Since Java initializes memory to all zeros, then you get 0-48 as the result until a real value shows up.

There are two sets of values that come back from the dashboard, the alliance and location. The alliances are instances of the Alliance object:

public static class Alliance {

    /** The integer value representing this enumeration. */
    public final int value;
    /** The Alliance name. */
    public final String name;

    public static final int kRed_val = 0;
    public static final int kBlue_val = 1;
    public static final int kInvalid_val = 2;

    /** alliance: Red */
    public static final Alliance kRed = new Alliance(kRed_val, "Red");
    /** alliance: Blue */
    public static final Alliance kBlue = new Alliance(kBlue_val, "Blue");
    /** alliance: Invalid */
    public static final Alliance kInvalid = new Alliance(kInvalid_val, "invalid");

    private Alliance(int value, String name) {
        this.value = value;
        this.name = name;
    }
} /* Alliance */

The locations are values 1, 2, or 3 and refer to the robot starting position from the FMS.

You can test both off the field by using the driver station and setting the combo box to “red 1”, “red 2”, “red 3”, “blue 1”, etc. and running the code. Those values should exactly correspond to the values you’ll get from the FMS on a real field in a competition.

I hope that this helps someone.