Class CanandcoderSettings
java.lang.Object
com.reduxrobotics.sensors.canandcoder.CanandcoderSettings
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 Summary
ConstructorsConstructorDescriptionInstantiates a newCanandcoderSettings
object, that is "completely blank" -- that is, it holds no settings values at all.Instantiates a newCanandcoderSettings
object that copies its settings from the input instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether or not all settings fields have been written into the object.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).Return a direct filtered view of settings values as a new HashMap, limited to only valid settings.Gets whether or not the encoder has an inverted direction (false for no, true for yes, null for unset).getMap()
Directly access the underlyingMap
of settings values.Gets the position frame period in seconds [0..65.535], or null if the value has not been set on this object.double
Gets the status frame period in seconds [1..65.535], or null if the value has not been set on this object.Gets the velocity filter width in milliseconds [0.25..63.75], or null if the value has not been set on this object.double
Gets the velocity frame period in seconds [0..65.535], or null if the value has not been set on this object.setDisableZeroButton
(boolean disable) Sets whether or not the sensor should disallow zeroing and factory resets from the onboard button.setInvertDirection
(boolean invert) Inverts the direction read from the sensor.setPositionFramePeriod
(double period) Sets the position frame period in seconds.setStatusFramePeriod
(double period) Sets the status frame period in seconds.setVelocityFilterWidth
(double widthMs) Sets the velocity filter width in milliseconds to sample over.setVelocityFramePeriod
(double period) Sets the velocity frame period in seconds.
-
Constructor Details
-
CanandcoderSettings
public CanandcoderSettings()Instantiates a newCanandcoderSettings
object, that is "completely blank" -- that is, it holds no settings values at all. Settings are only populated into theCanandcoderSettings
object explicitly through the various setter methods -- runningcanandcoder.setSetting(new CanandcoderSettings())
would not update the encoder at all. To reset an encoder back to factory defaults, useCanandcoder.resetFactoryDefaults(boolean, double)
-
CanandcoderSettings
Instantiates a newCanandcoderSettings
object that copies its settings from the input instance.- Parameters:
toCopy
- the input settings object to copy
-
-
Method Details
-
setVelocityFilterWidth
Sets the velocity filter width in milliseconds to sample over. Velocity is computed by averaging all the points in the pastwidthMs
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
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 methodsCanandcoder.getPosition()
andCanandcoder.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
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 andCanandcoder.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
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
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
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
Directly access the underlyingMap
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 fromCanandcoder.getSettings(double)
this is guarenteed to be true. However, if returned fromCanandcoder.getSettingsAsync()
, this may be false until all settings values have been received from the encoder.- Returns:
- whether the settings object has been filled
-
getFilteredMap
Return a direct filtered view of settings values as a new HashMap, limited to only valid settings.- Returns:
- map
-
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
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
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
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).
-