|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.nxt.addon.GyroSensor
public class GyroSensor
Support the HiTechnic Gyro sensor. Provides raw int
(with optional offset) and float
angular velocity in degrees/sec.
Notes:
setSpeed()
on any motor you will be using before instantiating so the AD sensor voltage stablizes.
Otherwise, the offset
may be skewed. See LeJOS forum post "motor setSpeed()
changes AD sensor value"
getAngularVelocity()
method uses statistical analysis to continuously determine the offset/bias to apply to
the raw sensor value
to be able to calculate the "true" degrees per second the sensor is rotating at. It is important that this is called frequently
enough to ensure the sample population
is adequate. This could have been done in a dedicated sampling thread but most use cases (such as GyroDirectionFinder
)
would be calling the getAngularVelocity()
method on fast periodic basis to support integration, etc. that it was
felt a dedicated thread would be redundant.
getAngularVelocity()
method call rate is at least 100 times/sec. If slower rates are
used, the offset/bias drift value may not reliably be detected.
Field Summary | |
---|---|
protected ADSensorPort |
port
The ADSensorPort passed in the constructor. |
Fields inherited from interface lejos.nxt.SensorConstants |
---|
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, GREEN, GREEN_INDEX, MAX_AD_RAW, MAX_TYPE, MIN_TYPE, MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE, WHITE, YELLOW |
Constructor Summary | |
---|---|
GyroSensor(ADSensorPort port)
Creates and initializes a new GyroSensor bound to passed ADSensorPort . |
|
GyroSensor(ADSensorPort port,
int offset)
Creates and initializes a new GyroSensor bound to passed ADSensorPort and sets the
offset to be used in . |
Method Summary | |
---|---|
float |
getAngularVelocity()
Calculate and return the current angular velocity. |
int |
readValue()
Read the gyro raw value and return with offset applied. |
void |
recalibrateOffset()
Samples the stationary (make sure it is) Gyro Sensor to determine the offset. |
void |
recalibrateOffsetAlt()
This function sets a suitable initial gyro offset. |
void |
setOffset(int offset)
Set the offset used by readValue() . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ADSensorPort port
ADSensorPort
passed in the constructor.
Constructor Detail |
---|
public GyroSensor(ADSensorPort port)
GyroSensor
bound to passed ADSensorPort
.
port
- The SensorPort
the Gyro is connected toSensorPort
public GyroSensor(ADSensorPort port, int offset)
GyroSensor
bound to passed ADSensorPort
and sets the
offset to be used in readValue()
.
port
- The SensorPort
the Gyro is connected tooffset
- The offset to apply to readValue()
SensorPort
Method Detail |
---|
public int readValue()
setOffset(int)
,
getAngularVelocity()
public void setOffset(int offset)
readValue()
. Default at instantiation is zero.
offset
- The int
offset valuereadValue()
public float getAngularVelocity()
Be sure to call recalibrateOffset()
to establish the offset before using this method.
getAngularVelocity
in interface Gyroscope
recalibrateOffset()
public void recalibrateOffset()
ReadValue()
to 0 (zero). Takes 5 seconds.
recalibrateOffset
in interface Gyroscope
setOffset(int)
public void recalibrateOffsetAlt()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |