Auto Init
Attaching this annotation to a RobotConfig derivative class will cause the init method to be executed automatically on the initialisation of any OpMode.
This is useful if you wish to make a "singleton" pattern for your RobotConfig class, where instantiating and initialising this class can be handled automatically via a hook.
NOTE: A singleton field on the classpath is required for your config, otherwise an instance can't be known to initialise.
@RobotConfig.AutoInit // annotation attached
public class Robot extends RobotConfig {
public static final Robot instance = new Robot(); // access your RobotConfig instance through a static field.
// a field exposing an instance like this *MUST* be present;
// the field name can be anything you choose and technically
// this field doesn't have to exist in this class.
// you can also use the kotlin `object` for a singleton.
@Override
protected void onRuntime() {
// will now be executed as a pre-init @Hook with access to OpMode information through BunyipsLib.getOpMode()
// and the conventional BunyipsOpMode.getInstance() for BunyipsOpMode users
// calling init() manually will no-op now
}
}
Content copied to clipboard
WARNING: Attaching @Config
to your RobotConfig
instance may cause the class to not show up on the dashboard, as it will try to recursively add itself to the config. To combat this you will need to use inner static classes or an entirely different class to hold your constants:
@RobotConfig.AutoInit
public class Robot extends RobotConfig {
@Config
public static class Constants {
public static double SOME_CONSTANT = 1;
// ...
}
public static final Robot instance = new Robot();
// ...
}
Content copied to clipboard
Since
7.0.0