Class EV3IRSensor
- java.lang.Object
-
- lejos.hardware.Device
-
- lejos.hardware.sensor.BaseSensor
-
- lejos.hardware.sensor.UARTSensor
-
- lejos.hardware.sensor.EV3IRSensor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SensorMode,SensorModes,SampleProvider
public class EV3IRSensor extends UARTSensor
EV3 Infra Red sensor
The digital EV3 Infrared Seeking Sensor detects proximity to the robot and reads signals emitted by the EV3 Infrared Beacon. The sensor can alse be used as a receiver for a Lego Ev3 IR remote control.Supported modes Mode name Description unit(s) Getter Distance Measures the distance to an object in front of the sensor Undefined getDistanceMode()Seek Locates up to four beacons Undefined, undefined getSeekMode()EV3 Infra Red sensor
The sensor can be used as a receiver for up to four Lego Ev3 IR remote controls using thegetRemoteCommand(int)andgetRemoteCommands(byte[], int, int)methods. See Sensor Product page See The leJOS sensor framework SeeleJOS conventions for SampleProviders- Author:
- andy
-
-
Field Summary
Fields Modifier and Type Field Description static intIR_CHANNELSprotected static intIR_PROXprotected static intIR_REMOTEprotected static intIR_SEEKprotected byte[]remoteValsprotected static intSWITCH_DELAY-
Fields inherited from class lejos.hardware.sensor.UARTSensor
currentMode, port
-
Fields inherited from class lejos.hardware.sensor.BaseSensor
modes
-
-
Constructor Summary
Constructors Constructor Description EV3IRSensor(Port port)EV3IRSensor(UARTPort port)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SensorModegetDistanceMode()EV3 Infra Red sensor, Distance mode
Measures the distance to an object in front of the sensor.intgetRemoteCommand(int chan)Return the current remote command from the specified channel.voidgetRemoteCommands(byte[] cmds, int offset, int len)Obtain the commands associated with one or more channels.SensorModegetSeekMode()EV3 Infra Red sensor, Seek mode
In seek mode the sensor locates up to four beacons and provides bearing and distance of each beacon.protected voidinit()-
Methods inherited from class lejos.hardware.sensor.UARTSensor
switchMode
-
Methods inherited from class lejos.hardware.sensor.BaseSensor
fetchSample, getAvailableModes, getCurrentMode, getMode, getMode, getModeCount, getName, sampleSize, setCurrentMode, setCurrentMode, setModes
-
Methods inherited from class lejos.hardware.Device
close, releaseOnClose
-
-
-
-
Field Detail
-
IR_PROX
protected static final int IR_PROX
- See Also:
- Constant Field Values
-
IR_SEEK
protected static final int IR_SEEK
- See Also:
- Constant Field Values
-
IR_REMOTE
protected static final int IR_REMOTE
- See Also:
- Constant Field Values
-
SWITCH_DELAY
protected static final int SWITCH_DELAY
- See Also:
- Constant Field Values
-
IR_CHANNELS
public static final int IR_CHANNELS
- See Also:
- Constant Field Values
-
remoteVals
protected byte[] remoteVals
-
-
Method Detail
-
init
protected void init()
-
getRemoteCommand
public int getRemoteCommand(int chan)
Return the current remote command from the specified channel. Remote commands are a single numeric value which represents which button on the Lego IR remote is currently pressed (0 means no buttons pressed). Four channels are supported (0-3) which correspond to 1-4 on the remote. The button values are:
1 TOP-LEFT
2 BOTTOM-LEFT
3 TOP-RIGHT
4 BOTTOM-RIGHT
5 TOP-LEFT + TOP-RIGHT
6 TOP-LEFT + BOTTOM-RIGHT
7 BOTTOM-LEFT + TOP-RIGHT
8 BOTTOM-LEFT + BOTTOM-RIGHT
9 CENTRE/BEACON
10 BOTTOM-LEFT + TOP-LEFT
11 TOP-RIGHT + BOTTOM-RIGHT- Parameters:
chan- channel to obtain the command for- Returns:
- the current command
-
getRemoteCommands
public void getRemoteCommands(byte[] cmds, int offset, int len)Obtain the commands associated with one or more channels. Each element of the array contains the command for the associated channel (0-3).- Parameters:
cmds- the array to store the commandsoffset- the offset to start storinglen- the number of commands to store.
-
getDistanceMode
public SensorMode getDistanceMode()
EV3 Infra Red sensor, Distance mode
Measures the distance to an object in front of the sensor.Size and content of the sample
The sample contains one element giving the distance to an object in front of the sensor. The distance provided is very roughly equivalent to meters but needs conversion to give better distance. See product page for details.
The effective range of the sensor in Distance mode is about 5 to 50 centimeters. Outside this range a zero is returned for low values and positive infinity for high values.- Returns:
- A sampleProvider
See
leJOS conventions for SampleProvidersSee Sensor Product page
-
getSeekMode
public SensorMode getSeekMode()
EV3 Infra Red sensor, Seek mode
In seek mode the sensor locates up to four beacons and provides bearing and distance of each beacon.Size and content of the sample
The sample contains four pairs of elements in a single sample. Each pair gives bearing of and distance to the beacon. The first pair of elements is associated with a beacon transmitting on channel 0, the second pair with a beacon transmitting on channel 1 etc.
The bearing values range from -25 to +25 (with values increasing clockwise when looking from behind the sensor). A bearing of 0 indicates the beacon is directly in front of the sensor.
Distance values are not to scale. Al increasing values indicate increasing distance.
If no beacon is detected both bearing is set to zero, and distance to positive infinity.- Returns:
- A sampleProvider
See
leJOS conventions for SampleProvidersSee Sensor Product page
-
-