readBeaconProximity

Read distance and heading from infrared sensor to beacon

Description

example

[proximity,heading] = readBeaconProximity(myirsensor,channel) measures the relative proximity and heading from the infrared sensor to the infrared beacon. The function returns the proximity as a value from 0 to 100 (near to far), and returns the heading as a value from -25 to 25 (left to right). The maximum range from the sensor to the beacon is approximately 200 cm (79 inches).

Examples

collapse all

Measure the relative distance from an infrared sensor to an EV3 IR beacon.

Create a connection to the EV3 brick called myev3.

myev3 = legoev3
myev3 = 

  legoev3 with properties:

      FirmwareVersion: 'V1.03E'
           HardwareID: []
            IPAddress: []
    CommunicationType: 'USB'
         BatteryLevel: 0
     ConnectedSensors: {'touch'  'infrared'  'color'  'sonic'}

The sensor appears in the list of connected sensors.

Create a connection to an infrared sensor.

myirsensor = irSensor(myev3)
myirsensor = 

  irSensor with properties:

      Channel: 1
    InputPort: 2

Read the relative distance and heading from the infrared sensor to an IR beacon that is using channel 2.

[proximity,heading] = readBeaconProximity(myirsensor,2)
proximity =

 -128


heading =

    0

These values indicate that no one is pressing a button on the IR beacon.

Press a button on the IR beacon and try again.

[proximity,heading] = readBeaconProximity(myirsensor,2)
proximity =

   26


heading =

  -14

The IR beacon is 26 distance units away from, and 14 heading units to the left of, the sensor.

Input Arguments

collapse all

Connection to infrared sensor, specified as a string that represents the object created using irSensor.

Data Types: char

The channel number that the IR beacon uses, specified as a double. The red switch on the beacon has four positions that determine the channel number. The forward position is channel 1.

Example: 2

Data Types: double

Output Arguments

collapse all

Relative distance from the sensor to the IR beacon, returned as an int8 value, from 0 to 100 (near to far).

Relative heading from the infrared sensor to the IR beacon, returned as an int8 value, from -25 to 25 (left to right).