Class CanandgyroSettings

java.lang.Object
com.reduxrobotics.canand.CanandSettings
com.reduxrobotics.sensors.canandgyro.CanandgyroSettings

public class CanandgyroSettings extends CanandSettings
The settings class for the Canandgyro.

This class holds settings values that can be used to reconfigure Canandgyro via Canandgyro.setSettings(com.reduxrobotics.sensors.canandgyro.CanandgyroSettings, double, int). Additionally, objects of this class are returned from Canandgyro.getSettings(double, double, int) and Canandgyro.getSettingsAsync() which can be used to read the device's settings.

 // Object initialization
 Canandgyro canandgyro = new Canandgyro(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, canandgyro.setSettings(new CanandgyroSettings()); will be a no-op.
 
 canandgyro.setSettings(new CanandgyroSettings()
     .setYawFramePeriod(0.005) // sets the rate of gyro measurements to every 5 ms
     .setAngularPositionFramePeriod(0) // disables angular position updates. 
                                       // Yaw uses a separate frame and is unaffected.
     .setAngularVelocityFramePeriod(0.01) // set angular velocity to every 10 ms
     .setAccelerationFramePeriod(0) // disable acceleration frames
 );
 // canandgyro.setSettings will block by default for up to 350 ms to confirm all values were set.
 
 
Objects returned by the blocking Canandgyro.getSettings(double, double, int) method may return Optional.empty() on its getters. This occurs when getSettings would've previously returned Optional.empty() -- however, this allows for partial settings fetches. This scenario is unlikely (assuming the device is attached) as failed settings fetches are by default retried up to 3 times. To check if the settings fetch succeeded, one can use CanandSettings.allSettingsReceived() to check all fields are populated. Example blocking fetch:
 // Object initialization
 Canandgyro canandgyro = new Canandgyro(0);
 
 // Robot code 
 CanandgyroSettings stg = canandgyro.getSettings(0.5); // wait up to 500 ms
 if (stg.allSettingsReceived()) {
     // print the status frame period (usually 100 ms)
     System.out.printf("status frame period: %d\n", stg.getStatusFramePeriod());
 }
 
  • Constructor Details

    • CanandgyroSettings

      public CanandgyroSettings()
      Instantiates a blank CanandgyroSettings object with no settings to be set.
    • CanandgyroSettings

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

    • fetchSettingsAddresses

      protected int[] fetchSettingsAddresses()
      Description copied from class: CanandSettings
      Gets the list of settings addresses this settings class records. This is typically a static list of constants from a Details class.
      Specified by:
      fetchSettingsAddresses in class CanandSettings
      Returns:
      settings addresses.
    • setYawFramePeriod

      public CanandgyroSettings setYawFramePeriod(double period)
      Sets the dedicated yaw frame period in seconds. By factory default, yaw frames are sent every 10 milliseconds (period = 0.010). If 0 is passed in, yaw frames will be disabled and Canandgyro.getYaw() will not return new values (unless configured to derive yaw from the angular position frame)
      Parameters:
      period - the new frame period in seconds [0_s, 65.535_s] inclusive
      Returns:
      the calling object, so these calls can be chained
    • setAngularPositionFramePeriod

      public CanandgyroSettings setAngularPositionFramePeriod(double period)
      Sets the angular position frame period in seconds. By factory default, angular position frames are sent every 20 milliseconds (period = 0.020). If 0 is passed in, angular position frames will be disabled and methods returning angular position data will not return new values.

      The one exception is Canandgyro.getYaw() which by default uses the yaw frame instead.

      Parameters:
      period - the new frame period in seconds [0_s, 65.535_s] inclusive
      Returns:
      the calling object, so these calls can be chained
    • setAngularVelocityFramePeriod

      public CanandgyroSettings setAngularVelocityFramePeriod(double period)
      Sets the angular velocity frame period in seconds. By factory default, angular velocity frames are sent every 100 milliseconds (period = 0.100). If 0 is passed in, angular velocity frames will be disabled and methods returning angular velocity data will not return new values.
      Parameters:
      period - the new frame period in seconds [0_s, 65.535_s] inclusive
      Returns:
      the calling object, so these calls can be chained
    • setAccelerationFramePeriod

      public CanandgyroSettings setAccelerationFramePeriod(double period)
      Sets the angular velocity frame period in seconds. By factory default, acceleration frames are sent every 100 milliseconds (period = 0.100). If 0 is passed in, acceleration frames will be disabled and methods returning acceleration data will not return new values.
      Parameters:
      period - the new frame period in seconds [0_s, 65.535_s] inclusive
      Returns:
      the calling object, so these calls can be chained
    • setStatusFramePeriod

      public CanandgyroSettings setStatusFramePeriod(double period)
      Sets the status frame period in seconds. By factory default, the device will broadcast 10 status messages every second (period=0.1).
      Parameters:
      period - the new period for status frames in seconds in range [0.001_s, 16.383_s].
      Returns:
      the calling object, so these calls can be chained
    • getYawFramePeriod

      public Optional<Double> getYawFramePeriod()
      Gets the dedicated yaw frame period in seconds [0..65.535], or Optional.empty() if the value has not been set on this object. A value of 0 means yaw frames are disabled.
      Returns:
      the frame period in seconds [0..65.535], or Optional.empty() if the value has not been set on this object.
    • getAngularPositionFramePeriod

      public Optional<Double> getAngularPositionFramePeriod()
      Gets the angular position frame period in seconds [0..65.535], or Optional.empty() if the value has not been set on this object. A value of 0 means angular position frames are disabled.
      Returns:
      the frame period in seconds [0..65.535], or Optional.empty() if the value has not been set on this object.
    • getAngularVelocityFramePeriod

      public Optional<Double> getAngularVelocityFramePeriod()
      Gets the angular velocity frame period in seconds [0..65.535], or Optional.empty() if the value has not been set on this object. A value of 0 means angular velocity frames are disabled.
      Returns:
      the frame period in seconds [0..65.535], or Optional.empty() if the value has not been set on this object.
    • getAccelerationFramePeriod

      public Optional<Double> getAccelerationFramePeriod()
      Gets the acceleration frame period in seconds [0..65.535], or Optional.empty() if the value has not been set on this object. A value of 0 means acceleration frames are disabled.
      Returns:
      the frame period in seconds [0..65.535], or Optional.empty() if the value has not been set on this object.
    • getStatusFramePeriod

      public Optional<Double> getStatusFramePeriod()
      Gets the status frame period in seconds [0.001..65.535], or Optional.empty() if the value has not beeno set on this object.
      Returns:
      the status frame period in seconds [0.001..65.535], or Optional.empty() if the value has not been set on this object.