Link Search Menu Expand Document

Add Control Methods

We created a very basic set(double) method previously, but this requires us to remember a lot of numbers that correspond to positions on our Lift. Let’s create a nice enum with the positions that we might want to use. Make sure to fill in <position_ticks> with your own positions!

...
  public enum Mode {
    /** Lift up position */
    UP(<upTicks>),
    /** Lift dispense position */
    DISPENSE(<dispense_ticks>),
    /** Lift down position */
    DOWN(<down_ticks>);

    private double output;

    private Mode(double output) {
      this.output = output;
    }
    public double getValue() {return this.output;}
  }

  public Lift() {
...

Now we can make an overload of our set(double) method that takes in a Mode, so that we can call it simply like subsystem.set(Mode). You can also use a switch statement if you want to have different defined operating modes that do other things.

    /**
   * Sets the Lift to the specified operating mode.
   * 
   * <p> Will do nothing and print a warning to the console if the subsystem
   * is disabled
   * 
   * @param mode desired Lift operating mode
   */
  public void set(Mode mode) {
    liftController.set(ControlMode.Position, mode.getValue());
  }

Copyright © 2021 JHS Viking Robotics. Distributed by an MIT license.