Class CanandcoderSettings

java.lang.Object
com.reduxrobotics.sensors.canandcoder.CanandcoderSettings

public class CanandcoderSettings extends Object
The settings class for the Canandcoder.

This class holds settings values that can be used to reconfigure Canandcoder via Canandcoder.setSettings(com.reduxrobotics.sensors.canandcoder.CanandcoderSettings, double). Additionally, objects of this class are returned from Canandcoder.getSettings(double) which can be used to read the encoder's settings.

 Canandcoder enc = new Canandcoder(0);
 
 // Only settings that are explicitly set here will be edited, so other settings 
 // such as the status frame period will remain untouched.
 // For example, enc.setSettings(new CanandcoderSettings()); will be a no-op.
 
 enc.setSettings(new CanandcoderSettings()
     .setPositionFramePeriod(0) // disables position readings
     .setVelocityFramePeriod(0.020) // sets the rate of velocity measurements to every 20 ms
     .setInvertDirection(true) // inverts the encoder direction
 );
 // enc.setSettings will block by default for up to 500 ms to confirm all values were set.
 
 
Objects returned by the blocking Canandcoder.getSettings(double) method will always have all setting values populated and the getters will never return null. However, they may return null if the object is either manually constructed and the corresponding setter hasn't been called yet (e.g. calling getStatusFramePeriod() before setStatusFramePeriod(double) on an object you made) or if the object comes from Canandcoder.getSettingsAsync() and not all settings have been received (use allSettingsReceived() to check if they're all present) Example blocking fetch:
 Canandcoder canandcoder = new Canandcoder(0);
 CanandcoderSettings stg;
 canandcoder.getSettings(0.5); // wait up to 500 ms
 System.out.printf("status frame period: %d\n", stg.getStatusFramePeriod()); // print the status frame period (usually 1000 ms)
 
  • Constructor Details

    • CanandcoderSettings

      public CanandcoderSettings()
      Instantiates a new CanandcoderSettings object, that is "completely blank" -- that is, it holds no settings values at all. Settings are only populated into the CanandcoderSettings object explicitly through the various setter methods -- running canandcoder.setSetting(new CanandcoderSettings()) would not update the encoder at all. To reset an encoder back to factory defaults, use Canandcoder.resetFactoryDefaults(boolean, double)
    • CanandcoderSettings

      public CanandcoderSettings(CanandcoderSettings toCopy)
      Instantiates a new CanandcoderSettings object that copies its settings from the input instance.
      Parameters:
      toCopy - the input settings object to copy
  • Method Details

    • setVelocityFilterWidth

      public CanandcoderSettings setVelocityFilterWidth(double widthMs)
      Sets the velocity filter width in milliseconds to sample over. Velocity is computed by averaging all the points in the past widthMs milliseconds. By factory default, the velocity filter averages over the past 25 milliseconds.
      Parameters:
      widthMs - the new number of samples to average over. Minimum accepted is 0.25 milliseconds, maximum is 63.75 ms.
      Returns:
      the calling object, so these calls can be chained
    • setPositionFramePeriod

      public CanandcoderSettings setPositionFramePeriod(double period)
      Sets the position frame period in seconds. By factory default, position frames are sent every 20 milliseconds (period=0.020) If 0 is passed in, position frames will be disabled and the methods Canandcoder.getPosition() and Canandcoder.getAbsPosition() will not return new values.
      Parameters:
      period - the new period for position frames in seconds in range [0_ms, 65.535_s]
      Returns:
      the calling object, so these calls can be chained
    • setVelocityFramePeriod

      public CanandcoderSettings setVelocityFramePeriod(double period)
      Sets the velocity frame period in seconds. By factory default, velocity frames are sent every 20 milliseconds (period=0.020) If 0 is passed in, velocity frames will be disabled and Canandcoder.getVelocity() will not return new values.
      Parameters:
      period - the new period for velocity frames in seconds in range [0_ms, 65.535_s]
      Returns:
      the calling object, so these calls can be chained
    • setStatusFramePeriod

      public CanandcoderSettings setStatusFramePeriod(double period)
      Sets the status frame period in seconds. By factory default, the encoder will broadcast 1 status message per second (period=1.0).
      Parameters:
      period - the new period for status frames in seconds in range [1.0_s, 65.535_s].
      Returns:
      the calling object, so these calls can be chained
    • setInvertDirection

      public CanandcoderSettings setInvertDirection(boolean invert)
      Inverts the direction read from the sensor. By factory default, the sensor will read counterclockwise from its reading face as positive (invert=false).
      Parameters:
      invert - whether to invert (negate) readings from the encoder
      Returns:
      the calling object
    • setDisableZeroButton

      public CanandcoderSettings setDisableZeroButton(boolean disable)
      Sets whether or not the sensor should disallow zeroing and factory resets from the onboard button. By factory default, the sensor will allow the zero button to function when pressed (disable=false)
      Parameters:
      disable - whether to disable the onboard zeroing button's functionality
      Returns:
      the calling object
    • getMap

      public Map<Byte,Long> getMap()
      Directly access the underlying Map of settings values. Intended for internal use.
      Returns:
      map
    • allSettingsReceived

      public boolean allSettingsReceived()
      Returns whether or not all settings fields have been written into the object. If this is returned from Canandcoder.getSettings(double) this is guarenteed to be true. However, if returned from Canandcoder.getSettingsAsync(), this may be false until all settings values have been received from the encoder.
      Returns:
      whether the settings object has been filled
    • getFilteredMap

      public Map<Byte,Long> getFilteredMap()
      Return a direct filtered view of settings values as a new HashMap, limited to only valid settings.
      Returns:
      map
    • getVelocityFilterWidth

      public Double getVelocityFilterWidth()
      Gets the velocity filter width in milliseconds [0.25..63.75], or null if the value has not been set on this object.
      Returns:
      the velocity filter width in milliseconds [0.25..63.75], or null if the value has not been set on this object.
    • getPositionFramePeriod

      public Double getPositionFramePeriod()
      Gets the position frame period in seconds [0..65.535], or null if the value has not been set on this object. A value of 0 means position messages are disabled.
      Returns:
      the position frame period in seconds [0..65.535], or null if the value has not been set on this object.
    • getVelocityFramePeriod

      public double getVelocityFramePeriod()
      Gets the velocity frame period in seconds [0..65.535], or null if the value has not been set on this object. A value of 0 means velocity messages are disabled.
      Returns:
      the velocity frame period in seconds [0..65.535], or null if the value has not been set on this object.
    • getStatusFramePeriod

      public double getStatusFramePeriod()
      Gets the status frame period in seconds [1..65.535], or null if the value has not been set on this object. A value of 0 means status messages are disabled.
      Returns:
      the status frame period in seconds [1..65.535], or null if the value has not been set on this object.
    • getInvertDirection

      public Boolean getInvertDirection()
      Gets whether or not the encoder has an inverted direction (false for no, true for yes, null for unset).
      Returns:
      whether or not the encoder has an inverted direction (false for no, true for yes, null for unset).
    • getDisableZeroButton

      public Boolean getDisableZeroButton()
      Gets whether or not the sensor should disallow zeroing and factory resets from the onboard button (0 for allow, 1 for disallow, -1 for unset).
      Returns:
      whether or not the encoder has its onboard zero button's functionality disabled (false for allow, true for disallow, null for unset).