GlobalUnits
Overview
The GlobalUnits are the base distange, angle, and time units used by the framework when not explicitly specified.
These default to:
distance -> DistanceUnit.INCHESangle -> AngleUnit.RADIANStime -> TimeUnit.SECONDS
You can however set them manually in two ways:
I highly recommend using the second method, even though it takes a couple extra steps. The first method has some dangers covered if you scroll down a little.
Also you can reset the variables multiple times and even combine both methods if you'd like.
Setting up
Method 1
Calling the GlobalUnits.setUnits() method in your code:
- Java
 - Kotlin
 
public class MyTeleOp extends BlackOp {
    @Override
    public void go() {
        // Set just the distanceUnit
        GlobalUnits.setUnits(DistanceUnit.SMOOTS);
        // Set distanceUnit and angleUnit
        GlobalUnits.setUnits(DistanceUnit.SMOOTS, AngleUnit.ARCSECONDS)
        // Set all three units
        GlobalUnits.setUnits(DistanceUnit.SMOOTS, AngleUnit.ARCSECONDS, TimeUnit.CENTURIES)
    }
}
class MyTeleOp : BlackOp() {
    override fun go() {
        // Set just the distanceUnit
        GlobalUnits.setUnits(DistanceUnit.SMOOTS)
        // Set distanceUnit and angleUnit
        GlobalUnits.setUnits(DistanceUnit.SMOOTS, AngleUnit.ARCSECONDS)
        // Set all three units
        GlobalUnits.setUnits(DistanceUnit.SMOOTS, AngleUnit.ARCSECONDS, TimeUnit.CENTURIES)
    }
}
There is a downside/risk to this method. Look at this code:
pubic class MyTeleOp extends BlackOp {
    // This is created BEFORE the right units are set
    // So this startPose was created using inches and radians
    // Not centimetes and degrees, as was desired
    Pose2d startPose = new Pose2d(toIn(50), toIn(50), toRad(180));
    @Override
    public void go() {
        // This is called too late
        GlobalUnits.setUnits(DistanceUnit.CENTIMETERS, AngleUnit.DEGREES);
    }
}
Basically, calling any method that uses the units before the units are properly set will lead to some undesired behaviour.
Method 2
In the second method, we're doing to use a config file to set the units, which solves the aforementioned problem.
First, find the Teamcode -> src -> main -> res -> raw folder
In the raw folder, create a new file called bsm_units.properties file
Spelling and case-sensitivity is very important here.
Finally, in the units.properties file, put in the following:
distance=insert_unit_here
angle=insert_unit_here
time=insert_unit_here
Unit spelling must also be ON POINT.
To get the spellings for each supported unit, find the doc for the designed unit (e.g. DistanceUnit),
and copy paste over whichever unit you want (e.g. centimeters or LIGHT_YEARS)
*Unit names are not case sensitive
