Package trclib.sensor
Class TrcGyro
- All Implemented Interfaces:
TrcOdometrySensor
- Direct Known Subclasses:
FtcAnalogGyro
,FtcAndroidGyro
,FtcImu
,FtcMRGyro
This class implements a platform independent gyro. Typically, this class is extended by a platform dependent
gyro class. The platform dependent gyro class must implement the abstract methods required by this class. The
abstract methods allow this class to get raw data for each gyro axis. Depending on the options specified in the
constructor, this class creates an integrator or a CardinalConverter. The platform dependent gyro can specify
how many axes it supports by setting the HAS_AXIS options. If it does not provide heading data, it can set the
INTEGRATE option and let the built-in integrator handle it. Or if it provides a Cardinal heading instead of
Cartesian, it can set the CONVERT_TO_CARTESIAN option to enable the CardinalConverter to do the conversion.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class trclib.sensor.TrcSensor
TrcSensor.DataSource<D>, TrcSensor.SensorData<T>
Nested classes/interfaces inherited from interface trclib.sensor.TrcOdometrySensor
TrcOdometrySensor.Odometry
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TrcElapsedTimer
static final int
static final int
static final int
static final int
private TrcDataIntegrator<TrcGyro.DataType>
private final TrcOdometrySensor.Odometry
private int
private TrcWrapValueConverter
private int
private TrcWrapValueConverter
private int
private TrcWrapValueConverter
private double
Fields inherited from class trclib.sensor.TrcSensor
instanceName, tracer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetName()
This method returns the instance name.getOdometry
(int axisIndex) This method returns a copy of the odometry data of the specified axis.getRawData
(int index, TrcGyro.DataType dataType) This abstract method returns the raw sensor data for the specified axis and type.abstract TrcSensor.SensorData<Double>
getRawXData
(TrcGyro.DataType dataType) This abstract method returns the raw data with the specified type of the x-axis.private double
This method reads the raw X Heading.abstract TrcSensor.SensorData<Double>
getRawYData
(TrcGyro.DataType dataType) This abstract method returns the raw data with the specified type of the y-axis.private double
This method reads the raw Y Heading.abstract TrcSensor.SensorData<Double>
getRawZData
(TrcGyro.DataType dataType) This abstract method returns the raw data with the specified type of the z-axis.private double
This method reads the raw Z Heading.This method returns the heading of the x-axis.This method returns the rotation rate on the x-axis.This method returns the heading of the y-axis.This method returns the rotation rate on the y-axis.This method returns the heading of the z-axis.This method returns the rotation rate on the z-axis.void
printElapsedTime
(TrcDbgTrace tracer) This method prints the elapsed time info using the given tracer.void
resetOdometry
(boolean resetHardware) This method resets the odometry data and sensor.void
This method resets the integrator on the x-axis.void
This method resets the WrapValueConverter on the x-axis.void
This method resets the integrator on the y-axis.void
This method resets the WrapValueConverter on the y-axis.void
This method resets the integrator on the z-axis.void
This method resets the WrapValueConverter on the z-axis.void
setElapsedTimerEnabled
(boolean enabled) This method enables/disables the elapsed timers for performance monitoring.void
setEnabled
(boolean enabled) This method enables/disables the processing of gyro data.void
setXInverted
(boolean inverted) This method inverts the x-axis.void
setXScale
(double scale) This method sets the scale factor for the data of the x-axis.void
setXValueRange
(double valueRangeLow, double valueRangeHigh) This method sets the heading value range of the x-axis.void
setYInverted
(boolean inverted) This method inverts the y-axis.void
setYScale
(double scale) This method sets the scale factor for the data of the y-axis.void
setYValueRange
(double valueRangeLow, double valueRangeHigh) This method sets the heading value range of the y-axis.void
setZInverted
(boolean inverted) This method inverts the z-axis.void
setZScale
(double scale) This method sets the scale factor for the data of the z-axis.void
setZValueRange
(double valueRangeLow, double valueRangeHigh) This method sets the heading value range of the z-axis.toString()
This method returns the instance name.private void
This method reads the raw gyro Z data and updates the odometry with it.Methods inherited from class trclib.sensor.TrcSensor
calibrate, calibrate, getNumAxes, getProcessedData, isCalibrating, setInverted, setScale, setScaleAndOffset
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface trclib.sensor.TrcOdometrySensor
getOdometries, getOdometry
-
Field Details
-
GYRO_HAS_X_AXIS
public static final int GYRO_HAS_X_AXIS- See Also:
-
GYRO_HAS_Y_AXIS
public static final int GYRO_HAS_Y_AXIS- See Also:
-
GYRO_HAS_Z_AXIS
public static final int GYRO_HAS_Z_AXIS- See Also:
-
GYRO_INTEGRATE
public static final int GYRO_INTEGRATE- See Also:
-
odometry
-
integrator
-
xWrapValueConverter
-
yWrapValueConverter
-
zWrapValueConverter
-
xIndex
private int xIndex -
yIndex
private int yIndex -
zIndex
private int zIndex -
getDataElapsedTimer
-
zZeroPos
private double zZeroPos
-
-
Constructor Details
-
TrcGyro
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.numAxes
- specifies the number of axes of the gyro.options
- specifies the gyro options. Multiple options can be OR'd together. GYRO_HAS_X_AXIS - supports x-axis. GYRO_HAS_Y_AXIS - supports y-axis. GYRO_HAS_Z_AXIS - supports z-axis. GYRO_INTEGRATE - do integration on all axes to get headings.filters
- specifies an array of filter objects one for each supported axis. It is assumed that the order of the filters in the array is x, y and then z. If an axis is specified in the options but no filter will be used on that axis, the corresponding element in the array should be set to null. If no filter is used at all, filters can be set to null.
-
TrcGyro
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.numAxes
- specifies the number of axes of the gyro.options
- specifies the gyro options. Multiple options can be OR'd together. GYRO_HAS_X_AXIS - supports x-axis. GYRO_HAS_Y_AXIS - supports y-axis. GYRO_HAS_Z_AXIS - supports z-axis. GYRO_INTEGRATE - do integration on all axes to get headings. GYRO_CONVERT_TO_CARTESIAN - converts the Cardinal heading to Cartesian heading.
-
-
Method Details
-
getRawXData
This abstract method returns the raw data with the specified type of the x-axis.- Parameters:
dataType
- specifies the data type.- Returns:
- raw data with the specified type of the x-axis.
-
getRawYData
This abstract method returns the raw data with the specified type of the y-axis.- Parameters:
dataType
- specifies the data type.- Returns:
- raw data with the specified type of the y-axis.
-
getRawZData
This abstract method returns the raw data with the specified type of the z-axis.- Parameters:
dataType
- specifies the data type.- Returns:
- raw data with the specified type of the z-axis.
-
toString
This method returns the instance name.- Overrides:
toString
in classTrcSensor<TrcGyro.DataType>
- Returns:
- instance name.
-
setEnabled
public void setEnabled(boolean enabled) This method enables/disables the processing of gyro data. It is not automatically enabled when the TrcGyro object is created. You need to explicitly enable the it before data processing will start. As part of enabling the gyro, calibrate() is also called. calibrate() may be overridden by the platform dependent gyro if it is capable of doing its own. Otherwise, calibrate will call the built-in calibrator to do the calibration. Enabling/disabling data processing for the gyro involves enabling/disabling the Integrator and the CardinalConverter if they exist.- Parameters:
enabled
- specifies true if enabling, false otherwise.
-
setElapsedTimerEnabled
public void setElapsedTimerEnabled(boolean enabled) This method enables/disables the elapsed timers for performance monitoring.- Parameters:
enabled
- specifies true to enable elapsed timers, false to disable.
-
printElapsedTime
This method prints the elapsed time info using the given tracer.- Parameters:
tracer
- specifies the tracer to be used to print the info.
-
setXInverted
public void setXInverted(boolean inverted) This method inverts the x-axis. This is useful if the orientation of the gyro x-axis is such that the data goes the wrong direction.- Parameters:
inverted
- specifies true to invert x-axis, false otherwise.
-
setYInverted
public void setYInverted(boolean inverted) This method inverts the y-axis. This is useful if the orientation of the gyro y-axis is such that the data goes the wrong direction.- Parameters:
inverted
- specifies true to invert y-axis, false otherwise.
-
setZInverted
public void setZInverted(boolean inverted) This method inverts the z-axis. This is useful if the orientation of the gyro z-axis is such that the data goes the wrong direction.- Parameters:
inverted
- specifies true to invert z-axis, false otherwise.
-
setXScale
public void setXScale(double scale) This method sets the scale factor for the data of the x-axis.- Parameters:
scale
- specifies the x scale factor.
-
setYScale
public void setYScale(double scale) This method sets the scale factor for the data of the y-axis.- Parameters:
scale
- specifies the y scale factor.
-
setZScale
public void setZScale(double scale) This method sets the scale factor for the data of the z-axis.- Parameters:
scale
- specifies the z scale factor.
-
setXValueRange
public void setXValueRange(double valueRangeLow, double valueRangeHigh) This method sets the heading value range of the x-axis. The value range is used by the CardinalConverter to convert the heading to Cartesian heading.- Parameters:
valueRangeLow
- specifies the low value of the x-axis range.valueRangeHigh
- specifies the high value of the x-axis range.
-
setYValueRange
public void setYValueRange(double valueRangeLow, double valueRangeHigh) This method sets the heading value range of the y-axis. The value range is used by the CardinalConverter to convert the heading to Cartesian heading.- Parameters:
valueRangeLow
- specifies the low value of the y-axis range.valueRangeHigh
- specifies the high value of the y-axis range.
-
setZValueRange
public void setZValueRange(double valueRangeLow, double valueRangeHigh) This method sets the heading value range of the z-axis. The value range is used by the CardinalConverter to convert the heading to Cartesian heading.- Parameters:
valueRangeLow
- specifies the low value of the z-axis range.valueRangeHigh
- specifies the high value of the z-axis range.
-
resetXWrapValueConverter
public void resetXWrapValueConverter()This method resets the WrapValueConverter on the x-axis. -
resetYWrapValueConverter
public void resetYWrapValueConverter()This method resets the WrapValueConverter on the y-axis. -
resetZWrapValueConverter
public void resetZWrapValueConverter()This method resets the WrapValueConverter on the z-axis. -
getRawXHeading
private double getRawXHeading()This method reads the raw X Heading.- Returns:
- raw X Heading.
-
getRawYHeading
private double getRawYHeading()This method reads the raw Y Heading.- Returns:
- raw Y Heading.
-
getRawZHeading
private double getRawZHeading()This method reads the raw Z Heading.- Returns:
- raw Z Heading.
-
getXRotationRate
This method returns the rotation rate on the x-axis.- Returns:
- X rotation rate.
-
getYRotationRate
This method returns the rotation rate on the y-axis.- Returns:
- Y rotation rate.
-
getZRotationRate
This method returns the rotation rate on the z-axis.- Returns:
- Z rotation rate.
-
getXHeading
This method returns the heading of the x-axis. If there is an integrator, we call the integrator to get the heading. Else if we have a CardinalConverter, we call it to get the heading else we call the platform dependent gyro to get the raw heading value.- Returns:
- X heading.
-
getYHeading
This method returns the heading of the y-axis. If there is an integrator, we call the integrator to get the heading. Else if we have a CardinalConverter, we call it to get the heading else we call the platform dependent gyro to get the raw heading value.- Returns:
- Y heading.
-
getZHeading
This method returns the heading of the z-axis. If there is an integrator, we call the integrator to get the heading. Else if we have a CardinalConverter, we call it to get the heading else we call the platform dependent gyro to get the raw heading value.- Returns:
- Z heading.
-
resetXIntegrator
public void resetXIntegrator()This method resets the integrator on the x-axis. -
resetYIntegrator
public void resetYIntegrator()This method resets the integrator on the y-axis. -
resetZIntegrator
public void resetZIntegrator()This method resets the integrator on the z-axis. -
getRawData
This abstract method returns the raw sensor data for the specified axis and type.- Specified by:
getRawData
in classTrcSensor<TrcGyro.DataType>
- Parameters:
index
- specifies the axis index.dataType
- specifies the data type.- Returns:
- raw data for the specified axis and type.
-
updateOdometry
private void updateOdometry()This method reads the raw gyro Z data and updates the odometry with it. -
getName
This method returns the instance name.- Specified by:
getName
in interfaceTrcOdometrySensor
- Returns:
- instance name.
-
resetOdometry
public void resetOdometry(boolean resetHardware) This method resets the odometry data and sensor. TODO: need to support multiple axes.- Specified by:
resetOdometry
in interfaceTrcOdometrySensor
- Parameters:
resetHardware
- specifies true to do a hardware reset, false to do a software reset. Hardware reset may require some time to complete and will block this method from returning until finish.
-
getOdometry
This method returns a copy of the odometry data of the specified axis. It must be a copy so it won't change while the caller is accessing the data fields.- Specified by:
getOdometry
in interfaceTrcOdometrySensor
- Parameters:
axisIndex
- specifies the axis index if it is a multi-axes sensor, 0 if it is a single axis sensor.- Returns:
- a copy of the odometry data of the specified axis.
-