Package trclib.sensor
Class TrcSensor<D>
java.lang.Object
trclib.sensor.TrcSensor<D>
- Direct Known Subclasses:
FtcAndroidSensor
,FtcColorSensor
,FtcDistanceSensor
,FtcMRColorSensor
,FtcMRRangeSensor
,FtcOpticalDistanceSensor
,FtcUltrasonicSensor
,TrcAccelerometer
,TrcAnalogInput
,TrcGyro
This class implements a platform independent value sensor that has one or more axes or data type. Typically,
this class is extended by a platform dependent value sensor class. The platform dependent sensor class must
implement the abstract methods required by this class. The abstract methods allow this class to get raw data
for each axis. This class also allows the caller to register an array of DataProcessors. The data processors
will be called one at a time in the array order to filter/process the sensor data.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
This interface will be implemented by sensor classes that provide multiple data types.static class
This class implements the SensorData object that consists of the sensor value as well as a timestamp when the data sample is taken. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
private TrcSensorCalibrator<D>
private final TrcFilter[]
protected final String
private static final int
private final int
private final double[]
private final double[]
private final int[]
final TrcDbgTrace
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
This method calibrates the sensor by creating a calibrator if none exist yet.protected void
This method calibrates the sensor by creating a calibrator if none exist yet.int
This method returns the number of axes of the sensor.getProcessedData
(int index, D dataType) This method returns the processed data for the specified axis and type.abstract TrcSensor.SensorData<?>
getRawData
(int index, D dataType) This method returns the selected raw sensor data.boolean
This method always returns false because the built-in calibrator is synchronous.void
setInverted
(int index, boolean inverted) This method inverts the specified axis of the sensor.void
setScale
(int index, double scale) This method sets the scale factor for the data of the specified axis.void
setScaleAndOffset
(int index, double scale, double offset) This method sets the scale factor and offset for the data of the specified axis.toString()
This method returns the instance name.
-
Field Details
-
NUM_CAL_SAMPLES
private static final int NUM_CAL_SAMPLES- See Also:
-
CAL_INTERVAL
private static final long CAL_INTERVAL- See Also:
-
tracer
-
instanceName
-
numAxes
private final int numAxes -
filters
-
signs
private final int[] signs -
scales
private final double[] scales -
offsets
private final double[] offsets -
calibrator
-
-
Constructor Details
-
TrcSensor
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.numAxes
- specifies the number of axes.filters
- specifies an array of filter objects, one for each axis, to filter sensor data. If no filter is used, this can be set to null.
-
TrcSensor
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.numAxes
- specifies the number of axes.
-
-
Method Details
-
getRawData
This method returns the selected raw sensor data.- Parameters:
index
- specifies the index if the sensor provides some sort of array data (e.g. the axis index of a 3-axis gyro).dataType
- specifies the data type to return (e.g. rotation rate or heading of a gyro axis).- Returns:
- selected sensor data.
-
toString
This method returns the instance name. -
getNumAxes
public int getNumAxes()This method returns the number of axes of the sensor.- Returns:
- number of axes.
-
setInverted
public void setInverted(int index, boolean inverted) This method inverts the specified axis of the sensor. This is useful if the orientation of the sensor axis is such that the data goes the wrong direction, if the sensor is mounted up-side-down, for example.- Parameters:
index
- specifies the axis index.inverted
- specifies true to invert the axis, false otherwise.
-
setScaleAndOffset
public void setScaleAndOffset(int index, double scale, double offset) This method sets the scale factor and offset for the data of the specified axis.- Parameters:
index
- specifies the axis index.scale
- specifies the scale factor for the axis.offset
- specifies the offset to be subtracted from the scaled data.
-
setScale
public void setScale(int index, double scale) This method sets the scale factor for the data of the specified axis.- Parameters:
index
- specifies the axis index.scale
- specifies the scale factor for the axis.
-
calibrate
This method calibrates the sensor by creating a calibrator if none exist yet. It then calls the calibrator to do the calibration.- Parameters:
numCalSamples
- specifies the number of calibration sample to take.calInterval
- specifies the interval between each calibration sample in msec.dataType
- specifies the data type needed calibration.
-
calibrate
This method calibrates the sensor by creating a calibrator if none exist yet. It then calls the calibrator to do the calibration.- Parameters:
dataType
- specifies the data type needed calibration.
-
isCalibrating
public boolean isCalibrating()This method always returns false because the built-in calibrator is synchronous.- Returns:
- false.
-
getProcessedData
This method returns the processed data for the specified axis and type. The data will go through a filter if a filter is supplied for the axis. The calibration data will be applied to the sensor data if applicable. The sign and scale will also be applied.- Parameters:
index
- specifies the axis index.dataType
- specifies the data type object.- Returns:
- processed sensor data for the axis.
-