Class CanandgyroSettings
java.lang.Object
com.reduxrobotics.canand.CanandSettings
com.reduxrobotics.sensors.canandgyro.CanandgyroSettings
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()); }
-
Field Summary
Fields inherited from class com.reduxrobotics.canand.CanandSettings
ephemeral, values
-
Constructor Summary
ConstructorDescriptionInstantiates a blankCanandgyroSettings
object with no settings to be set.CanandgyroSettings
(CanandgyroSettings toCopy) Instantiates a newCanandgyroSettings
object that copies its settings from the input instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected int[]
Gets the list of settings addresses this settings class records.Gets the acceleration frame period in seconds [0..65.535], orOptional.empty()
if the value has not been set on this object.Gets the angular position frame period in seconds [0..65.535], orOptional.empty()
if the value has not been set on this object.Gets the angular velocity frame period in seconds [0..65.535], orOptional.empty()
if the value has not been set on this object.Gets the status frame period in seconds [0.001..65.535], orOptional.empty()
if the value has not beeno set on this object.Gets the dedicated yaw frame period in seconds [0..65.535], orOptional.empty()
if the value has not been set on this object.setAccelerationFramePeriod
(double period) Sets the angular velocity frame period in seconds.setAngularPositionFramePeriod
(double period) Sets the angular position frame period in seconds.setAngularVelocityFramePeriod
(double period) Sets the angular velocity frame period in seconds.setStatusFramePeriod
(double period) Sets the status frame period in seconds.setYawFramePeriod
(double period) Sets the dedicated yaw frame period in seconds.Methods inherited from class com.reduxrobotics.canand.CanandSettings
allSettingsReceived, checkBounds, getBool, getFilteredMap, getFloatAsDouble, getIntAsDouble, getMap, getMissingIndexes, isEmpty, setEphemeral, toString
-
Constructor Details
-
CanandgyroSettings
public CanandgyroSettings()Instantiates a blankCanandgyroSettings
object with no settings to be set. -
CanandgyroSettings
Instantiates a newCanandgyroSettings
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 classCanandSettings
- Returns:
- settings addresses.
-
setYawFramePeriod
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 andCanandgyro.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
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
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
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
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
Gets the dedicated yaw frame period in seconds [0..65.535], orOptional.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
Gets the angular position frame period in seconds [0..65.535], orOptional.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
Gets the angular velocity frame period in seconds [0..65.535], orOptional.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
Gets the acceleration frame period in seconds [0..65.535], orOptional.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
Gets the status frame period in seconds [0.001..65.535], orOptional.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.
-