Package trclib.sensor
Class TrcAccelerometer
- Direct Known Subclasses:
FtcAccelerometer
,FtcAndroidAccel
This class implements a platform independent accelerometer. Typically, this class is extended by a platform
dependent accelerometer class. The platform dependent accelerometer class must implement the abstract methods
required by this class. The abstract methods allow this class to get raw data for each accelerometer axis.
Depending on the options specified in the constructor, this class may create an integrator. The platform dependent
accelerometer can specify how many axes it supports by setting the HAS_AXIS options. If it does not provide
velocity or distance data, it can set the INTEGRATE and DOUBLE_INTEGRATE options and let the built-in integrator
handle it.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class trclib.sensor.TrcSensor
TrcSensor.DataSource<D>, TrcSensor.SensorData<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
private TrcElapsedTimer
protected final String
private int
private int
private int
-
Constructor Summary
ConstructorsConstructorDescriptionTrcAccelerometer
(String instanceName, int numAxes, int options) Constructor: Creates an instance of the object.TrcAccelerometer
(String instanceName, int numAxes, int options, TrcFilter[] filters) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptiongetRawData
(int index, TrcAccelerometer.DataType dataType) This abstract method returns the raw sensor data for the specified axis and type.abstract TrcSensor.SensorData<Double>
getRawXData
(TrcAccelerometer.DataType dataType) This abstract method returns the raw data of the specified type for the x-axis.abstract TrcSensor.SensorData<Double>
getRawYData
(TrcAccelerometer.DataType dataType) This abstract method returns the raw data of the specified type for the y-axis.abstract TrcSensor.SensorData<Double>
getRawZData
(TrcAccelerometer.DataType dataType) This abstract method returns the raw data of the specified type for the z-axis.This method returns the acceleration on the x-axis.This method returns the distance of the x-axis.This method returns the velocity of the x-axis.This method returns the acceleration on the y-axis.This method returns the distance of the y-axis.This method returns the velocity of the y-axis.This method returns the acceleration on the z-axis.This method returns the distance of the z-axis.This method returns the velocity of the z-axis.void
printElapsedTime
(TrcDbgTrace tracer) This method prints the elapsed time info using the given tracer.void
This method resets the integrator on the x-axis.void
This method resets the integrator on the y-axis.void
This method resets the integrator 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 accelerometer 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
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
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.toString()
This method returns the instance name.Methods inherited from class trclib.sensor.TrcSensor
calibrate, calibrate, getNumAxes, getProcessedData, isCalibrating, setInverted, setScale, setScaleAndOffset
-
Field Details
-
ACCEL_HAS_X_AXIS
public static final int ACCEL_HAS_X_AXIS- See Also:
-
ACCEL_HAS_Y_AXIS
public static final int ACCEL_HAS_Y_AXIS- See Also:
-
ACCEL_HAS_Z_AXIS
public static final int ACCEL_HAS_Z_AXIS- See Also:
-
ACCEL_INTEGRATE
public static final int ACCEL_INTEGRATE- See Also:
-
ACCEL_DOUBLE_INTEGRATE
public static final int ACCEL_DOUBLE_INTEGRATE- See Also:
-
instanceName
-
dataIntegrator
-
xIndex
private int xIndex -
yIndex
private int yIndex -
zIndex
private int zIndex -
getDataElapsedTimer
-
-
Constructor Details
-
TrcAccelerometer
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 accelerometer options. Multiple options can be OR'd together. ACCEL_HAS_X_AXIS - supports x-axis. ACCEL_HAS_Y_AXIS - supports y-axis. ACCEL_HAS_Z_AXIS - supports z-axis. ACCEL_INTEGRATE - do integration on all axes to get velocities. ACCEL_DOUBLE_INTEGRATE - do double integration on all axes to get distances.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.
-
TrcAccelerometer
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 accelerometer options. Multiple options can be OR'd together. ACCEL_HAS_X_AXIS - supports x-axis. ACCEL_HAS_Y_AXIS - supports y-axis. ACCEL_HAS_Z_AXIS - supports z-axis. ACCEL_INTEGRATE - do integration on all axes to get velocities. ACCEL_DOUBLE_INTEGRATE - do double integration on all axes to get distances.
-
-
Method Details
-
getRawXData
This abstract method returns the raw data of the specified type for the x-axis.- Parameters:
dataType
- specifies the data type.- Returns:
- raw data of the specified type for the x-axis.
-
getRawYData
This abstract method returns the raw data of the specified type for the y-axis.- Parameters:
dataType
- specifies the data type.- Returns:
- raw data of the specified type for the y-axis.
-
getRawZData
This abstract method returns the raw data of the specified type for the z-axis.- Parameters:
dataType
- specifies the data type.- Returns:
- raw data of the specified type for the z-axis.
-
toString
This method returns the instance name.- Overrides:
toString
in classTrcSensor<TrcAccelerometer.DataType>
- Returns:
- instance name.
-
setEnabled
public void setEnabled(boolean enabled) This method enables/disables the processing of accelerometer data. It is not automatically enabled when the TrcAccelerometer object is created. You need to explicitly enable the it before data processing will start. As part of enabling the accelerometer, calibrate() is also called. calibrate() may be overridden by the platform dependent accelerometer 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 if it 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 accelerometer 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 accelerometer 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 accelerometer 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.
-
getXAcceleration
This method returns the acceleration on the x-axis.- Returns:
- X acceleration.
-
getYAcceleration
This method returns the acceleration on the y-axis.- Returns:
- Y acceleration.
-
getZAcceleration
This method returns the acceleration on the z-axis.- Returns:
- Z acceleration.
-
getXVelocity
This method returns the velocity of the x-axis. If there is an integrator, we call the integrator to get the velocity else we call the platform dependent accelerometer to get the raw velocity value.- Returns:
- X velocity.
-
getYVelocity
This method returns the velocity of the y-axis. If there is an integrator, we call the integrator to get the velocity else we call the platform dependent accelerometer to get the raw velocity value.- Returns:
- Y velocity.
-
getZVelocity
This method returns the velocity of the z-axis. If there is an integrator, we call the integrator to get the velocity else we call the platform dependent accelerometer to get the raw velocity value.- Returns:
- Z velocity.
-
getXDistance
This method returns the distance of the x-axis. If there is an integrator, we call the integrator to get the distance else we call the platform dependent accelerometer to get the raw distance value.- Returns:
- X distance.
-
getYDistance
This method returns the distance of the y-axis. If there is an integrator, we call the integrator to get the distance else we call the platform dependent accelerometer to get the raw distance value.- Returns:
- Y distance.
-
getZDistance
This method returns the distance of the z-axis. If there is an integrator, we call the integrator to get the distance else we call the platform dependent accelerometer to get the raw distance value.- Returns:
- Z distance.
-
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<TrcAccelerometer.DataType>
- Parameters:
index
- specifies the axis index.dataType
- specifies the data type.- Returns:
- raw data for the specified axis.
-